From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2567 invoked by alias); 29 Jul 2004 15:30:59 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 2555 invoked from network); 29 Jul 2004 15:30:57 -0000 Received: from unknown (HELO nevyn.them.org) (66.93.172.17) by sourceware.org with SMTP; 29 Jul 2004 15:30:57 -0000 Received: from drow by nevyn.them.org with local (Exim 4.34 #1 (Debian)) id 1BqCqi-0001vu-S1; Thu, 29 Jul 2004 11:29:41 -0400 Date: Thu, 29 Jul 2004 16:29:00 -0000 From: Daniel Jacobowitz To: Allen Hopkins Cc: gdb@sources.redhat.com Subject: Re: breaking at for-loop test line Message-ID: <20040729152940.GA7326@nevyn.them.org> Mail-Followup-To: Allen Hopkins , gdb@sources.redhat.com References: <4108321A.6070306@eecs.berkeley.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4108321A.6070306@eecs.berkeley.edu> User-Agent: Mutt/1.5.5.1+cvs20040105i X-SW-Source: 2004-07/txt/msg00360.txt.bz2 On Wed, Jul 28, 2004 at 04:09:14PM -0700, Allen Hopkins wrote: > Is there a way to break at the test statement of a for-loop > on every iteration, the same way a while-loop works? Here's > what I mean: > > 1 #include > 2 > 3 int main(int argc, char* argv[]) > 4 { > 5 int i = 0; > 6 > 7 for (i = 0; i < 3; i++) { > 8 cout << i << endl; > 9 } > 10 > 11 while (i < 6) { > 12 cout << i++ << endl; > 13 } > 14 > 15 exit(0); > 16 } > > If I set a breakpoint at line 7, and another at line 11, > and "run" and "continue" until exit, it will only break once > on the for-loop, but it will break on each iteration of the > while-loop. How does this make sense? Is there any way to > get a breakpoint at the top of the for-loop to act like the > while-loop? What Atul wrote is basically correct; GDB can only pick one breakpoint location for a particular line number, and it picks the beginning of the line. It would be nice if there were a way to set a breakpoint at the condition, but we don't have enough information to know for sure where the "condition" part is; and we don't want to always set breakpoints at every part of a line, because it makes breakpoints on simple statements that get broken up by ptimization very awkward to work with. I've been thinking for a while about a better interface for this, but I haven't come up with one yet. In the mean time, you can take a look at the disassembly, figure out where the condition is, and set a breakpoint there using break *. GDB could also make it much easier to figure out where the condition is than it does now... -- Daniel Jacobowitz