From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: [RFC/WIP PATCH v2 07/12] Expand %ITSET% and %THREAD% in the prompt
Date: Sat, 17 Dec 2011 03:00:00 -0000 [thread overview]
Message-ID: <20111217025943.22456.16475.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20111217025904.22456.50717.stgit@localhost6.localdomain6>
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
next prev parent reply other threads:[~2011-12-17 3:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-17 2:59 [RFC/WIP I/T sets V2 PATCH 00/14] I/T sets Pedro Alves
2011-12-17 2:59 ` [RFC/WIP PATCH v2 03/12] manythreads.exp: Adjust to handle threads appearing/disappearing after "Program received signal SIGFOO" Pedro Alves
2011-12-17 2:59 ` [RFC/WIP PATCH v2 01/12] Flip to set target-async on by default Pedro Alves
2011-12-23 18:04 ` Marc Khouzam
2011-12-17 3:00 ` Pedro Alves [this message]
2011-12-17 3:00 ` [RFC/WIP PATCH v2 11/12] Default the current itset to the current inferior set (curset) Pedro Alves
2011-12-17 3:00 ` [RFC/WIP PATCH v2 04/12] ia64-sigill.exp: Don't assume there's no infrun output after the prompt Pedro Alves
2011-12-17 3:05 ` [RFC/WIP PATCH v2 08/12] I/T set support for breakpoints - trigger set, and stop set Pedro Alves
2011-12-17 3:07 ` [RFC/WIP PATCH v2 13/12] Comment out new info breakpoints output, in order to not break the test suite Pedro Alves
2011-12-17 3:08 ` [RFC/WIP PATCH v2 12/12] Default "set schedule-multiple" to on Pedro Alves
2011-12-17 8:49 ` [RFC/WIP PATCH v2 14/12] experiment with "scope" Pedro Alves
2011-12-17 12:35 ` [RFC/WIP PATCH v2 02/14] Implement all-stop on top of a target running non-stop mode Pedro Alves
2011-12-17 12:37 ` [RFC/WIP PATCH v2 06/14] Add base itsets support Pedro Alves
2011-12-17 12:37 ` [RFC/WIP PATCH v2 05/14] watchthreads-reorder.exp: Don't assume there's no infrun output after the prompt Pedro Alves
2011-12-17 12:38 ` [RFC/WIP PATCH v2 09/14] Add I/T set support to most execution commands Pedro Alves
2011-12-17 14:05 ` [RFC/WIP PATCH v2 10/14] Parallel steps, wait for all threads to reach their goal Pedro Alves
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=20111217025943.22456.16475.stgit@localhost6.localdomain6 \
--to=pedro@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/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