aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sartain <mikesart@valvesoftware.com>2013-08-01 18:51:08 +0000
committerMichael Sartain <mikesart@valvesoftware.com>2013-08-01 18:51:08 +0000
commit7526625a76ca97a2637749b0cc4068bf0bd907fb (patch)
treec5fa321bbb7b03eba6f13b85a78d3d1d0f9d45e2
parent2bf963306acbe20bd3de14ad150c157243cd3844 (diff)
downloadlldb-7526625a76ca97a2637749b0cc4068bf0bd907fb.tar.gz
Fix Linux Host::GetCurrentThreadID() to return real tid (not pthread_t).
This fixes threadname logging (--thread-name) Add "-t" to TestLogging.py script to enable threadsafe and disable threadname logging git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@187599 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--source/Host/common/Host.cpp16
-rw-r--r--source/Host/linux/Host.cpp17
-rw-r--r--test/logging/TestLogging.py5
3 files changed, 21 insertions, 17 deletions
diff --git a/source/Host/common/Host.cpp b/source/Host/common/Host.cpp
index 5aee4ad20..2e5b6e98f 100644
--- a/source/Host/common/Host.cpp
+++ b/source/Host/common/Host.cpp
@@ -31,6 +31,7 @@
#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
#include <sys/wait.h>
+#include <sys/syscall.h>
#endif
#if defined (__FreeBSD__)
@@ -455,6 +456,8 @@ Host::GetCurrentThreadID()
return thread_self;
#elif defined(__FreeBSD__)
return lldb::tid_t(pthread_getthreadid_np());
+#elif defined(__linux__)
+ return lldb::tid_t(syscall(SYS_gettid));
#else
return lldb::tid_t(pthread_self());
#endif
@@ -660,7 +663,7 @@ Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
// Set the pthread name if possible
if (pid == curr_pid && tid == curr_tid)
{
- ::pthread_set_name_np(::pthread_self(), name);
+ ::pthread_set_name_np (::pthread_self(), name);
return true;
}
return false;
@@ -668,21 +671,20 @@ Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
void *fn = dlsym (RTLD_DEFAULT, "pthread_setname_np");
if (fn)
{
- int (*pthread_setname_np_func)(pthread_t thread, const char *name);
- *reinterpret_cast<void **> (&pthread_setname_np_func) = fn;
-
lldb::pid_t curr_pid = Host::GetCurrentProcessID();
lldb::tid_t curr_tid = Host::GetCurrentThreadID();
-
if (pid == LLDB_INVALID_PROCESS_ID)
pid = curr_pid;
if (tid == LLDB_INVALID_THREAD_ID)
tid = curr_tid;
- if (pid == curr_pid)
+ if (pid == curr_pid && tid == curr_tid)
{
- if (pthread_setname_np_func (tid, name) == 0)
+ int (*pthread_setname_np_func)(pthread_t thread, const char *name);
+ *reinterpret_cast<void **> (&pthread_setname_np_func) = fn;
+
+ if (pthread_setname_np_func (::pthread_self(), name) == 0)
return true;
}
}
diff --git a/source/Host/linux/Host.cpp b/source/Host/linux/Host.cpp
index c7120e2b7..0efc89ad7 100644
--- a/source/Host/linux/Host.cpp
+++ b/source/Host/linux/Host.cpp
@@ -451,18 +451,17 @@ Host::ThreadCreated (const char *thread_name)
std::string
Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid)
{
+ assert(pid != LLDB_INVALID_PROCESS_ID);
+ assert(tid != LLDB_INVALID_THREAD_ID);
+
// Read /proc/$TID/comm file.
lldb::DataBufferSP buf_sp = ReadProcPseudoFile (tid, "comm");
- if (buf_sp->GetByteSize())
- {
- const char *comm_str = (const char *)buf_sp->GetBytes();
- const char *cr_str = ::strchr(comm_str, '\n');
- size_t length = cr_str ? (cr_str - comm_str) : buf_sp->GetByteSize();
+ const char *comm_str = (const char *)buf_sp->GetBytes();
+ const char *cr_str = ::strchr(comm_str, '\n');
+ size_t length = cr_str ? (cr_str - comm_str) : strlen(comm_str);
- std::string thread_name(comm_str, length);
- return thread_name;
- }
- return std::string("");
+ std::string thread_name(comm_str, length);
+ return thread_name;
}
void
diff --git a/test/logging/TestLogging.py b/test/logging/TestLogging.py
index 12b3b84a9..368708f33 100644
--- a/test/logging/TestLogging.py
+++ b/test/logging/TestLogging.py
@@ -34,7 +34,10 @@ class LogTestCase(TestBase):
if (os.path.exists (log_file)):
os.remove (log_file)
- self.runCmd ("log enable -f '%s' lldb commands" % (log_file))
+ # By default, Debugger::EnableLog() will set log options to
+ # PREPEND_THREAD_NAME + OPTION_THREADSAFE. We don't want the
+ # threadnames here, so we enable just threadsafe (-t).
+ self.runCmd ("log enable -t -f '%s' lldb commands" % (log_file))
self.runCmd ("command alias bp breakpoint")