This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] -thread-info new command


Following discussion on thread http://sources.redhat.com/ml/gdb-patches/2007-03/msg00138.html
I propose an implementation of *-thread-info* mi command.


I will propose new testsuite enhancements and document for this command *later* since I prefer that command to be approved (in its format) before going in doc and testsuite work that represents much more work for me.

This command takes an optional thread id in parameter, if omitted the current thread is taken.


Attached is the patch to be discussed. -- Denis




2007-03-19  Denis Pilat  <denis.pilat@st.com>

	* gdb.h (gdb_thread_info): New function.
	* thread.c (gdb_thread_info, do_captured_thread_info): New functions.
	* mi/mi-cmds.c (mi_cmds): Add entry for new MI command -thread-info.
	* mi/mi-cmds.h (mi_cmd_thread_info): New extern.
 	* mi/mi-main.c (mi_cmd_thread_info): New function.

Index: gdb.h
===================================================================
RCS file: /cvs/src/src/gdb/gdb.h,v
retrieving revision 1.6
diff -u -p -r1.6 gdb.h
--- gdb.h	9 Jan 2007 17:58:50 -0000	1.6
+++ gdb.h	19 Mar 2007 14:23:24 -0000
@@ -63,4 +63,8 @@ enum gdb_rc gdb_thread_select (struct ui
 enum gdb_rc gdb_list_thread_ids (struct ui_out *uiout,
 				 char **error_message);
 
+/* Print information for current thread or thread which num is in tidstr.  */
+enum gdb_rc gdb_thread_info (struct ui_out *uiout, char *tidstr,
+			     char **error_message);
+
 #endif
Index: thread.c
===================================================================
RCS file: /cvs/src/src/gdb/thread.c,v
retrieving revision 1.51
diff -u -p -r1.51 thread.c
--- thread.c	28 Feb 2007 17:35:01 -0000	1.51
+++ thread.c	19 Mar 2007 14:23:28 -0000
@@ -737,3 +742,59 @@ The new thread ID must be currently know
   if (!xdb_commands)
     add_com_alias ("t", "thread", class_run, 1);
 }
+
+
+static int
+do_captured_thread_info (struct ui_out *uiout, void *tidstr)
+{
+  int num;
+  struct thread_info *tp;
+  ptid_t current_ptid;
+  char *extra_info;
+
+  /* backup current thread.   */
+  current_ptid = inferior_ptid;
+
+  /* if no argument we consider user needs info for current thread.  */
+  if (tidstr)
+    num = value_as_long (parse_and_eval (tidstr));
+  else
+    num =  pid_to_thread_id (inferior_ptid);
+  
+  tp = find_thread_id (num);
+
+  if (!tp)
+    error (_("Thread ID %d not known."), num);
+
+  if (!thread_alive (tp))
+    error (_("Thread ID %d has terminated."), num);
+
+  if (tidstr)
+    switch_to_thread (tp->ptid);
+
+  ui_out_field_int (uiout, "thread-id", pid_to_thread_id (inferior_ptid));
+
+  /* For mi, we just print location.  */
+  if (ui_out_is_mi_like_p (uiout))
+    print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS);
+  else
+    print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
+
+  extra_info = target_extra_thread_info (tp);
+  if (extra_info)
+    ui_out_field_string (uiout, "thread-extra-info",extra_info);  
+
+  /* Restores the current thread, this also restores the current frame.  */
+  if (tidstr)
+    switch_to_thread (current_ptid);
+
+  return GDB_RC_OK;
+}
+
+
+enum gdb_rc
+gdb_thread_info (struct ui_out *uiout, char *tidstr, char **error_message)
+{
+  return catch_exceptions_with_msg (uiout, do_captured_thread_info, tidstr,
+				    error_message, RETURN_MASK_ALL);
+}
Index: mi/mi-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v
retrieving revision 1.24
diff -u -p -r1.24 mi-cmds.c
--- mi/mi-cmds.c	2 Feb 2007 23:01:27 -0000	1.24
+++ mi/mi-cmds.c	19 Mar 2007 14:23:31 -0000
@@ -128,7 +128,7 @@ struct mi_cmd mi_cmds[] =
   { "target-list-current-targets", { NULL, 0 }, NULL, NULL },
   { "target-list-parameters", { NULL, 0 }, NULL, NULL },
   { "target-select", { NULL, 0 }, mi_cmd_target_select},
-  { "thread-info", { NULL, 0 }, NULL, NULL },
+  { "thread-info", { NULL, 0 }, 0, mi_cmd_thread_info},
   { "thread-list-all-threads", { NULL, 0 }, NULL, NULL },
   { "thread-list-ids", { NULL, 0 }, 0, mi_cmd_thread_list_ids},
   { "thread-select", { NULL, 0 }, 0, mi_cmd_thread_select},
Index: mi/mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.21
diff -u -p -r1.21 mi-cmds.h
--- mi/mi-cmds.h	2 Feb 2007 23:01:27 -0000	1.21
+++ mi/mi-cmds.h	19 Mar 2007 14:23:31 -0000
@@ -104,6 +104,7 @@ extern mi_cmd_args_ftype mi_cmd_target_d
 extern mi_cmd_args_ftype mi_cmd_target_select;
 extern mi_cmd_argv_ftype mi_cmd_thread_list_ids;
 extern mi_cmd_argv_ftype mi_cmd_thread_select;
+extern mi_cmd_argv_ftype mi_cmd_thread_info;
 extern mi_cmd_argv_ftype mi_cmd_var_assign;
 extern mi_cmd_argv_ftype mi_cmd_var_create;
 extern mi_cmd_argv_ftype mi_cmd_var_delete;
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.94
diff -u -p -r1.94 mi-main.c
--- mi/mi-main.c	3 Feb 2007 05:41:15 -0000	1.94
+++ mi/mi-main.c	19 Mar 2007 14:23:35 -0000
@@ -283,6 +283,27 @@ mi_cmd_thread_list_ids (char *command, c
 }
 
 enum mi_cmd_result
+mi_cmd_thread_info (char *command, char **argv, int argc)
+{
+  enum gdb_rc rc = MI_CMD_DONE;
+
+  if (argc == 0)
+    rc = gdb_thread_info (uiout, NULL, &mi_error_message);
+  else if (argc == 1)
+    rc = gdb_thread_info (uiout, argv[0], &mi_error_message);
+  else
+    {
+      mi_error_message = xstrprintf ("mi_cmd_thread_info: USAGE: -thread-info [threadnum].");
+      return MI_CMD_ERROR;
+    }
+
+  if (rc == GDB_RC_FAIL)
+    return MI_CMD_ERROR;
+  else
+    return MI_CMD_DONE;
+}
+
+enum mi_cmd_result
 mi_cmd_data_list_register_names (char *command, char **argv, int argc)
 {
   int regnum, numregs;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]