From: Denis PILAT <denis.pilat@st.com>
To: gdb-patches <gdb-patches@sourceware.org>
Cc: Nick Roberts <nickrob@snap.net.nz>
Subject: [RFC] -thread-info new command
Date: Mon, 19 Mar 2007 14:30:00 -0000 [thread overview]
Message-ID: <45FE9E6A.3030906@st.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 526 bytes --]
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
[-- Attachment #2: thread-info.patch --]
[-- Type: text/plain, Size: 5211 bytes --]
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;
next reply other threads:[~2007-03-19 14:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-19 14:30 Denis PILAT [this message]
2007-03-20 1:44 ` Nick Roberts
2007-03-20 3:09 ` Nick Roberts
2007-03-20 3:14 ` Daniel Jacobowitz
2007-03-20 3:26 ` Nick Roberts
2007-03-21 21:09 ` Nick Roberts
2007-03-22 4:35 ` [RFC] gdb_breakpoint " Nick Roberts
2007-03-27 19:54 ` Daniel Jacobowitz
2007-03-27 21:36 ` Nick Roberts
2007-04-04 14:36 ` Denis PILAT
2007-04-10 15:14 ` Daniel Jacobowitz
2007-04-10 14:53 ` Daniel Jacobowitz
2007-04-10 21:54 ` Nick Roberts
2007-04-10 22:04 ` Daniel Jacobowitz
2007-04-11 1:16 ` Nick Roberts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45FE9E6A.3030906@st.com \
--to=denis.pilat@st.com \
--cc=gdb-patches@sourceware.org \
--cc=nickrob@snap.net.nz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox