From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22742 invoked by alias); 13 Mar 2009 16:47:57 -0000 Received: (qmail 22728 invoked by uid 22791); 13 Mar 2009 16:47:55 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,HK_OBFDOM,J_CHICKENPOX_31,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Mar 2009 16:47:49 +0000 Received: from spaceape14.eur.corp.google.com (spaceape14.eur.corp.google.com [172.28.16.148]) by smtp-out.google.com with ESMTP id n2DGljci010426 for ; Fri, 13 Mar 2009 16:47:45 GMT Received: from rv-out-0506.google.com (rvbl9.prod.google.com [10.140.88.9]) by spaceape14.eur.corp.google.com with ESMTP id n2DGlh4m025611 for ; Fri, 13 Mar 2009 09:47:44 -0700 Received: by rv-out-0506.google.com with SMTP id l9so1696974rvb.49 for ; Fri, 13 Mar 2009 09:47:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.141.48.6 with SMTP id a6mr663988rvk.36.1236962862797; Fri, 13 Mar 2009 09:47:42 -0700 (PDT) In-Reply-To: <20090302065301.356261C7A1E@localhost> References: <20090302065301.356261C7A1E@localhost> Date: Fri, 13 Mar 2009 17:04:00 -0000 Message-ID: Subject: Re: [RFA]: Handle multi-line versions of multi-breakpoints From: Doug Evans To: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-System-Of-Record: true 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-03/txt/msg00210.txt.bz2 Ping. On Sun, Mar 1, 2009 at 11:53 PM, Doug Evans wrote: > Hi. > > "multi-breakpoints" (multiple breakpoints for the same source line) > don't work for constructors and inline functions where the source expression > spans several lines (at least for the new testcases included in this patch). > > This patch fixes it by, if there's no exact match, > rescanning the symtabs for all matches of the best match. > Included are updated testcases to exercise the bug. > The bug isn't exposed by templates, but I updated mb-templates.{cc,exp} > anyway (if only to confirm things work there too). > > Ok to check in? > > 2009-03-01 Doug Evans > > * symtab.c (expand_line_sal): If we don't find an exact match, > rescan all symtabs again to find all copies of the best match. > > * gdb.cp/mb-ctor.exp: Add multi-line source statement test. > * gdb.cp/mb-ctor.cc: Ditto. > * gdb.cp/mb-inline.exp: Add multi-line source statement test. > * gdb.cp/mb-inline.h (multi_line_foo): New function. > * gdb.cp/mb-inline1.cc: Call it. > * gdb.cp/mb-inline2.cc: Ditto. > * gdb.cp/mb-templates.exp: Add multi-line source statement test. > * gdb.cp/mb-templates.cc (multi_line_foo): New template. > > Index: symtab.c > =================================================================== > RCS file: /cvs/src/src/gdb/symtab.c,v > retrieving revision 1.204 > diff -u -p -r1.204 symtab.c > --- symtab.c 2 Mar 2009 06:33:24 -0000 1.204 > +++ symtab.c 2 Mar 2009 06:39:17 -0000 > @@ -4481,7 +4481,6 @@ expand_line_sal (struct symtab_and_line > else > { > struct linetable_entry *best_item = 0; > - struct symtab *best_symtab = 0; > int exact = 0; > > lineno = sal.line; > @@ -4533,13 +4532,41 @@ expand_line_sal (struct symtab_and_line > && (best_item == NULL || item->line < best_item->line)) > { > best_item = item; > - best_symtab = symtab; > } > } > } > } > + > if (!exact && best_item) > - append_expanded_sal (&ret, best_symtab, lineno, best_item->pc); > + { > + /* We found a "good enough" match. > + Rescan to find all such matches. > + This is to handle constructors, templates, inline-functions > + that have multiple breakpoints for one line number. */ > + > + ALL_SYMTABS (objfile, symtab) > + { > + if (strcmp (sal.symtab->filename, > + symtab->filename) == 0) > + { > + struct linetable *l; > + int len; > + l = LINETABLE (symtab); > + if (!l) > + continue; > + len = l->nitems; > + > + for (j = 0; j < len; j++) > + { > + struct linetable_entry *item = &(l->item[j]); > + > + if (item->line == best_item->line) > + append_expanded_sal (&ret, symtab, item->line, > + item->pc); > + } > + } > + } > + } > } > > /* For optimized code, compiler can scatter one source line accross > Index: testsuite/gdb.cp/mb-ctor.cc > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/mb-ctor.cc,v > retrieving revision 1.1 > diff -u -p -r1.1 mb-ctor.cc > --- testsuite/gdb.cp/mb-ctor.cc 24 Sep 2007 07:40:32 -0000 1.1 > +++ testsuite/gdb.cp/mb-ctor.cc 2 Mar 2009 06:39:17 -0000 > @@ -28,11 +28,19 @@ public: > ~Derived(); > private: > int i; > + int i2; > }; > > Derived::Derived(int i) : Base(i) > { > this->i = i; > + /* The next statement is spread over two lines on purpose to exercise > + a bug where breakpoints set on all but the last line of a statement > + would not get multiple breakpoints. > + The second line's text for gdb_get_line_number is a subset of the > + first line so that we don't care which line gdb prints when it stops. */ > + this->i2 = // set breakpoint here > + i; // breakpoint here > } > > Derived::~Derived() > Index: testsuite/gdb.cp/mb-ctor.exp > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/mb-ctor.exp,v > retrieving revision 1.5 > diff -u -p -r1.5 mb-ctor.exp > --- testsuite/gdb.cp/mb-ctor.exp 3 Jan 2009 05:58:04 -0000 1.5 > +++ testsuite/gdb.cp/mb-ctor.exp 2 Mar 2009 06:39:17 -0000 > @@ -43,6 +43,11 @@ gdb_start > gdb_reinitialize_dir $srcdir/$subdir > gdb_load ${binfile} > > +if ![runto_main] then { > + perror "couldn't run to breakpoint" > + continue > +} > + > # Set a breakpoint with multiple locations > # and a condition. > > @@ -50,34 +55,31 @@ gdb_test "break 'Derived::Derived(int)'" > "Breakpoint.*at.* file .*$srcfile, line.*\\(2 locations\\).*" \ > "set-breakpoint at ctor" > > +gdb_breakpoint [gdb_get_line_number "set breakpoint here"] > + > gdb_test "break 'Derived::~Derived()'" \ > "Breakpoint.*at.* file .*$srcfile, line.*\\(2 locations\\).*" \ > "set-breakpoint at dtor" > > -gdb_run_cmd > -gdb_expect { > - -re "Breakpoint \[0-9\]+,.*Derived.*i=7.*$gdb_prompt $" { > - pass "run to breakpoint" > - } > - -re "$gdb_prompt $" { > - fail "run to breakpoint" > - } > - timeout { > - fail "run to breakpoint (timeout)" > - } > -} > +gdb_test "continue" \ > + ".*Breakpoint.*Derived.*i=7.*" \ > + "run to breakpoint 1 v1" > + > +gdb_continue_to_breakpoint "set breakpoint here" ".* breakpoint here" > > gdb_test "continue" \ > ".*Breakpoint.*Derived.*i=15.*" \ > - "run to breakpoint 2" > + "run to breakpoint 1 v2" > + > +gdb_continue_to_breakpoint "set breakpoint here" ".* breakpoint here" > > gdb_test "continue" \ > ".*Breakpoint.*~Derived.*" \ > - "run to breakpoint 3" > + "run to breakpoint 3 v1" > > gdb_test "continue" \ > ".*Breakpoint.*~Derived.*" \ > - "run to breakpoint 4" > + "run to breakpoint 3 v2" > > gdb_test "continue" \ > ".*exited normally.*" \ > Index: testsuite/gdb.cp/mb-inline.exp > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/mb-inline.exp,v > retrieving revision 1.2 > diff -u -p -r1.2 mb-inline.exp > --- testsuite/gdb.cp/mb-inline.exp 3 Jan 2009 05:58:04 -0000 1.2 > +++ testsuite/gdb.cp/mb-inline.exp 2 Mar 2009 06:39:17 -0000 > @@ -106,3 +106,25 @@ gdb_expect { > gdb_test "continue" \ > ".*Program exited normally.*" \ > "continue with disabled breakpoint 1.2" > + > +# Make sure we can set a breakpoint on a source statement that spans > +# multiple lines. > + > +delete_breakpoints > + > +set bp_location [gdb_get_line_number "set multi-line breakpoint here" $hdrfile] > + > +if { ![runto_main] } { > + fail "Can't run to main for multi_line_foo tests." > + return 0 > +} > + > +gdb_test "break $hdrfile:$bp_location" \ > + "Breakpoint.*at.* file .*$hdrfile, line.*\\(2 locations\\).*" \ > + "set multi_line_foo breakpoint" > +gdb_test "continue" \ > + ".*Breakpoint.*multi_line_foo \\(i=0\\).*" \ > + "run to multi_line_foo breakpoint 4 afn" > +gdb_test "continue" \ > + ".*Breakpoint.*multi_line_foo \\(i=1\\).*" \ > + "run to multi_line_foo breakpoint 4 bfn" > Index: testsuite/gdb.cp/mb-inline.h > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/mb-inline.h,v > retrieving revision 1.2 > diff -u -p -r1.2 mb-inline.h > --- testsuite/gdb.cp/mb-inline.h 3 Jan 2009 05:58:04 -0000 1.2 > +++ testsuite/gdb.cp/mb-inline.h 2 Mar 2009 06:39:17 -0000 > @@ -26,5 +26,12 @@ foo (int i) > return i; // set breakpoint here > } > > +static int > +multi_line_foo (int i) > +{ > + return // set multi-line breakpoint here > + i; > +} > + > extern int afn (); > extern int bfn (); > Index: testsuite/gdb.cp/mb-inline1.cc > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/mb-inline1.cc,v > retrieving revision 1.2 > diff -u -p -r1.2 mb-inline1.cc > --- testsuite/gdb.cp/mb-inline1.cc 3 Jan 2009 05:58:04 -0000 1.2 > +++ testsuite/gdb.cp/mb-inline1.cc 2 Mar 2009 06:39:17 -0000 > @@ -23,7 +23,7 @@ > int > afn () > { > - return foo (0); > + return foo (0) + multi_line_foo (0); > } > > int > Index: testsuite/gdb.cp/mb-inline2.cc > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/mb-inline2.cc,v > retrieving revision 1.2 > diff -u -p -r1.2 mb-inline2.cc > --- testsuite/gdb.cp/mb-inline2.cc 3 Jan 2009 05:58:04 -0000 1.2 > +++ testsuite/gdb.cp/mb-inline2.cc 2 Mar 2009 06:39:17 -0000 > @@ -21,5 +21,5 @@ > int > bfn () > { > - return foo (1); > + return foo (1) + multi_line_foo (1); > } > Index: testsuite/gdb.cp/mb-templates.cc > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/mb-templates.cc,v > retrieving revision 1.1 > diff -u -p -r1.1 mb-templates.cc > --- testsuite/gdb.cp/mb-templates.cc 24 Sep 2007 07:40:32 -0000 1.1 > +++ testsuite/gdb.cp/mb-templates.cc 2 Mar 2009 06:39:17 -0000 > @@ -8,6 +8,13 @@ void foo(T i) > std::cout << "hi\n"; // set breakpoint here > } > > +template > +void multi_line_foo(T i) > +{ > + std::cout // set multi-line breakpoint here > + << "hi\n"; > +} > + > int main() > { > foo(0); > @@ -16,4 +23,9 @@ int main() > foo(1); > foo(2); > foo(2); > + > + multi_line_foo(0); > + multi_line_foo(0); > + > + return 0; > } > Index: testsuite/gdb.cp/mb-templates.exp > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/mb-templates.exp,v > retrieving revision 1.5 > diff -u -p -r1.5 mb-templates.exp > --- testsuite/gdb.cp/mb-templates.exp 3 Jan 2009 05:58:04 -0000 1.5 > +++ testsuite/gdb.cp/mb-templates.exp 2 Mar 2009 06:39:17 -0000 > @@ -165,3 +165,25 @@ gdb_test "continue" \ > ".*Breakpoint.*foo \\(i=1\\).*" \ > "instantiation: run to breakpoint 2" > > + > +# Make sure we can set a breakpoint on a source statement that spans > +# multiple lines. > + > +delete_breakpoints > + > +set bp_location [gdb_get_line_number "set multi-line breakpoint here"] > + > +if { ![runto_main] } { > + fail "Can't run to main for multi_line_foo tests." > + return 0 > +} > + > +gdb_test "break $srcfile:$bp_location" \ > + "Breakpoint.*at.* file .*$srcfile, line.*\\(2 locations\\).*" \ > + "set multi_line_foo breakpoint" > +gdb_test "continue" \ > + ".*Breakpoint.*multi_line_foo \\(i=0\\).*" \ > + "run to multi_line_foo breakpoint 2 " > +gdb_test "continue" \ > + ".*Breakpoint.*multi_line_foo \\(i=0\\).*" \ > + "run to multi_line_foo breakpoint 2 " >