This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] guile: Add 'history-push!' procedure
- From: ludo at gnu dot org (Ludovic CourtÃs)
- To: Eli Zaretskii <eliz at gnu dot org>
- Cc: gdb-patches at sourceware dot org, xdje42 at gmail dot com
- Date: Thu, 20 Feb 2014 23:29:48 +0100
- Subject: Re: [PATCH] guile: Add 'history-push!' procedure
- Authentication-results: sourceware.org; auth=none
- References: <871tz06o4x dot fsf at gnu dot org> <83txbv69z9 dot fsf at gnu dot org> <877g8q7p80 dot fsf at gnu dot org> <834n3t694s dot fsf at gnu dot org>
Eli Zaretskii <eliz@gnu.org> skribis:
>> From: ludo@gnu.org (Ludovic CourtÃs)
>> Cc: gdb-patches@sourceware.org, xdje42@gmail.com
>> Date: Wed, 19 Feb 2014 22:43:43 +0100
>>
>> >> +@deffn {Scheme Procedure} history-push! value
>> >> +Push @var{value}, an instance of @code{<gdb:value>}, to @value{GDBN}'s
>> >> +value history.
>> >
>> > I think we should explain what "push" means in this context. It is
>> > not self-evident.
>>
>> Right. How about s/push/append/? (In the procedure name as well.)
>
> Fine with me.
Done.
>> >> Return its index in the history, or @code{#f} if it is
>> >> +not saved.
>> >
>> > Why would it not be saved?
>>
>> Good question. The doc above ârecord_latest_valueâ mentions that it can
>> return -1, but I see no path leading to that. Can I assume that -1 is
>> never returned?
>
> I don't know, but if that is your reading, I see no reason not to.
OK, I changed it to assume it always returns a positive value.
>> How about simply this:
>>
>> Using this function is useful to provide convenient access to values
>> manipulated by a Guile extension of GDB.
>
> I suggest
>
> Putting into history values returned by Guile extensions will allow
> the user convenient access to those values via CLI history
> facilities.
Perfect.
The version below incorporates those changes.
Thanks,
Ludoâ.
gdb/
2014-02-21 Ludovic CourtÃs <ludo@gnu.org>
* guile/scm-value.c (gdbscm_history_append_x): New function.
(value_functions): Add it.
gdb/testsuite/
2014-02-21 Ludovic CourtÃs <ludo@gnu.org>
* gdb.guile/scm-value.exp (test_value_in_inferior): Add
test for 'history-append!'.
gdb/doc/
2014-02-21 Ludovic CourtÃs <ludo@gnu.org>
* gdb/doc/guile.texi (Basic Guile): Document 'history-append!'.
---
gdb/doc/guile.texi | 9 +++++++++
gdb/guile/scm-value.c | 25 +++++++++++++++++++++++++
gdb/testsuite/gdb.guile/scm-value.exp | 8 ++++++++
3 files changed, 42 insertions(+)
diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi
index ceb98dc..56d817e 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-append! value
+Append @var{value}, an instance of @code{<gdb:value>}, to @value{GDBN}'s
+value history. Return its index in the history.
+
+Putting into history values returned by Guile extensions will allow
+the user convenient access to those values via CLI history
+facilities.
+@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..8ca0762 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -1297,6 +1297,27 @@ gdbscm_history_ref (SCM index)
return vlscm_scm_from_value (res_val);
}
+
+/* (history-append! <gdb:value>) -> index
+ Append VALUE to GDB's value history. Return its index in the history. */
+
+static SCM
+gdbscm_history_append_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 scm_from_int (res_index);
+}
/* Initialize the Scheme value code. */
@@ -1459,6 +1480,10 @@ Evaluates string in gdb and returns the result as a <gdb:value> object." },
"\
Return the specified value from GDB's value history." },
+ { "history-append!", 1, 0, 0, gdbscm_history_append_x,
+ "\
+Append 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..89f0ff1 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"
+ # Append value in the value history.
+ gdb_scm_test_silent_cmd "gu (define i (history-append! (make-value 42)))" \
+ "append 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