From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10418 invoked by alias); 29 Jul 2004 16:29:46 -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 10409 invoked from network); 29 Jul 2004 16:29:44 -0000 Received: from unknown (HELO mail2.nexpoint.net) (128.121.4.6) by sourceware.org with SMTP; 29 Jul 2004 16:29:44 -0000 Received: (qmail 31571 invoked from network); 29 Jul 2004 16:20:06 -0000 Received: from unknown (HELO laptop) (66.255.5.210) by mail2.nexpoint.net with SMTP; 29 Jul 2004 16:20:06 -0000 Content-Type: text/plain; charset="iso-8859-1" From: Andre Ancelin Organization: Adtec Digital, Inc. To: Daniel Jacobowitz , Allen Hopkins Subject: Re: breaking at for-loop test line Date: Thu, 29 Jul 2004 18:58:00 -0000 Cc: gdb@sources.redhat.com References: <4108321A.6070306@eecs.berkeley.edu> <20040729152940.GA7326@nevyn.them.org> In-Reply-To: <20040729152940.GA7326@nevyn.them.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200407291227.09937.andrea@adtecinc.com> X-SW-Source: 2004-07/txt/msg00361.txt.bz2 On Thursday 29 July 2004 11:29, Daniel Jacobowitz wrote: This works. 7 for (i =3D 0; i < 3;=20 8 i++) { 9 cout << i << endl; 10 } with a breakpoint at 8. It will stop for each pass. If you try 7 for (i =3D 0; 8 i < 3;=20 9 i++) { 10 cout << i << endl; 11 } with breakpoints at 7, 8, & 9, you stop at each line once, then at line 9 t= wo=20 more times, then out. It does not, however, stop again at line 8 for each=20 pass or at terminus (?). You can, however, add a breakpoint on line 11 and= =20 you will break at the next statement after line 11 upon terminus. Some might call this style ugly or wasteful, but I have found it much more= =20 debug friendly to leave all conditional tests on lines by themselves. Anoth= er=20 simple example: if (i < 6 || i > 9) { } > 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 =3D 0; > > 6 > > 7 for (i =3D 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... --=20 Andre Ancelin VP/CTO Adtec Digital, Inc andrea@adtecinc.com www.adtecinc.com