From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31621 invoked by alias); 23 Nov 2009 21:27:44 -0000 Received: (qmail 31613 invoked by uid 22791); 23 Nov 2009 21:27:43 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Nov 2009 21:27:39 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 4F16D10DAA; Mon, 23 Nov 2009 21:27:38 +0000 (GMT) Received: from caradoc.them.org (209.195.188.212.nauticom.net [209.195.188.212]) by nan.false.org (Postfix) with ESMTP id 266DD10D9E; Mon, 23 Nov 2009 21:27:38 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.69) (envelope-from ) id 1NCgRc-000219-Dc; Mon, 23 Nov 2009 16:27:36 -0500 Date: Mon, 23 Nov 2009 21:27:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Cc: "Maciej W. Rozycki" , Andrew Stubbs , Vladimir Prus , Eli Zaretskii Subject: RFC: Fix "break *EXP thread NUM" Message-ID: <20091123212736.GA3828@caradoc.them.org> Mail-Followup-To: gdb-patches@sourceware.org, "Maciej W. Rozycki" , Andrew Stubbs , Vladimir Prus , Eli Zaretskii MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-11/txt/msg00512.txt.bz2 This issue has come up several times over the years. I've CC'd a couple of folks from the last discussions I found in the list archives. Here's an example: (gdb) # OK (gdb) break main thread 999 Unknown thread 999. (gdb) # NG (gdb) break *main thread 999 A syntax error in expression, near `thread 999'. References: http://sourceware.org/ml/gdb-patches/2005-04/msg00092.html http://sourceware.org/ml/gdb-patches/2005-04/msg00116.html http://sourceware.org/ml/gdb-patches/2006-07/msg00412.html The problem is with the expression parser, which has no way to detect the "end" of an expression (a poorly defined concept). Since "if" can not be a valid C identifier, and we do not parse C statements (just expressions), we have a special technique in the lexer to detect that token and stop. So both of these work: (gdb) break main if 999 Breakpoint 1 at 0x44cce0 (gdb) break *main if 999 Note: breakpoint 1 also set at pc 0x44cce0. Breakpoint 2 at 0x44cce0 In this patch, I have taken advantage of the fact that even if you have a local variable named "thread", there is no valid C expression which has a variable name, whitespace, and an integer or floating point constant. So "thread [0-9]" can also safely be treated as an expression terminator. Does anyone see a problem with this approach? I updated the manual, and don't think a NEWS entry is required. Tested on x86_64-linux, with no regressions. -- Daniel Jacobowitz CodeSourcery 2009-11-23 Daniel Jacobowitz * c-exp.y (yylex): Stop before "thread N". * gdb.texinfo (Thread-Specific Breakpoints): Thread specifiers are allowed after the breakpoint condition. * gdb.base/condbreak.exp: Test combinations of "break *EXP", "if", and "thread". Correct matching in the previous test. Index: c-exp.y =================================================================== RCS file: /cvs/src/src/gdb/c-exp.y,v retrieving revision 1.65 diff -u -p -r1.65 c-exp.y --- c-exp.y 11 Nov 2009 16:45:46 -0000 1.65 +++ c-exp.y 23 Nov 2009 21:26:06 -0000 @@ -2250,6 +2250,22 @@ yylex (void) return 0; } + /* For the same reason (breakpoint conditions), "thread N" + terminates the expression. "thread" could be an identifier, but + an identifier is never followed by a number without intervening + punctuation. */ + if (namelen == 6 + && strncmp (tokstart, "thread", 6) == 0 + && (tokstart[6] == ' ' || tokstart[6] == '\t') + && ! scanning_macro_expansion ()) + { + char *p = tokstart + 7; + while (*p == ' ' || *p == '\t') + p++; + if (*p >= '0' && *p <= '9') + return 0; + } + lexptr += namelen; tryname: Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.642 diff -u -p -r1.642 gdb.texinfo --- doc/gdb.texinfo 23 Nov 2009 18:44:10 -0000 1.642 +++ doc/gdb.texinfo 23 Nov 2009 21:26:13 -0000 @@ -5214,8 +5214,8 @@ breakpoint, the breakpoint applies to @e program. You can use the @code{thread} qualifier on conditional breakpoints as -well; in this case, place @samp{thread @var{threadno}} before the -breakpoint condition, like this: +well; in this case, place @samp{thread @var{threadno}} before or +after the breakpoint condition, like this: @smallexample (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim Index: testsuite/gdb.base/condbreak.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/condbreak.exp,v retrieving revision 1.13 diff -u -p -r1.13 condbreak.exp --- testsuite/gdb.base/condbreak.exp 3 Jan 2009 05:58:03 -0000 1.13 +++ testsuite/gdb.base/condbreak.exp 23 Nov 2009 21:26:13 -0000 @@ -207,10 +207,10 @@ gdb_expect { setup_xfail hppa2.0w-*-* 11512CLLbs send_gdb "continue\n" gdb_expect { - -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*" { + -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*$gdb_prompt $" { pass "run until breakpoint at marker2" } - -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*" { + -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*$gdb_prompt $" { xfail "run until breakpoint at marker2" } -re "$gdb_prompt $" { @@ -220,3 +220,16 @@ gdb_expect { fail "(timeout) run until breakpoint at marker2" } } + +# Test combinations of conditional and thread-specific breakpoints. +gdb_test "break main if (1==1) thread 999" \ + "Unknown thread 999\\." +gdb_test "break main thread 999 if (1==1)" \ + "Unknown thread 999\\." + +# Verify that both if and thread can be distinguished from a breakpoint +# address expression. +gdb_test "break *main if (1==1) thread 999" \ + "Unknown thread 999\\." +gdb_test "break *main thread 999 if (1==1)" \ + "Unknown thread 999\\."