* [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
* Re: [PATCH] guile: Add 'history-push!' procedure
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
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2014-02-19 3:45 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: gdb-patches, xdje42
> From: ludo@gnu.org (Ludovic Courtès)
> Date: Tue, 18 Feb 2014 23:40:14 +0100
>
> This patch adds the âhistory-push!â procedure to add a value in the
> history.
Thanks.
> +@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.
> Return its index in the history, or @code{#f} if it is
> +not saved.
Why would it not be saved?
> +This function is useful to make it easier to access individual values
> +from a set of values displayed by a user function.
Not sure what this sentence is about. "Easier" how, and what do you
mean by "user function"?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] guile: Add 'history-push!' procedure
2014-02-19 3:45 ` Eli Zaretskii
@ 2014-02-19 21:43 ` Ludovic Courtès
2014-02-20 16:28 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2014-02-19 21:43 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches, xdje42
Eli Zaretskii <eliz@gnu.org> skribis:
>> From: ludo@gnu.org (Ludovic Courtès)
>> Date: Tue, 18 Feb 2014 23:40:14 +0100
>>
>> This patch adds the ‘history-push!’ procedure to add a value in the
>> history.
>
> Thanks.
>
>> +@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.)
>> 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?
>> +This function is useful to make it easier to access individual values
>> +from a set of values displayed by a user function.
>
> Not sure what this sentence is about. "Easier" how, and what do you
> mean by "user function"?
By “user function”, I mean a Scheme procedure written by the user to
extend GDB functionality. Such a procedure might display several
values–one example is the Guile VM stack walker, which displays local
variables. Instead of simply displaying something like this:
--8<---------------cut here---------------start------------->8---
(gdb) gu (display-vm-frames)
#0 #<program 7ffff5d0e420>
slot 0 -> "scheme@(guile-user)> "
slot 1 -> #<port file 6f70a0>
slot 2 -> #<port file 6f7070>
slot 3 -> #<program bc8100>
[...]
--8<---------------cut here---------------end--------------->8---
it could instead display something like this:
--8<---------------cut here---------------start------------->8---
(gdb) gu (display-vm-frames)
#0 #<program 7ffff5d0e420>
$12 -> "scheme@(guile-user)> "
$13 -> #<port file 6f70a0>
$14 -> #<port file 6f7070>
$15 -> #<program bc8100>
[...]
--8<---------------cut here---------------end--------------->8---
... thus allowing users to directly refer to $12 etc.
How about simply this:
Using this function is useful to provide convenient access to values
manipulated by a Guile extension of GDB.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] guile: Add 'history-push!' procedure
2014-02-19 21:43 ` Ludovic Courtès
@ 2014-02-20 16:28 ` Eli Zaretskii
2014-02-20 22:29 ` Ludovic Courtès
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2014-02-20 16:28 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: gdb-patches, xdje42
> 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.
> >> 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.
> 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.
Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] guile: Add 'history-push!' procedure
2014-02-20 16:28 ` Eli Zaretskii
@ 2014-02-20 22:29 ` Ludovic Courtès
2014-02-24 22:07 ` Doug Evans
0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2014-02-20 22:29 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches, xdje42
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);
+}
\f
/* 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] guile: Add 'history-push!' procedure
2014-02-20 22:29 ` Ludovic Courtès
@ 2014-02-24 22:07 ` Doug Evans
2014-02-26 22:01 ` Ludovic Courtès
0 siblings, 1 reply; 7+ messages in thread
From: Doug Evans @ 2014-02-24 22:07 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: Eli Zaretskii, gdb-patches
On Thu, Feb 20, 2014 at 2:29 PM, Ludovic Courtès <ludo@gnu.org> wrote:
> 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!'.
LGTM.
Thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] guile: Add 'history-push!' procedure
2014-02-24 22:07 ` Doug Evans
@ 2014-02-26 22:01 ` Ludovic Courtès
0 siblings, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2014-02-26 22:01 UTC (permalink / raw)
To: Doug Evans; +Cc: Eli Zaretskii, gdb-patches
Doug Evans <dje@google.com> skribis:
> On Thu, Feb 20, 2014 at 2:29 PM, Ludovic Courtès <ludo@gnu.org> wrote:
[...]
>> 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!'.
>
> LGTM.
Pushed, thanks.
Ludo’.
^ 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).