From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12516 invoked by alias); 28 Jul 2004 23:09:20 -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 12496 invoked from network); 28 Jul 2004 23:09:19 -0000 Received: from unknown (HELO relay0.EECS.Berkeley.EDU) (169.229.60.163) by sourceware.org with SMTP; 28 Jul 2004 23:09:19 -0000 Received: from gateway.EECS.Berkeley.EDU (nsmail@gateway.EECS.Berkeley.EDU [169.229.60.73]) by relay0.EECS.Berkeley.EDU (8.13.0/8.12.10) with ESMTP id i6SN9I2i020210 for ; Wed, 28 Jul 2004 16:09:18 -0700 (PDT) Received: from eecs.berkeley.edu (markov.EECS.Berkeley.EDU [128.32.33.224]) by gateway.EECS.Berkeley.EDU (Netscape Messaging Server 4.15) with ESMTP id I1L4BE00.GPF; Wed, 28 Jul 2004 16:09:14 -0700 Message-ID: <4108321A.6070306@eecs.berkeley.edu> Date: Thu, 29 Jul 2004 05:10:00 -0000 From: "Allen Hopkins" User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.0.1) Gecko/20020920 Netscape/7.0 MIME-Version: 1.0 To: gdb@sources.redhat.com Subject: breaking at for-loop test line Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-07/txt/msg00357.txt.bz2 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? Here's the compile command: > g++ -ggdb -Wno-deprecated -o s s.cpp There's no optimization going on that I'm not aware of, is there? Here's sample gdb output: (gdb) break 7 Breakpoint 1 at 0x10b04: file s.cpp, line 7. (gdb) break 11 Breakpoint 2 at 0x10b5c: file s.cpp, line 11. (gdb) run Starting program: /export/home/allenh/projects/metropolis/testing/foodir/s Breakpoint 1, main (argc=1, argv=0xffbeecac) at s.cpp:7 7 for (i = 0; i < 3; i++) { (gdb) c Continuing. 0 1 2 Breakpoint 2, main (argc=1, argv=0xffbeecac) at s.cpp:11 11 while (i < 6) { (gdb) c Continuing. 3 Breakpoint 2, main (argc=1, argv=0xffbeecac) at s.cpp:11 11 while (i < 6) { (gdb) c Continuing. 4 Breakpoint 2, main (argc=1, argv=0xffbeecac) at s.cpp:11 11 while (i < 6) { (gdb) c Continuing. 5 Breakpoint 2, main (argc=1, argv=0xffbeecac) at s.cpp:11 11 while (i < 6) { (gdb) c Continuing. Program exited normally. (gdb) Any advice appreciated. Oh, yeah... Sun Solaris 2.8 gcc 3.2.2 gdb 6.0 Thanks. -Allen Hopkins UC Berkeley