This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFA: fix crash in "macro define"
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Sat, 26 Jul 2008 13:05:53 -0600
- Subject: Re: RFA: fix crash in "macro define"
- References: <m34p6dhpt0.fsf@fleche.redhat.com>
- Reply-to: Tom Tromey <tromey at redhat dot com>
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
Tom> Today I noticed that "macro define" with no arguments causes gdb
Tom> to crash.
Whoops, I neglected to check "macro undef", which has the same bug.
New patch appended. It includes a regression test for undef as well.q
Built & tested on x86 F8. Ok?
Tom
ChangeLog:
2008-07-26 Tom Tromey <tromey@redhat.com>
* macrocmd.c (macro_define_command): Check for NULL argument.
(macro_undef_command): Likewise.
testsuite/ChangeLog:
2008-07-26 Tom Tromey <tromey@redhat.com>
* gdb.base/macscp.exp: Add regression test for "macro define" or
"macro undef" with no arguments.
Index: macrocmd.c
===================================================================
RCS file: /cvs/src/src/gdb/macrocmd.c,v
retrieving revision 1.14
diff -u -r1.14 macrocmd.c
--- macrocmd.c 18 Jul 2008 20:55:32 -0000 1.14
+++ macrocmd.c 26 Jul 2008 19:04:02 -0000
@@ -235,8 +235,12 @@
{
struct macro_definition new_macro;
char *name = NULL;
- struct cleanup *cleanup_chain = make_cleanup (free_macro_definition_ptr,
- &new_macro);
+ struct cleanup *cleanup_chain;
+
+ if (!exp)
+ error (_("usage: macro define NAME[(ARGUMENT-LIST)] [REPLACEMENT-LIST]"));
+
+ cleanup_chain = make_cleanup (free_macro_definition_ptr, &new_macro);
make_cleanup (free_current_contents, &name);
memset (&new_macro, 0, sizeof (struct macro_definition));
@@ -308,6 +312,10 @@
macro_undef_command (char *exp, int from_tty)
{
char *name;
+
+ if (!exp)
+ error (_("usage: macro undef NAME"));
+
skip_ws (&exp);
name = extract_identifier (&exp);
if (! name)
Index: testsuite/gdb.base/macscp.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/macscp.exp,v
retrieving revision 1.8
diff -u -r1.8 macscp.exp
--- testsuite/gdb.base/macscp.exp 18 Jul 2008 20:55:33 -0000 1.8
+++ testsuite/gdb.base/macscp.exp 26 Jul 2008 19:04:05 -0000
@@ -472,3 +472,13 @@
gdb_test "print M" \
"No symbol \"M\" in current context\." \
"print expression with macro after user undef."
+
+# Regression test; this used to crash.
+gdb_test "macro define" \
+ "usage: macro define.*" \
+ "macro define with no arguments"
+
+# Regression test; this used to crash.
+gdb_test "macro undef" \
+ "usage: macro undef.*" \
+ "macro undef with no arguments"