* Prevent crashes using $arg0
@ 2006-02-07 19:39 Daniel Jacobowitz
2006-02-07 20:46 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2006-02-07 19:39 UTC (permalink / raw)
To: gdb-patches
This patch fixes a crash Andrew Stubbs reported:
if 1 == 1
print $arg0
end
The new response is:
$arg0 used outside of any user function
Comments? Not thrilled with the wording of the error, but it'll do.
--
Daniel Jacobowitz
CodeSourcery
2006-02-07 Daniel Jacobowitz <dan@codesourcery.com>
* cli/cli-script.c (insert_args): Handle NULL user_args.
2006-02-07 Daniel Jacobowitz <dan@codesourcery.com>
* gdb.base/commands.exp (stray_arg0_test): New test.
Index: cli/cli-script.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-script.c,v
retrieving revision 1.32
diff -u -p -r1.32 cli-script.c
--- cli/cli-script.c 17 Dec 2005 22:40:17 -0000 1.32
+++ cli/cli-script.c 7 Feb 2006 19:37:18 -0000
@@ -1,8 +1,8 @@
/* GDB CLI command scripting.
Copyright (c) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
- 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free
- Software Foundation, Inc.
+ 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GDB.
@@ -598,7 +598,9 @@ insert_args (char *line)
len += p - line;
i = p[4] - '0';
- if (p[4] == 'c')
+ if (user_args == NULL)
+ error (_("%.5s used outside of any user function"), p);
+ else if (p[4] == 'c')
{
/* $argc. Number will be <=10. */
len += user_args->count == 10 ? 2 : 1;
Index: testsuite/gdb.base/commands.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/commands.exp,v
retrieving revision 1.14
diff -u -p -r1.14 commands.exp
--- testsuite/gdb.base/commands.exp 7 Mar 2005 21:36:16 -0000 1.14
+++ testsuite/gdb.base/commands.exp 7 Feb 2006 19:37:19 -0000
@@ -1,5 +1,5 @@
# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1997, 1998, 1999, 2000,
-# 2001, 2002, 2003 Free Software Foundation, Inc.
+# 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -563,6 +563,12 @@ proc temporary_breakpoint_commands {} {
timeout { fail "(timeout) run factorial until temporary breakpoint" }
}
}
+
+proc stray_arg0_test { } {
+ gdb_test "if 1 == 1\nprint \$arg0\nend" \
+ "\\\$arg0 used outside of any user function" \
+ "stray_arg0_test #1"
+}
gdbvar_simple_if_test
gdbvar_simple_while_test
@@ -579,3 +585,4 @@ test_command_prompt_position
deprecated_command_test
bp_deleted_in_command_test
temporary_breakpoint_commands
+stray_arg0_test
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Prevent crashes using $arg0 2006-02-07 19:39 Prevent crashes using $arg0 Daniel Jacobowitz @ 2006-02-07 20:46 ` Eli Zaretskii 2006-02-20 16:04 ` Daniel Jacobowitz 0 siblings, 1 reply; 5+ messages in thread From: Eli Zaretskii @ 2006-02-07 20:46 UTC (permalink / raw) To: gdb-patches > Date: Tue, 7 Feb 2006 14:39:32 -0500 > From: Daniel Jacobowitz <drow@false.org> > > This patch fixes a crash Andrew Stubbs reported: > > if 1 == 1 > print $arg0 > end > > The new response is: > $arg0 used outside of any user function Is it possible to have $arg0 behave outside user-defined functions as any other convenience variable? That is, can we have this response instead: (gdb) if 1 == 1 >print $arg0 >end $1 = void (gdb) ? If this is not too hard, it's cleaner, since it doesn't reserve the names of these variables globally. [Time passes...] Actually, I'm quite sure we should behave like I suggested, since we already do that without the if clause: (gdb) print $arg0 $1 = void (gdb) ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Prevent crashes using $arg0 2006-02-07 20:46 ` Eli Zaretskii @ 2006-02-20 16:04 ` Daniel Jacobowitz 2006-02-20 21:22 ` Eli Zaretskii 0 siblings, 1 reply; 5+ messages in thread From: Daniel Jacobowitz @ 2006-02-20 16:04 UTC (permalink / raw) To: Eli Zaretskii; +Cc: gdb-patches On Tue, Feb 07, 2006 at 10:38:28PM +0200, Eli Zaretskii wrote: > Is it possible to have $arg0 behave outside user-defined functions as > any other convenience variable? That is, can we have this response > instead: > > (gdb) if 1 == 1 > >print $arg0 > >end > $1 = void > (gdb) > > ? If this is not too hard, it's cleaner, since it doesn't reserve the > names of these variables globally. Good idea. > [Time passes...] Actually, I'm quite sure we should behave like I > suggested, since we already do that without the if clause: > > (gdb) print $arg0 > $1 = void > (gdb) And let's test that too. Does this look better? Tested x86_64-pc-linux-gnu. -- Daniel Jacobowitz CodeSourcery 2006-02-20 Daniel Jacobowitz <dan@codesourcery.com> * cli/cli-script.c (insert_args): Handle NULL user_args. 2006-02-20 Daniel Jacobowitz <dan@codesourcery.com> * gdb.base/commands.exp (stray_arg0_test): New test. Index: cli/cli-script.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-script.c,v retrieving revision 1.32 diff -u -p -r1.32 cli-script.c --- cli/cli-script.c 17 Dec 2005 22:40:17 -0000 1.32 +++ cli/cli-script.c 20 Feb 2006 16:00:50 -0000 @@ -1,8 +1,8 @@ /* GDB CLI command scripting. Copyright (c) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, - 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free - Software Foundation, Inc. + 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GDB. @@ -590,6 +590,11 @@ insert_args (char *line) char *p, *save_line, *new_line; unsigned len, i; + /* If we are not in a user-defined function, treat $argc, $arg0, et + cetera as normal convenience variables. */ + if (user_args == NULL) + return xstrdup (line); + /* First we need to know how much memory to allocate for the new line. */ save_line = line; len = 0; Index: testsuite/gdb.base/commands.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/commands.exp,v retrieving revision 1.14 diff -u -p -r1.14 commands.exp --- testsuite/gdb.base/commands.exp 7 Mar 2005 21:36:16 -0000 1.14 +++ testsuite/gdb.base/commands.exp 20 Feb 2006 16:00:50 -0000 @@ -1,5 +1,5 @@ # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1997, 1998, 1999, 2000, -# 2001, 2002, 2003 Free Software Foundation, Inc. +# 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -563,6 +563,26 @@ proc temporary_breakpoint_commands {} { timeout { fail "(timeout) run factorial until temporary breakpoint" } } } + +# Test that GDB can handle $arg0 outside of user functions without +# crashing. +proc stray_arg0_test { } { + gdb_test "print \$arg0" \ + "\\\$\[0-9\]* = void" \ + "stray_arg0_test #1" + + gdb_test "if 1 == 1\nprint \$arg0\nend" \ + "\\\$\[0-9\]* = void" \ + "stray_arg0_test #2" + + gdb_test "print \$arg0 = 1" \ + "\\\$\[0-9\]* = 1" \ + "stray_arg0_test #3" + + gdb_test "print \$arg0" \ + "\\\$\[0-9\]* = 1" \ + "stray_arg0_test #4" +} gdbvar_simple_if_test gdbvar_simple_while_test @@ -579,3 +599,4 @@ test_command_prompt_position deprecated_command_test bp_deleted_in_command_test temporary_breakpoint_commands +stray_arg0_test ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Prevent crashes using $arg0 2006-02-20 16:04 ` Daniel Jacobowitz @ 2006-02-20 21:22 ` Eli Zaretskii 2006-03-30 17:20 ` Daniel Jacobowitz 0 siblings, 1 reply; 5+ messages in thread From: Eli Zaretskii @ 2006-02-20 21:22 UTC (permalink / raw) To: gdb-patches > Date: Mon, 20 Feb 2006 11:04:28 -0500 > From: Daniel Jacobowitz <drow@false.org> > Cc: gdb-patches@sourceware.org > > Good idea. > > > [Time passes...] Actually, I'm quite sure we should behave like I > > suggested, since we already do that without the if clause: > > > > (gdb) print $arg0 > > $1 = void > > (gdb) > > And let's test that too. > > Does this look better? Yes, thanks. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Prevent crashes using $arg0 2006-02-20 21:22 ` Eli Zaretskii @ 2006-03-30 17:20 ` Daniel Jacobowitz 0 siblings, 0 replies; 5+ messages in thread From: Daniel Jacobowitz @ 2006-03-30 17:20 UTC (permalink / raw) To: gdb-patches On Mon, Feb 20, 2006 at 10:38:07PM +0200, Eli Zaretskii wrote: > > Date: Mon, 20 Feb 2006 11:04:28 -0500 > > From: Daniel Jacobowitz <drow@false.org> > > Cc: gdb-patches@sourceware.org > > > > Good idea. > > > > > [Time passes...] Actually, I'm quite sure we should behave like I > > > suggested, since we already do that without the if clause: > > > > > > (gdb) print $arg0 > > > $1 = void > > > (gdb) > > > > And let's test that too. > > > > Does this look better? > > Yes, thanks. Thanks, I've checked this in. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-03-30 16:51 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-02-07 19:39 Prevent crashes using $arg0 Daniel Jacobowitz 2006-02-07 20:46 ` Eli Zaretskii 2006-02-20 16:04 ` Daniel Jacobowitz 2006-02-20 21:22 ` Eli Zaretskii 2006-03-30 17:20 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox