aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-12-02 19:17:14 +0000
committerPedro Alves <palves@redhat.com>2016-12-02 19:22:48 +0000
commitdf3ee9ca894f7e831713c332aa7820a6463c2435 (patch)
treeef1554a381a5fc332d8fefc214860d3ed4d2f20c /gdb/doc
parentec835369f121c11d6e9484ed8c6c11097ad545c5 (diff)
downloadbinutils-df3ee9ca894f7e831713c332aa7820a6463c2435.zip
binutils-df3ee9ca894f7e831713c332aa7820a6463c2435.tar.gz
binutils-df3ee9ca894f7e831713c332aa7820a6463c2435.tar.bz2
Support an "unlimited" number of user-defined arguments
New in v2: - A few adjustments / simplifications were possible now that we require C++11: . Use std::unique_ptr to make the user_args_stack std::vector own its elements: static std::vector<std::unique_ptr<user_args>> user_args_stack; . use vector::emplace_back to construct elements directly in the corresponding vectors. . use std::to_string instead of adding a gdb::to_string replacement. - Now includes a test. Docs/NEWS are unchanged from v1 and have already been approved. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I recently wrote a user-defined command that could benefit from supporting an unlimited number of arguments: http://palves.net/list-active-signal-handlers-with-gdb/ E.g., 'info signal-dispositions 1 2 3 4 5 6 7 8 9 10 11' However, we currently only support up to 10 arguments passed to user-defined commands ($arg0..$arg9). I can't find a good reason for that, other than "old code with hard coded limits". This patch removes that limit and modernizes the code along the way: - Makes the user_args struct a real C++ class that uses std::vector for storage. - Removes the "next" pointer from within user_args and uses a std::vector to maintain a stack instead. - Adds a new RAII-based scoped_user_args_level class to help push/pop user args in the stack instead of using a cleanup. gdb/ChangeLog: 2016-12-02 Pedro Alves <palves@redhat.com> * NEWS: Mention that user commands now accept an unlimited number of arguments. * cli/cli-script.c: Include <vector>. (struct string_view): New type. (MAXUSERARGS): Delete. (struct user_args): Now a C++ class. (user_args_stack): New. (struct scoped_user_args_level): New type. (execute_user_command): Use scoped_user_args_level. (arg_cleanup): Delete. (setup_user_args): Deleted, and refactored as ... (user_args::user_args): ... this new constructor. Limit of number of arguments removed. (insert_user_defined_cmd_args): Defer to user_args_stack. (user_args::insert_args): New, bits based on old insert_user_defined_cmd_args with limit of number of arguments eliminated. gdb/doc/ChangeLog: 2016-12-02 Pedro Alves <palves@redhat.com> * gdb.texinfo (User-defined Commands): Limit on number of arguments passed to user-defined commands removed; update. gdb/testsuite/ChangeLog: 2016-12-02 Pedro Alves <palves@redhat.com> * gdb.base/commands.exp (user_defined_command_manyargs_test): New procedure. (top level): Call it.
Diffstat (limited to 'gdb/doc')
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo6
2 files changed, 8 insertions, 3 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 18564b6..1bf50f1 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,10 @@
2016-12-02 Pedro Alves <palves@redhat.com>
+ * gdb.texinfo (User-defined Commands): Limit on number of
+ arguments passed to user-defined commands removed; update.
+
+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.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index f4dfac2..a0de7d1 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -24057,9 +24057,9 @@ files.
@cindex arguments, to user-defined commands
A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
which you assign a new name as a command. This is done with the
-@code{define} command. User commands may accept up to 10 arguments
+@code{define} command. User commands may accept an unlimited number of arguments
separated by whitespace. Arguments are accessed within the user command
-via @code{$arg0@dots{}$arg9}. A trivial example:
+via @code{$arg0@dots{}$argN}. A trivial example:
@smallexample
define adder
@@ -24083,7 +24083,7 @@ functions calls.
@cindex argument count in user-defined commands
@cindex how many arguments (user-defined commands)
In addition, @code{$argc} may be used to find out how many arguments have
-been passed. This expands to a number in the range 0@dots{}10.
+been passed.
@smallexample
define adder