This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFA: fix crash in "macro define"
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 25 Jul 2008 10:49:31 -0600
- Subject: RFA: fix crash in "macro define"
- Reply-to: tromey at redhat dot com
Today I noticed that "macro define" with no arguments causes gdb to
crash.
This patch fixes the bug. It also adds a regression test.
Built and tested on x86 F8. Ok?
Tom
ChangeLog:
2008-07-25 Tom Tromey <tromey@redhat.com>
* macrocmd.c (macro_define_command): Check for NULL argument.
testsuite/ChangeLog:
2008-07-25 Tom Tromey <tromey@redhat.com>
* gdb.base/macscp.exp: Add regression test for "macro define" 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 25 Jul 2008 16:17:45 -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));
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 25 Jul 2008 16:17:46 -0000
@@ -472,3 +472,8 @@
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"