This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] fix for rbreak issue w/ "Junk at end of arguments"


Hi folks,

When you 'rbreak' a pattern that matches certain symbols (e.g., those
containing "@plt"), you will get a "Junk at end of arguments" error
when applying the breakpoints.

For instance, given the example program:

#include <stdio.h>
int foo() {
        return 37;
}

int main() {
        printf("%d\n", foo());
}

compiled with gcc -g and run under a clean build of gdb as of last
night (on a 'clean' CentOS 5 system, as well as an modded
Debian-derivative system):

[cgd@blue tmp]$ gdb/bld.clean/gdb/gdb a.out
GNU gdb 6.8.50.20080315-cvs
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu"...
(gdb) rbreak printf
Function "printf" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y

Breakpoint 1 (printf@plt) pending.
<function, no debug info> printf@plt;
(gdb) run
Starting program: /tmp/a.out
Error in re-setting breakpoint 1: Junk at end of arguments.
37

Program exited with code 03.
(gdb)

Note the pending breakpoint query, the error setting the breakpoint,
and the fact that the breakpoint wasn't hit.


What seems to be happening is that when setting the breakpoint,
breakpoint_re_set_one is called.  This calls decode_line_1 which in
turn calls skip_quoted, which ultimately leaves "@plt" as something to
be left over after stopping the symbol name at "printf".  (My analysis
may be a bit off, I actually debugged this using an optimized gdb
binary, stupid me.)


The attached patch fixes this by quoting the symbol name.  (The symbol
name is actually quoted in one case in rbreak_command already, this
gets the other.)

With the patch, as expected:

[cgd@blue tmp]$ gdb/bld.dirty/gdb/gdb a.out
GNU gdb 6.8.50.20080315-cvs
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu"...
(gdb) rbreak printf
Breakpoint 1 at 0x400398
<function, no debug info> printf@plt;
(gdb) run
Starting program: /tmp/a.out

Breakpoint 1, 0x0000000000400398 in printf@plt ()
(gdb)

No pending breakpoint query, no breakpoint-setting error, and
breakpoint is hit as expected.


(FWIW, i originally tripped over this on a symbol other than printf.
That was just something easy for the example.  And, others out in the
world have seen this too, e.g.,
http://community.livejournal.com/evan_tech .)


Tested manually as shown above, plus by running gdb 'make check'
before/after symtab.c patch.  Only change is that the new test goes
from FAIL to PASS.

If this patch is acceptable, please apply it.  (I don't have write access.)


chris
---
[gdb/ChangeLog]
2008-03-15  Chris Demetriou  <cgd@google.com>

        * symtab.c (rbreak_command): Quote symbol name before passing
        it to break_command.

[gdb/testsuite/ChangeLog]
2008-03-15  Chris Demetriou  <cgd@google.com>

        * gdb.base/break.exp (rbreak junk): New test for rbreak
        "Junk at end of arguments" issue.
[gdb/ChangeLog]
2008-03-15  Chris Demetriou  <cgd@google.com>

        * symtab.c (rbreak_command): Quote symbol name before passing
	it to break_command.

[gdb/testsuite/ChangeLog]
2008-03-15  Chris Demetriou  <cgd@google.com>

        * gdb.base/break.exp (rbreak junk): New test for rbreak
	"Junk at end of arguments" issue.


--- gdb/symtab.c	2008-03-15 00:12:38.000000000 -0700
+++ gdb/symtab.c	2008-03-15 00:30:07.545943000 -0700
@@ -3345,7 +3345,12 @@ rbreak_command (char *regexp, int from_t
 	}
       else
 	{
-	  break_command (SYMBOL_LINKAGE_NAME (p->msymbol), from_tty);
+	  char *string = alloca (strlen (SYMBOL_LINKAGE_NAME(p->msymbol)) + 3);
+	  strcpy (string, "'");
+	  strcat (string, SYMBOL_LINKAGE_NAME(p->msymbol));
+	  strcat (string, "'");
+
+	  break_command (string, from_tty);
 	  printf_filtered ("<function, no debug info> %s;\n",
 			   SYMBOL_PRINT_NAME (p->msymbol));
 	}
--- gdb/testsuite/gdb.base/break.exp	2008-03-15 00:12:38.000000000 -0700
+++ gdb/testsuite/gdb.base/break.exp	2008-03-15 00:29:15.680217000 -0700
@@ -944,6 +944,48 @@ gdb_expect {
 }
 
 
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+if [target_info exists gdb_stub] {
+    gdb_step_for_stub;
+}
+
+#
+# test that 'rbreak' on a symbol that may be from a shared library doesn't
+# cause a "Junk at end of arguments." error.
+#
+# On x86 GNU/Linux, this test will choke on e.g. __libc_start_main@plt.
+#
+# Note that this test won't necessarily choke on all targets even if
+# all the rbreak issue is present.  rbreak needs to match and set a
+# breakpoint on a symbol causes 'break' to choke.
+#
+
+gdb_test "set breakpoint pending on" "" "rbreak junk pending setup"
+
+# We expect at least one breakpoint to be set when we "rbreak main".
+gdb_test "rbreak main" \
+    ".*Breakpoint.*at.* file .*$srcfile, line.*" \
+    "rbreak junk set breakpoint"
+
+# Run to a breakpoint.  Fail if we see "Junk at end of arguments".
+gdb_run_cmd
+gdb_expect {
+    -re "Junk at end of arguments" {
+	fail "rbreak junk"
+    }
+    -re ".*Breakpoint \[0-9\]+,.*$gdb_prompt $" {
+	pass "rbreak junk"
+    }
+    timeout {
+	fail "rbreak junk (timeout)"
+    }
+}
+
+
 # Reset the default arguments for VxWorks
 if [istarget "*-*-vxworks*"] {
     set timeout 10

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]