diff options
Diffstat (limited to 'src/android.c')
| -rw-r--r-- | src/android.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/android.c b/src/android.c index b501a66b25d..76014cbcb3a 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -282,6 +282,46 @@ static volatile sig_atomic_t android_pselect_interrupted; | |||
| 282 | 282 | ||
| 283 | #endif | 283 | #endif |
| 284 | 284 | ||
| 285 | /* Set the task name of the current task to NAME, a string at most 16 | ||
| 286 | characters in length. | ||
| 287 | |||
| 288 | This name is displayed as that of the task (LWP)'s pthread in | ||
| 289 | GDB. */ | ||
| 290 | |||
| 291 | static void | ||
| 292 | android_set_task_name (const char *name) | ||
| 293 | { | ||
| 294 | char proc_name[INT_STRLEN_BOUND (long) | ||
| 295 | + sizeof "/proc/self/task//comm"]; | ||
| 296 | int fd; | ||
| 297 | pid_t lwp; | ||
| 298 | size_t length; | ||
| 299 | |||
| 300 | lwp = gettid (); | ||
| 301 | sprintf (proc_name, "/proc/self/task/%ld/comm", (long) lwp); | ||
| 302 | fd = open (proc_name, O_WRONLY | O_TRUNC); | ||
| 303 | |||
| 304 | if (fd < 1) | ||
| 305 | goto failure; | ||
| 306 | |||
| 307 | length = strlen (name); | ||
| 308 | |||
| 309 | if (write (fd, name, MIN (16, length)) < 0) | ||
| 310 | goto failure; | ||
| 311 | |||
| 312 | close (fd); | ||
| 313 | return; | ||
| 314 | |||
| 315 | failure: | ||
| 316 | __android_log_print (ANDROID_LOG_WARN, __func__, | ||
| 317 | "Failed to set task name for LWP %ld: %s", | ||
| 318 | (long) lwp, strerror (errno)); | ||
| 319 | |||
| 320 | /* Close the file descriptor if it is already set. */ | ||
| 321 | if (fd >= 0) | ||
| 322 | close (fd); | ||
| 323 | } | ||
| 324 | |||
| 285 | static void * | 325 | static void * |
| 286 | android_run_select_thread (void *data) | 326 | android_run_select_thread (void *data) |
| 287 | { | 327 | { |
| @@ -298,6 +338,9 @@ android_run_select_thread (void *data) | |||
| 298 | int sig; | 338 | int sig; |
| 299 | #endif | 339 | #endif |
| 300 | 340 | ||
| 341 | /* Set the name of this thread's LWP for debugging purposes. */ | ||
| 342 | android_set_task_name ("`android_select'"); | ||
| 343 | |||
| 301 | #if __ANDROID_API__ < 16 | 344 | #if __ANDROID_API__ < 16 |
| 302 | /* A completely different implementation is used when building for | 345 | /* A completely different implementation is used when building for |
| 303 | Android versions earlier than 16, because pselect with a signal | 346 | Android versions earlier than 16, because pselect with a signal |
| @@ -797,6 +840,9 @@ android_run_debug_thread (void *data) | |||
| 797 | char *line; | 840 | char *line; |
| 798 | size_t n; | 841 | size_t n; |
| 799 | 842 | ||
| 843 | /* Set the name of this thread's LWP for debugging purposes. */ | ||
| 844 | android_set_task_name ("`android_debug'"); | ||
| 845 | |||
| 800 | fd = (int) (intptr_t) data; | 846 | fd = (int) (intptr_t) data; |
| 801 | file = fdopen (fd, "r"); | 847 | file = fdopen (fd, "r"); |
| 802 | 848 | ||