diff options
author | Vladimir Prus <vladimir@codesourcery.com> | 2008-03-15 13:53:25 +0000 |
---|---|---|
committer | Vladimir Prus <vladimir@codesourcery.com> | 2008-03-15 13:53:25 +0000 |
commit | 8e8901c5c22072ecab98e3f3e121df2bf0aefc01 (patch) | |
tree | 25ab58963d0a6a3199cd4190561f6417efb5a435 /gdb/thread.c | |
parent | 7d1e6fb8639f8b672daaa338744003b4b2595d37 (diff) | |
download | gdb-8e8901c5c22072ecab98e3f3e121df2bf0aefc01.zip gdb-8e8901c5c22072ecab98e3f3e121df2bf0aefc01.tar.gz gdb-8e8901c5c22072ecab98e3f3e121df2bf0aefc01.tar.bz2 |
Implement -thread-info.
* gdbthread.h (print_thread_info): Declare.
* thread.c (print_thread_info): New, extracted
from info_threads_command and adjusted to
work for CLI and MI.
(info_threads_command): Use print_thread_info.
* Makefile.in: Update dependencies.
* mi/mi-cmds.c (mi_cmds): Specify a handler
for -thread-info.
* mi/mi-cmds.h (mi_cmd_thread_info): Declare.
* mi/mi-main.c (mi_cmd_thread_info): New.
(mi_cmd_list_features): Include 'thread-info'.
Diffstat (limited to 'gdb/thread.c')
-rw-r--r-- | gdb/thread.c | 80 |
1 files changed, 64 insertions, 16 deletions
diff --git a/gdb/thread.c b/gdb/thread.c index 97facd2..1ce514a 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -407,15 +407,14 @@ prune_threads (void) } } -/* Print information about currently known threads - - * Note: this has the drawback that it _really_ switches - * threads, which frees the frame cache. A no-side - * effects info-threads command would be nicer. - */ - -static void -info_threads_command (char *arg, int from_tty) +/* Prints the list of threads and their details on UIOUT. + This is a version of 'info_thread_command' suitable for + use from MI. + If REQESTED_THREAD is not -1, it's the GDB id of the thread + that should be printed. Otherwise, all threads are + printed. */ +void +print_thread_info (struct ui_out *uiout, int requested_thread) { struct thread_info *tp; ptid_t current_ptid; @@ -423,45 +422,94 @@ info_threads_command (char *arg, int from_tty) struct cleanup *old_chain; struct frame_id saved_frame_id; char *extra_info; + int current_thread = -1; /* Backup current thread and selected frame. */ saved_frame_id = get_frame_id (get_selected_frame (NULL)); old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id); + make_cleanup_ui_out_list_begin_end (uiout, "threads"); + prune_threads (); target_find_new_threads (); current_ptid = inferior_ptid; for (tp = thread_list; tp; tp = tp->next) { + struct cleanup *chain2; + + if (requested_thread != -1 && tp->num != requested_thread) + continue; + + chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); + if (ptid_equal (tp->ptid, current_ptid)) - printf_filtered ("* "); + { + current_thread = tp->num; + ui_out_text (uiout, "* "); + } else - printf_filtered (" "); + ui_out_text (uiout, " "); - printf_filtered ("%d %s", tp->num, target_tid_to_str (tp->ptid)); + ui_out_field_int (uiout, "id", tp->num); + ui_out_text (uiout, " "); + ui_out_field_string (uiout, "target-id", target_tid_to_str (tp->ptid)); extra_info = target_extra_thread_info (tp); if (extra_info) - printf_filtered (" (%s)", extra_info); - puts_filtered (" "); + { + ui_out_text (uiout, " ("); + ui_out_field_string (uiout, "details", extra_info); + ui_out_text (uiout, ")"); + } + ui_out_text (uiout, " "); /* That switch put us at the top of the stack (leaf frame). */ switch_to_thread (tp->ptid); - print_stack_frame (get_selected_frame (NULL), 0, LOCATION); + print_stack_frame (get_selected_frame (NULL), + /* For MI output, print frame level. */ + ui_out_is_mi_like_p (uiout), + LOCATION); + + do_cleanups (chain2); } /* Restores the current thread and the frame selected before the "info threads" command. */ do_cleanups (old_chain); + if (requested_thread == -1) + { + gdb_assert (current_thread != -1); + if (ui_out_is_mi_like_p (uiout)) + ui_out_field_int (uiout, "current-thread-id", current_thread); + } + /* If case we were not able to find the original frame, print the new selected frame. */ if (frame_find_by_id (saved_frame_id) == NULL) { warning (_("Couldn't restore frame in current thread, at frame 0")); - print_stack_frame (get_selected_frame (NULL), 0, LOCATION); + /* For MI, we should probably have a notification about + current frame change. But this error is not very likely, so + don't bother for now. */ + if (!ui_out_is_mi_like_p (uiout)) + print_stack_frame (get_selected_frame (NULL), 0, LOCATION); } } + +/* Print information about currently known threads + + * Note: this has the drawback that it _really_ switches + * threads, which frees the frame cache. A no-side + * effects info-threads command would be nicer. + */ + +static void +info_threads_command (char *arg, int from_tty) +{ + print_thread_info (uiout, -1); +} + /* Switch from one thread to another. */ void |