From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12129 invoked by alias); 28 Nov 2011 15:39:56 -0000 Received: (qmail 11882 invoked by uid 22791); 28 Nov 2011 15:39:53 -0000 X-SWARE-Spam-Status: No, hits=4.1 required=5.0 tests=AWL,BAYES_00,BOTNET,FROM_12LTRDOM,RDNS_DYNAMIC,TW_FC X-Spam-Check-By: sourceware.org Received: from bl22-166-20.dsl.telepac.pt (HELO localhost6.localdomain6) (2.83.166.20) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Nov 2011 15:39:39 +0000 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu1) with ESMTP id pASFdVBX018028 for ; Mon, 28 Nov 2011 15:39:31 GMT Subject: [RFC/WIP PATCH 07/14] Expand %ITSET% in the prompt to the current I/T set. To: gdb-patches@sourceware.org From: Pedro Alves Date: Mon, 28 Nov 2011 15:40:00 -0000 Message-ID: <20111128153931.17761.19802.stgit@localhost6.localdomain6> In-Reply-To: <20111128153742.17761.21459.stgit@localhost6.localdomain6> References: <20111128153742.17761.21459.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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: 2011-11/txt/msg00766.txt.bz2 This adds a simple hook that allows expanding "%ITSET%" in the prompt to the current set. Here's how I use it currently: $ gdb -q -nx -ex "set prompt %ITSET%> " ~/gdb/tests/threads [all]> info threads Id Target Id Frame 3 Thread 0x7ffff7028700 (LWP 6890) "threads" 0x00007ffff7bcc78e in __lll_lock_wait_private () from /lib/x86_64-linux-gnu/libpthread.so.0 * 2 Thread 0x7ffff7829700 (LWP 6889) "threads" thread_function0 (arg=0x0) at threads.c:63 1 Thread 0x7ffff7fcb720 (LWP 6884) "threads" 0x00007ffff7910011 in clone () from /lib/x86_64-linux-gnu/libc.so.6 [all]> itfocus [1.1] New focus: Current inferior is 1. [1.1]> Not sure this is the way to go, or whether we'll only support this through python. This was simple enough to make sure I could work on the rest of the stuff without getting lost. I'll also make use of this in all examples in this series. --- gdb/event-top.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index a276690..de040cb 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -23,6 +23,7 @@ #include "defs.h" #include "top.h" #include "inferior.h" +#include "itset.h" #include "target.h" #include "terminal.h" /* for job_control */ #include "event-loop.h" @@ -36,6 +37,7 @@ #include "observer.h" #include "continuations.h" #include "gdbcmd.h" /* for dont_repeat() */ +#include "gdb_obstack.h" /* readline include files. */ #include "readline/readline.h" @@ -215,6 +217,38 @@ change_line_handler (void) } } +static char * +expand_gdb_prompt (char *prompt) +{ + struct obstack obstack; + char *p; + + obstack_init (&obstack); + + p = prompt; + while (*p) + { + if (CONST_STRNEQ (p, "%ITSET%")) + { + obstack_grow_str (&obstack, "["); + if (itset_name (current_itset) != NULL) + obstack_grow_str (&obstack, itset_name (current_itset)); + else + obstack_grow_str (&obstack, itset_spec (current_itset)); + obstack_grow_str (&obstack, "]"); + p += sizeof ("%ITSET%") - 1; + continue; + } + + obstack_1grow (&obstack, *p); + p++; + } + + obstack_1grow (&obstack, '\0'); + + return xstrdup (obstack_finish (&obstack)); +} + /* Displays the prompt. If the argument NEW_PROMPT is NULL, the prompt that is displayed is the current top level prompt. Otherwise, it displays whatever NEW_PROMPT is as a local/secondary @@ -276,8 +310,12 @@ display_gdb_prompt (char *new_prompt) } else { + char *top; + /* Display the top level prompt. */ - actual_gdb_prompt = top_level_prompt (); + top = top_level_prompt (); + actual_gdb_prompt = expand_gdb_prompt (top); + xfree (top); } } else