Index: base/threading/platform_thread_android.cc |
diff --git a/base/threading/platform_thread_android.cc b/base/threading/platform_thread_android.cc |
index 0dbb1913d0e08af10fb86330a66dc75b41edd40f..bd0b4b33db74a137fa1dd0508f39586362857d5a 100644 |
--- a/base/threading/platform_thread_android.cc |
+++ b/base/threading/platform_thread_android.cc |
@@ -5,6 +5,7 @@ |
#include "base/threading/platform_thread.h" |
#include <errno.h> |
+#include <sys/prctl.h> |
#include <sys/resource.h> |
#include "base/android/jni_android.h" |
@@ -77,6 +78,18 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, |
void PlatformThread::SetName(const char* name) { |
ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
tracked_objects::ThreadData::InitializeThreadContext(name); |
+ |
+ // Like linux, on android we can get the thread names to show up in the |
+ // debugger by setting the process name for the LWP. |
+ // We don't want to do this for the main thread because that would rename |
+ // the process, causing tools like killall to stop working. |
+ if (PlatformThread::CurrentId() == getpid()) |
+ return; |
+ |
+ // Set the name for the LWP (which gets truncated to 15 characters). |
+ int err = prctl(PR_SET_NAME, name); |
+ if (err < 0 && errno != EPERM) |
+ DPLOG(ERROR) << "prctl(PR_SET_NAME)"; |
} |