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]

[PATCH] guile: Add 'history-push!' procedure


Hello,

This patch adds the âhistory-push!â procedure to add a value in the
history.

I think itâs useful to procedures that display a lot of values that the
user may then want to inspect individually.  One example is the Guile VM
stack walker: it displays each VM frame local variables, and having them
in the history makes it easier to recall them later on (similar the what
Guileâs â,localsâ meta-command does.)

WDYT?

Thanks,
Ludoâ.

gdb/
2014-02-19  Ludovic CourtÃs  <ludo@gnu.org>

	* guile/scm-value.c (gdbscm_history_push_x): New function.
	(value_functions): Add it.

gdb/testsuite/
2014-02-19  Ludovic CourtÃs  <ludo@gnu.org>

	* gdb.guile/scm-value.exp (test_value_in_inferior): Add
	test for 'history-push!'.

gdb/doc/
2014-02-19  Ludovic CourtÃs  <ludo@gnu.org>

	* gdb/doc/guile.texi (Basic Guile): Document 'history-push!'.
---
 gdb/doc/guile.texi                    |  9 +++++++++
 gdb/guile/scm-value.c                 | 26 ++++++++++++++++++++++++++
 gdb/testsuite/gdb.guile/scm-value.exp |  8 ++++++++
 3 files changed, 43 insertions(+)

diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi
index ceb98dc..b916dd8 100644
--- a/gdb/doc/guile.texi
+++ b/gdb/doc/guile.texi
@@ -278,6 +278,15 @@ history contains the result of evaluating an expression from Guile's
 command line.
 @end deffn
 
+@deffn {Scheme Procedure} history-push! value
+Push @var{value}, an instance of @code{<gdb:value>}, to @value{GDBN}'s
+value history.  Return its index in the history, or @code{#f} if it is
+not saved.
+
+This function is useful to make it easier to access individual values
+from a set of values displayed by a user function.
+@end deffn
+
 @deffn {Scheme Procedure} parse-and-eval expression
 Parse @var{expression} as an expression in the current language,
 evaluate it, and return the result as a @code{<gdb:value>}.
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index f7f27ce..8198d8b 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -1297,6 +1297,28 @@ gdbscm_history_ref (SCM index)
 
   return vlscm_scm_from_value (res_val);
 }
+
+/* (history-push! <gdb:value>) -> index
+   Push VALUE to GDB's value history.  Return its index in the history,
+   or #f if it is not saved.  */
+
+static SCM
+gdbscm_history_push_x (SCM value)
+{
+  int res_index = -1;
+  struct value *v;
+  volatile struct gdb_exception except;
+
+  v = vlscm_scm_to_value (value);
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      res_index = record_latest_value (v);
+    }
+  GDBSCM_HANDLE_GDB_EXCEPTION (except);
+
+  return res_index < 0 ? SCM_BOOL_F : scm_from_int (res_index);
+}
 
 /* Initialize the Scheme value code.  */
 
@@ -1459,6 +1481,10 @@ Evaluates string in gdb and returns the result as a <gdb:value> object." },
     "\
 Return the specified value from GDB's value history." },
 
+  { "history-push!", 1, 0, 0, gdbscm_history_push_x,
+    "\
+Push the specified value onto GDB's value history." },
+
   END_FUNCTIONS
 };
 
diff --git a/gdb/testsuite/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp
index 3ebdd58..d6e63fb 100644
--- a/gdb/testsuite/gdb.guile/scm-value.exp
+++ b/gdb/testsuite/gdb.guile/scm-value.exp
@@ -59,6 +59,14 @@ proc test_value_in_inferior {} {
     gdb_test "gu (print (value-field s \"a\"))" \
 	"= 3" "access element inside struct using string name"
 
+    # Push value in the value history.
+    gdb_scm_test_silent_cmd "gu (define i (history-push! (make-value 42)))" \
+	"push 42"
+
+    gdb_test "gu i" "\[0-9\]+"
+    gdb_test "gu (history-ref i)" "#<gdb:value 42>"
+    gdb_test "p \$" "= 42"
+
     # Test dereferencing the argv pointer.
 
     # Just get inferior variable argv the value history, available to guile.
-- 
1.8.4


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