* [RFA] fix for rbreak issue w/ "Junk at end of arguments"
@ 2008-03-15 8:18 Chris Demetriou
2008-03-21 15:32 ` Daniel Jacobowitz
0 siblings, 1 reply; 3+ messages in thread
From: Chris Demetriou @ 2008-03-15 8:18 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 3414 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gdb-rbreak.patch --]
[-- Type: text/x-patch; name=gdb-rbreak.patch, Size: 2287 bytes --]
[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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] fix for rbreak issue w/ "Junk at end of arguments"
2008-03-15 8:18 [RFA] fix for rbreak issue w/ "Junk at end of arguments" Chris Demetriou
@ 2008-03-21 15:32 ` Daniel Jacobowitz
[not found] ` <2e7be40c0803220015h500b84fft723d595bfeb9888d@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2008-03-21 15:32 UTC (permalink / raw)
To: Chris Demetriou; +Cc: gdb-patches
On Sat, Mar 15, 2008 at 01:18:09AM -0700, Chris Demetriou wrote:
> If this patch is acceptable, please apply it. (I don't have write access.)
Thanks for fixing this. It's OK, modulo our whitespace conventions
(space before paren); I fixed that and checked it in. Want write access?
If so, fill out the sourceware.org form; it's on the front page of the
web site.
Oddly the test doesn't fail for me even though I've got an
__libc_start_main@plt. It's not setting a breakpoint at the
PLT entry... boo, it thinks that comes from a startfile. Another day.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] fix for rbreak issue w/ "Junk at end of arguments"
[not found] ` <2e7be40c0803220015h500b84fft723d595bfeb9888d@mail.gmail.com>
@ 2008-03-22 7:20 ` Chris Demetriou
0 siblings, 0 replies; 3+ messages in thread
From: Chris Demetriou @ 2008-03-22 7:20 UTC (permalink / raw)
To: Chris Demetriou, gdb-patches
On Fri, Mar 21, 2008 at 8:32 AM, Daniel Jacobowitz <drow@false.org> wrote:
> Thanks for fixing this. It's OK, modulo our whitespace conventions
> (space before paren); I fixed that and checked it in.
Ahh, how I've missed the GNU coding conventions. 8-) Thanks.
> Want write access?
> If so, fill out the sourceware.org form; it's on the front page of the
> web site.
Sure, why not. It's easier (for you all 8-) than having you apply
patches for me.
> Oddly the test doesn't fail for me even though I've got an
> __libc_start_main@plt. It's not setting a breakpoint at the
> PLT entry... boo, it thinks that comes from a startfile. Another day.
Yeah. It seemed likely that this didn't fail in the same way for
everybody -- otherwise I think a lot of people would have screamed by
now, and it would have been fixed sooner.
That's why I coded the test so that it didn't even *attempt* to verify
a breakpoint on the @plt symbol on linux, and that's also why i
verified that the issue existed on two different distro's.
I don't have a system on which it did not fail previously, otherwise i
probably would have investigated a bit further before submitting the
patch. (Now that you have confirmed that the patch is reasonable, I
don't really want to spend time investigating, of course. 8-)
thanks,
chris
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-22 7:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-15 8:18 [RFA] fix for rbreak issue w/ "Junk at end of arguments" Chris Demetriou
2008-03-21 15:32 ` Daniel Jacobowitz
[not found] ` <2e7be40c0803220015h500b84fft723d595bfeb9888d@mail.gmail.com>
2008-03-22 7:20 ` Chris Demetriou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox