summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Stubbs <andrew.stubbs@st.com>2005-11-16 12:44:11 +0000
committerAndrew Stubbs <andrew.stubbs@st.com>2005-11-16 12:44:11 +0000
commitb25c4dc17eee35accf5262e75456600dc9daf2a4 (patch)
tree84d2ae692b25de5ccd72eec145a4143f73b15668
parent9d353410049b0eb877d7e78eab53b6b72c15af92 (diff)
downloadgdb-b25c4dc17eee35accf5262e75456600dc9daf2a4.tar.gz
2005-11-16 Andrew Stubbs <andrew.stubbs@st.com>
* NEWS (6.4): Mention $argc. * cli/cli-script.c: Include gdb_assert.h. (locate_arg): Detect $argc. (insert_args): Substitute $argc. * Makefile.in (cli-script.o): Add dependency on gdb_assert.h. doc/ * gdb.texinfo (User-defined commands): Add $argc. Add missing 'end'. Change @var{$arg0 to @code{$arg0.
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/Makefile.in2
-rw-r--r--gdb/NEWS6
-rw-r--r--gdb/cli/cli-script.c40
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo17
6 files changed, 68 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 63c25d7421c..6299afb1df3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2005-11-16 Andrew Stubbs <andrew.stubbs@st.com>
+
+ * NEWS (6.4): Mention $argc.
+ * cli/cli-script.c: Include gdb_assert.h.
+ (locate_arg): Detect $argc.
+ (insert_args): Substitute $argc.
+ * Makefile.in (cli-script.o): Add dependency on gdb_assert.h.
+
2005-11-15 Andrew Stubbs <andrew.stubbs@st.com>
* NEWS: Add --batch-silent, --return-child-result, and --eval-command
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 64c6b229a32..8d8a79e6abb 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -2807,7 +2807,7 @@ cli-logging.o: $(srcdir)/cli/cli-logging.c $(defs_h) $(gdbcmd_h) $(ui_out_h) \
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-logging.c
cli-script.o: $(srcdir)/cli/cli-script.c $(defs_h) $(value_h) $(language_h) \
$(ui_out_h) $(gdb_string_h) $(exceptions_h) $(top_h) $(cli_cmds_h) \
- $(cli_decode_h) $(cli_script_h)
+ $(cli_decode_h) $(cli_script_h) $(gdb_assert_h)
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-script.c
cli-setshow.o: $(srcdir)/cli/cli-setshow.c $(defs_h) $(readline_tilde_h) \
$(value_h) $(gdb_string_h) $(ui_out_h) $(cli_decode_h) $(cli_cmds_h) \
diff --git a/gdb/NEWS b/gdb/NEWS
index c7555c8feae..5780e11767d 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -70,6 +70,12 @@ behavior.
GDB now supports the not-quite-ieee VAX F and D floating point formats.
+* User-defined command support
+
+In addition to using $arg0..$arg9 for argument passing, it is now possible
+to use $argc to determine now many arguments have been passed. See the
+section on user-defined commands in the user manual for more information.
+
*** Changes in GDB 6.3:
* New command line option
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index a4da9c5c586..1a91d2dd186 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -33,6 +33,7 @@
#include "cli/cli-cmds.h"
#include "cli/cli-decode.h"
#include "cli/cli-script.h"
+#include "gdb_assert.h"
/* Prototypes for local functions */
@@ -572,7 +573,8 @@ locate_arg (char *p)
{
while ((p = strchr (p, '$')))
{
- if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4]))
+ if (strncmp (p, "$arg", 4) == 0
+ && (isdigit (p[4]) || p[4] == 'c'))
return p;
p++;
}
@@ -596,12 +598,20 @@ insert_args (char *line)
len += p - line;
i = p[4] - '0';
- if (i >= user_args->count)
+ if (p[4] == 'c')
+ {
+ /* $argc. Number will be <=10. */
+ len += user_args->count == 10 ? 2 : 1;
+ }
+ else if (i >= user_args->count)
{
error (_("Missing argument %d in user function."), i);
return NULL;
}
- len += user_args->a[i].len;
+ else
+ {
+ len += user_args->a[i].len;
+ }
line = p + 5;
}
@@ -625,13 +635,27 @@ insert_args (char *line)
memcpy (new_line, line, p - line);
new_line += p - line;
- i = p[4] - '0';
- len = user_args->a[i].len;
- if (len)
+ if (p[4] == 'c')
+ {
+ gdb_assert (user_args->count >= 0 && user_args->count <= 10);
+ if (user_args->count == 10)
+ {
+ *(new_line++) = '1';
+ *(new_line++) = '0';
+ }
+ else
+ *(new_line++) = user_args->count + '0';
+ }
+ else
{
- memcpy (new_line, user_args->a[i].arg, len);
- new_line += len;
+ i = p[4] - '0';
+ len = user_args->a[i].len;
+ if (len)
+ {
+ memcpy (new_line, user_args->a[i].arg, len);
+ new_line += len;
+ }
}
line = p + 5;
}
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index e39f4ae1d75..e757cd7b90b 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2005-11-16 Andrew Stubbs <andrew.stubbs@st.com>
+
+ * gdb.texinfo (User-defined commands): Add $argc. Add missing 'end'.
+ Change @var{$arg0 to @code{$arg0.
+
2005-11-14 Andrew Stubbs <andrew.stubbs@st.com>
* gdb.texinfo (Choosing files): Add --eval-command.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index a837d169921..bd65b9e862e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -15660,11 +15660,12 @@ 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
separated by whitespace. Arguments are accessed within the user command
-via @var{$arg0@dots{}$arg9}. A trivial example:
+via @code{$arg0@dots{}$arg9}. A trivial example:
@smallexample
define adder
print $arg0 + $arg1 + $arg2
+end
@end smallexample
@noindent
@@ -15680,6 +15681,20 @@ its three arguments. Note the arguments are text substitutions, so they may
reference variables, use complex expressions, or even perform inferior
functions calls.
+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.
+
+@smallexample
+define adder
+ if $argc == 2
+ print $arg0 + $arg1
+ end
+ if $argc == 3
+ print $arg0 + $arg1 + $arg2
+ end
+end
+@end smallexample
+
@table @code
@kindex define