summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorEd Maste <emaste@freebsd.org>2013-07-25 19:10:32 +0000
committerEd Maste <emaste@freebsd.org>2013-07-25 19:10:32 +0000
commit02983be252186caf1afb42f54786f5d88420cc13 (patch)
tree02c6ea3ff3878764b4e798f16859b98ee6f808bd /lldb/source
parent72090eea73ef0c556277730dad5a58cb9c77dc52 (diff)
downloadbcm5719-llvm-02983be252186caf1afb42f54786f5d88420cc13.tar.gz
bcm5719-llvm-02983be252186caf1afb42f54786f5d88420cc13.zip
Set thread names on FreeBSD
Also move the logic to shorten thread names from linux/Host.cpp to a new SetShortThreadName as both FreeBSD and Linux need the functionality. llvm-svn: 187149
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Host/common/Host.cpp47
-rw-r--r--lldb/source/Host/freebsd/Host.cpp2
-rw-r--r--lldb/source/Host/linux/Host.cpp27
3 files changed, 50 insertions, 26 deletions
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index c2f63565a34..5aee4ad2094 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -648,6 +648,22 @@ Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
return true;
}
return false;
+#elif defined (__FreeBSD__)
+ 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;
+
+ // Set the pthread name if possible
+ if (pid == curr_pid && tid == curr_tid)
+ {
+ ::pthread_set_name_np(::pthread_self(), name);
+ return true;
+ }
+ return false;
#elif defined (__linux__) || defined (__GLIBC__)
void *fn = dlsym (RTLD_DEFAULT, "pthread_setname_np");
if (fn)
@@ -676,6 +692,37 @@ Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
#endif
}
+bool
+Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
+ const char *thread_name, size_t len)
+{
+ char *namebuf = (char *)::malloc (len + 1);
+
+ // Thread names are coming in like '<lldb.comm.debugger.edit>' and
+ // '<lldb.comm.debugger.editline>'. So just chopping the end of the string
+ // off leads to a lot of similar named threads. Go through the thread name
+ // and search for the last dot and use that.
+ const char *lastdot = ::strrchr (thread_name, '.');
+
+ if (lastdot && lastdot != thread_name)
+ thread_name = lastdot + 1;
+ ::strncpy (namebuf, thread_name, len);
+ namebuf[len] = 0;
+
+ int namebuflen = strlen(namebuf);
+ if (namebuflen > 0)
+ {
+ if (namebuf[namebuflen - 1] == '(' || namebuf[namebuflen - 1] == '>')
+ {
+ // Trim off trailing '(' and '>' characters for a bit more cleanup.
+ namebuflen--;
+ namebuf[namebuflen] = 0;
+ }
+ return Host::SetThreadName (pid, tid, namebuf);
+ }
+ return false;
+}
+
FileSpec
Host::GetProgramFileSpec ()
{
diff --git a/lldb/source/Host/freebsd/Host.cpp b/lldb/source/Host/freebsd/Host.cpp
index a17be9f4719..405e7eacf5a 100644
--- a/lldb/source/Host/freebsd/Host.cpp
+++ b/lldb/source/Host/freebsd/Host.cpp
@@ -75,6 +75,8 @@ Host::ThreadCreated (const char *thread_name)
{
::pthread_setspecific (g_thread_create_key, new FreeBSDThread(thread_name));
}
+
+ Host::SetShortThreadName (LLDB_INVALID_PROCESS_ID, LLDB_INVALID_THREAD_ID, thread_name, 16);
}
std::string
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index a756a47ffa8..cdcff1f3d75 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -451,32 +451,7 @@ Host::ThreadCreated (const char *thread_name)
{
if (!Host::SetThreadName (LLDB_INVALID_PROCESS_ID, LLDB_INVALID_THREAD_ID, thread_name))
{
- // pthread_setname_np_func can fail if the thread name is longer than
- // the supported limit on Linux. When this occurs, the error ERANGE is returned
- // and SetThreadName will fail. Let's drop it down to 16 characters and try again.
- char namebuf[16];
-
- // Thread names are coming in like '<lldb.comm.debugger.edit>' and '<lldb.comm.debugger.editline>'
- // So just chopping the end of the string off leads to a lot of similar named threads.
- // Go through the thread name and search for the last dot and use that.
- const char *lastdot = ::strrchr( thread_name, '.' );
-
- if (lastdot && lastdot != thread_name)
- thread_name = lastdot + 1;
- ::strncpy (namebuf, thread_name, sizeof(namebuf));
- namebuf[ sizeof(namebuf) - 1 ] = 0;
-
- int namebuflen = strlen(namebuf);
- if (namebuflen > 0)
- {
- if (namebuf[namebuflen - 1] == '(' || namebuf[namebuflen - 1] == '>')
- {
- // Trim off trailing '(' and '>' characters for a bit more cleanup.
- namebuflen--;
- namebuf[namebuflen] = 0;
- }
- Host::SetThreadName (LLDB_INVALID_PROCESS_ID, LLDB_INVALID_THREAD_ID, namebuf);
- }
+ Host::SetShortThreadName (LLDB_INVALID_PROCESS_ID, LLDB_INVALID_THREAD_ID, thread_name, 16);
}
}
OpenPOWER on IntegriCloud