From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12336 invoked by alias); 19 May 2008 20:48:45 -0000 Received: (qmail 12303 invoked by uid 22791); 19 May 2008 20:48:44 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 19 May 2008 20:48:20 +0000 Received: (qmail 26707 invoked from network); 19 May 2008 20:48:18 -0000 Received: from unknown (HELO orlando.local) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 19 May 2008 20:48:18 -0000 From: Pedro Alves To: gdb@sourceware.org Subject: Re: Single stepping a simple C-program, but... Date: Mon, 19 May 2008 20:48:00 -0000 User-Agent: KMail/1.9.9 Cc: Peter Toft References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200805192148.18788.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2008-05/txt/msg00143.txt.bz2 A Monday 19 May 2008 21:18:36, Peter Toft wrote: > Hi guys > > I was a bit surprised today with GDB, and I hope one of you can explain it > to me. Take a look at http://pastebin.org/37117 01. #include 02. 03. int main(void) 04. { 05. int ii=4; 06. 07. if ((ii>3) || (ii<1)) 08. printf("hej A\n"); 09. else 10. printf("hej B\n"); 11. 12. return 0; 13. } > Press download and save as my_program.c > $ gcc -g my_program.c > $ gdb ./a.out > (gdb) br 7 > Breakpoint 1 at 0x804838c: file my_program.c, line 7. > (gdb) r > Starting program: /home/pto/c/a.out > > Breakpoint 1, main () at my_program.c:7 > 7 if ((ii>3) || (ii<1)) > (gdb) s > 8 printf("hej A\n"); > (gdb) s > hej A > 7 if ((ii>3) || (ii<1)) <----------- WHY!!!!?? > (gdb) s > 12 return 0; > > ------- > > Why does the second "step" i.e. "s" take me BACK to line 7 after I > have been in line 8???? > Presumably, because there's a branch instruction after the printf call to skip the else clause, GDB hits it (step-resume breakpoint), and the debug info gcc is producing is marking that address as belonging to line 7? -- Pedro Alves