diff options
author | Pedro Alves <palves@redhat.com> | 2016-01-13 10:56:06 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-01-13 10:59:14 +0000 |
commit | 43792cf0de3a49fb871d432343672bdf16270e99 (patch) | |
tree | a0c0937a8ca20d3bbfd466ebf2e1f65f5aabcb24 /gdb/thread.c | |
parent | 8465445732dc04c3fb6cf954274e12d06b274f08 (diff) | |
download | gdb-43792cf0de3a49fb871d432343672bdf16270e99.zip gdb-43792cf0de3a49fb871d432343672bdf16270e99.tar.gz gdb-43792cf0de3a49fb871d432343672bdf16270e99.tar.bz2 |
Centralize thread ID printing
Add a new function to print a thread ID, in the style of paddress,
plongest, etc. and adjust all CLI-reachable paths to use it.
This gives us a single place to tweak to print inferior-qualified
thread IDs later:
- [Switching to thread 1 (Thread 0x7ffff7fc2740 (LWP 8155))]
+ [Switching to thread 1.1 (Thread 0x7ffff7fc2740 (LWP 8155))]
etc., though for now, this has no user-visible change.
No regressions on x86_64 Fedora 20.
gdb/ChangeLog:
2016-01-13 Pedro Alves <palves@redhat.com>
* breakpoint.c (remove_threaded_breakpoints)
(print_one_breakpoint_location): Use print_thread_id.
* btrace.c (btrace_enable, btrace_disable, btrace_teardown)
(btrace_fetch, btrace_clear): Use print_thread_id.
* common/print-utils.c (CELLSIZE): Delete.
(get_cell): Rename to ...
(get_print_cell): ... this and made extern. Adjust call callers.
Adjust to use PRINT_CELL_SIZE.
* common/print-utils.h (get_print_cell): Declare.
(PRINT_CELL_SIZE): New.
* gdbthread.h (print_thread_id): Declare.
* infcmd.c (signal_command): Use print_thread_id.
* inferior.c (print_inferior): Use print_thread_id.
* infrun.c (handle_signal_stop)
(insert_exception_resume_breakpoint)
(insert_exception_resume_from_probe)
(print_signal_received_reason): Use print_thread_id.
* record-btrace.c (record_btrace_info)
(record_btrace_resume_thread, record_btrace_cancel_resume)
(record_btrace_step_thread, record_btrace_wait): Use
print_thread_id.
* thread.c (thread_apply_all_command): Use print_thread_id.
(print_thread_id): New function.
(thread_apply_command): Use print_thread_id.
(thread_command, thread_find_command, do_captured_thread_select):
Use print_thread_id.
Diffstat (limited to 'gdb/thread.c')
-rw-r--r-- | gdb/thread.c | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/gdb/thread.c b/gdb/thread.c index 56526e4..0ad26fc 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -1610,6 +1610,17 @@ make_cleanup_restore_current_thread (void) restore_current_thread_cleanup_dtor); } +/* See gdbthread.h. */ + +const char * +print_thread_id (struct thread_info *thr) +{ + char *s = get_print_cell (); + + xsnprintf (s, PRINT_CELL_SIZE, "%d", thr->num); + return s; +} + /* If non-zero tp_array_compar should sort in ascending order, otherwise in descending order. */ @@ -1700,8 +1711,8 @@ thread_apply_all_command (char *cmd, int from_tty) if (thread_alive (tp_array[k])) { switch_to_thread (tp_array[k]->ptid); - printf_filtered (_("\nThread %d (%s):\n"), - tp_array[k]->num, + printf_filtered (_("\nThread %s (%s):\n"), + print_thread_id (tp_array[k]), target_pid_to_str (inferior_ptid)); execute_command (cmd, from_tty); @@ -1713,6 +1724,8 @@ thread_apply_all_command (char *cmd, int from_tty) do_cleanups (old_chain); } +/* Implementation of the "thread apply" command. */ + static void thread_apply_command (char *tidlist, int from_tty) { @@ -1779,13 +1792,15 @@ thread_command (char *tidstr, int from_tty) if (target_has_stack) { + struct thread_info *tp = inferior_thread (); + if (is_exited (inferior_ptid)) - printf_filtered (_("[Current thread is %d (%s) (exited)]\n"), - pid_to_thread_id (inferior_ptid), + printf_filtered (_("[Current thread is %s (%s) (exited)]\n"), + print_thread_id (tp), target_pid_to_str (inferior_ptid)); else - printf_filtered (_("[Current thread is %d (%s)]\n"), - pid_to_thread_id (inferior_ptid), + printf_filtered (_("[Current thread is %s (%s)]\n"), + print_thread_id (tp), target_pid_to_str (inferior_ptid)); } else @@ -1834,32 +1849,32 @@ thread_find_command (char *arg, int from_tty) { if (tp->name != NULL && re_exec (tp->name)) { - printf_filtered (_("Thread %d has name '%s'\n"), - tp->num, tp->name); + printf_filtered (_("Thread %s has name '%s'\n"), + print_thread_id (tp), tp->name); match++; } tmp = target_thread_name (tp); if (tmp != NULL && re_exec (tmp)) { - printf_filtered (_("Thread %d has target name '%s'\n"), - tp->num, tmp); + printf_filtered (_("Thread %s has target name '%s'\n"), + print_thread_id (tp), tmp); match++; } tmp = target_pid_to_str (tp->ptid); if (tmp != NULL && re_exec (tmp)) { - printf_filtered (_("Thread %d has target id '%s'\n"), - tp->num, tmp); + printf_filtered (_("Thread %s has target id '%s'\n"), + print_thread_id (tp), tmp); match++; } tmp = target_extra_thread_info (tp); if (tmp != NULL && re_exec (tmp)) { - printf_filtered (_("Thread %d has extra info '%s'\n"), - tp->num, tmp); + printf_filtered (_("Thread %s has extra info '%s'\n"), + print_thread_id (tp), tmp); match++; } } @@ -1899,7 +1914,7 @@ do_captured_thread_select (struct ui_out *uiout, void *tidstr) annotate_thread_changed (); ui_out_text (uiout, "[Switching to thread "); - ui_out_field_int (uiout, "new-thread-id", pid_to_thread_id (inferior_ptid)); + ui_out_field_string (uiout, "new-thread-id", print_thread_id (tp)); ui_out_text (uiout, " ("); ui_out_text (uiout, target_pid_to_str (inferior_ptid)); ui_out_text (uiout, ")]"); |