This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC/WIP PATCH v2 07/12] Expand %ITSET% and %THREAD% in the prompt


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]