[Lldb-commits] [lldb] r187599 - Fix Linux Host::GetCurrentThreadID() to return real tid (not pthread_t).
Michael Sartain
mikesart at valvesoftware.com
Thu Aug 1 11:51:09 PDT 2013
Author: mikesart
Date: Thu Aug 1 13:51:08 2013
New Revision: 187599
URL: http://llvm.org/viewvc/llvm-project?rev=187599&view=rev
Log:
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
Modified:
lldb/trunk/source/Host/common/Host.cpp
lldb/trunk/source/Host/linux/Host.cpp
lldb/trunk/test/logging/TestLogging.py
Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=187599&r1=187598&r2=187599&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Thu Aug 1 13:51:08 2013
@@ -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, ll
// 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, ll
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;
}
}
Modified: lldb/trunk/source/Host/linux/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/Host.cpp?rev=187599&r1=187598&r2=187599&view=diff
==============================================================================
--- lldb/trunk/source/Host/linux/Host.cpp (original)
+++ lldb/trunk/source/Host/linux/Host.cpp Thu Aug 1 13:51:08 2013
@@ -451,18 +451,17 @@ Host::ThreadCreated (const char *thread_
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
Modified: lldb/trunk/test/logging/TestLogging.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/logging/TestLogging.py?rev=187599&r1=187598&r2=187599&view=diff
==============================================================================
--- lldb/trunk/test/logging/TestLogging.py (original)
+++ lldb/trunk/test/logging/TestLogging.py Thu Aug 1 13:51:08 2013
@@ -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")
More information about the lldb-commits
mailing list