diff options
author | Pedro Alves <palves@redhat.com> | 2016-12-02 19:17:13 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-12-02 19:17:13 +0000 |
commit | 01770bbde902e075e524b518ac6c1087a4cc1cfb (patch) | |
tree | ea8041e575a6b7447dd92d986da08ab869ae9242 /gdb/doc/gdb.texinfo | |
parent | 7ed7e438bf8a21983eeaeec0617868f8bab06197 (diff) | |
download | gdb-01770bbde902e075e524b518ac6c1087a4cc1cfb.zip gdb-01770bbde902e075e524b518ac6c1087a4cc1cfb.tar.gz gdb-01770bbde902e075e524b518ac6c1087a4cc1cfb.tar.bz2 |
Fix PR 20559 - "eval" command and $arg0...$arg9/$argc substitution
It'd be handy to be able to iterate over command arguments in
user-defined commands, in order to support optional arguments
($arg0..$argN).
I thought I could make it work with "eval", but alas, it doesn't work
currently. E.g., with:
define test
set $i = 0
while $i < $argc
eval "print $arg%d", $i
set $i = $i + 1
end
end
we get:
(gdb) test 1
$1 = void
(gdb) test 1 2 3
$2 = void
$3 = void
$4 = void
(gdb)
The problem is that "eval" doesn't do user-defined command arguments
substitution after expanding its own argument. This patch fixes that,
which makes the example above work:
(gdb) test 1
$1 = 1
(gdb) test 1 2 3
$2 = 1
$3 = 2
$4 = 3
(gdb)
New test included, similar the above, but also exercises expanding
$argc.
I think this is likely to simplify many scripts out there, so I'm
adding an example to the manual and mentioning it in NEWS as well.
gdb/ChangeLog:
2016-12-02 Pedro Alves <palves@redhat.com>
PR cli/20559
* NEWS: Mention "eval" expands user-defined command arguments.
* cli/cli-script.c (execute_control_command): Adjust to rename.
(insert_args): Rename to ...
(insert_user_defined_cmd_args): ... this, and make extern.
* cli/cli-script.h (insert_user_defined_cmd_args): New
declaration.
* printcmd.c: Include "cli/cli-script.h".
(eval_command): Call insert_user_defined_cmd_args.
gdb/doc/ChangeLog:
2016-12-02 Pedro Alves <palves@redhat.com>
PR cli/20559
* gdb.texinfo (Define): Add example of using "eval" to process a
variable number of arguments.
(Output) <eval>: Add anchor.
gdb/testsuite/ChangeLog:
2016-12-02 Pedro Alves <palves@redhat.com>
PR cli/20559
* gdb.base/commands.exp (user_defined_command_args_eval): New
procedure.
(top level): Call it.
Diffstat (limited to 'gdb/doc/gdb.texinfo')
-rw-r--r-- | gdb/doc/gdb.texinfo | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 6ad2754..f4dfac2 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -24096,6 +24096,21 @@ define adder end @end smallexample +Combining with the @code{eval} command (@pxref{eval}) makes it easier +to process a variable number of arguments: + +@smallexample +define adder + set $i = 0 + set $sum = 0 + while $i < $argc + eval "set $sum = $sum + $arg%d", $i + set $i = $i + 1 + end + print $sum +end +@end smallexample + @table @code @kindex define @@ -24526,6 +24541,7 @@ Here's an example of printing DFP types using the above conversion letters: printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl @end smallexample +@anchor{eval} @kindex eval @item eval @var{template}, @var{expressions}@dots{} Convert the values of one or more @var{expressions} under the control of |