public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] guile: Add 'history-push!' procedure
@ 2014-02-18 22:40 Ludovic Courtès
  2014-02-19  3:45 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2014-02-18 22:40 UTC (permalink / raw)
  To: gdb-patches, Doug Evans

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);
+}
 \f
 /* 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-02-26 22:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-18 22:40 [PATCH] guile: Add 'history-push!' procedure Ludovic Courtès
2014-02-19  3:45 ` Eli Zaretskii
2014-02-19 21:43   ` Ludovic Courtès
2014-02-20 16:28     ` Eli Zaretskii
2014-02-20 22:29       ` Ludovic Courtès
2014-02-24 22:07         ` Doug Evans
2014-02-26 22:01           ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).