From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27754 invoked by alias); 19 Mar 2007 14:30:20 -0000 Received: (qmail 27736 invoked by uid 22791); 19 Mar 2007 14:30:19 -0000 X-Spam-Check-By: sourceware.org Received: from lon-del-02.spheriq.net (HELO lon-del-02.spheriq.net) (195.46.50.98) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 19 Mar 2007 14:30:12 +0000 Received: from lon-out-01.spheriq.net ([195.46.50.129]) by lon-del-02.spheriq.net with ESMTP id l2JEULMt018464 for ; Mon, 19 Mar 2007 14:30:21 GMT Received: from lon-cus-01.spheriq.net (lon-cus-01.spheriq.net [195.46.50.37]) by lon-out-01.spheriq.net with ESMTP id l2JEU62k029740 for ; Mon, 19 Mar 2007 14:30:07 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by lon-cus-01.spheriq.net with ESMTP id l2JEU5mt014932 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Mon, 19 Mar 2007 14:30:06 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 84B17DA42; Mon, 19 Mar 2007 14:30:04 +0000 (GMT) Received: from mail1.cro.st.com (mail1.cro.st.com [164.129.40.131]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2C9FE4757B; Mon, 19 Mar 2007 14:30:04 +0000 (GMT) Received: from [164.129.44.95] (crx595.cro.st.com [164.129.44.95]) by mail1.cro.st.com (MOS 3.7.5a-GA) with ESMTP id CKA06844 (AUTH "denis pilat"); Mon, 19 Mar 2007 15:30:02 +0100 (CET) Message-ID: <45FE9E6A.3030906@st.com> Date: Mon, 19 Mar 2007 14:30:00 -0000 From: Denis PILAT User-Agent: Thunderbird 1.5.0.10 (X11/20070221) MIME-Version: 1.0 To: gdb-patches Cc: Nick Roberts Subject: [RFC] -thread-info new command Content-Type: multipart/mixed; boundary="------------080802070401060902020502" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-03/txt/msg00167.txt.bz2 This is a multi-part message in MIME format. --------------080802070401060902020502 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 526 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 --------------080802070401060902020502 Content-Type: text/plain; name="thread-info.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="thread-info.patch" Content-length: 5211 2007-03-19 Denis Pilat * 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; --------------080802070401060902020502--