From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21140 invoked by alias); 17 Dec 2011 03:00:08 -0000 Received: (qmail 21074 invoked by uid 22791); 17 Dec 2011 03:00:06 -0000 X-SWARE-Spam-Status: Yes, hits=6.3 required=5.0 tests=AWL,BAYES_00,BOTNET,FROM_12LTRDOM,RCVD_IN_BRBL_LASTEXT,RDNS_DYNAMIC,TW_FC X-Spam-Check-By: sourceware.org Received: from bl16-10-144.dsl.telepac.pt (HELO localhost6.localdomain6) (188.81.10.144) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 17 Dec 2011 02:59:51 +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 pBH2xhYS022718 for ; Sat, 17 Dec 2011 02:59:43 GMT Subject: [RFC/WIP PATCH v2 07/12] Expand %ITSET% and %THREAD% in the prompt To: gdb-patches@sourceware.org From: Pedro Alves Date: Sat, 17 Dec 2011 03:00:00 -0000 Message-ID: <20111217025943.22456.16475.stgit@localhost6.localdomain6> In-Reply-To: <20111217025904.22456.50717.stgit@localhost6.localdomain6> References: <20111217025904.22456.50717.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-12/txt/msg00555.txt.bz2 This adds a simple prompt hook that expands "%ITSET%" to the current set, and "%THREAD%" to the current thread. It was discussed in v1 that it would be better to reuse or follow the syntax of "set extended-prompt". Here's how I use it currently: $ gdb -q -nx -ex "set prompt %ITSET%;%THREAD%> " ~/gdb/tests/threads all;i1.t2> info threads Id Target Id Frame 3 Thread 0x7ffff7028700 (LWP 31058) "threads" __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97 * 2 Thread 0x7ffff7829700 (LWP 31057) "threads" thread_function0 (arg=0x0) at threads.c:63 1 Thread 0x7ffff7fcb720 (LWP 31053) "threads" clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:84 all;i1.t2> all;i1.t2> itfocus i1 warning: 3 threads for inferior 1 in the current i/t set, switching to first Current inferior is 1. i1;i1.t3> This was just a quick hack to make it easy to work on the rest of the stuff without getting lost. I'll make use of this in all examples in this series. v2: - also expand %THREAD%. --- gdb/event-top.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 54 insertions(+), 1 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index a276690..871ab47 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,53 @@ 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%")) + { + if (itset_name (current_itset) != NULL) + obstack_grow_str (&obstack, itset_name (current_itset)); + else + obstack_grow_str (&obstack, itset_spec (current_itset)); + p += sizeof ("%ITSET%") - 1; + continue; + } + + if (CONST_STRNEQ (p, "%THREAD%")) + { + char buf[100]; + + sprintf (buf, "i%d", current_inferior ()->num); + obstack_grow_str (&obstack, buf); + + if (!ptid_equal (inferior_ptid, null_ptid)) + { + sprintf (buf, ".t%d", inferior_thread ()->num); + obstack_grow_str (&obstack, buf); + } + + p += sizeof ("%THREAD%") - 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 +325,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