Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb@sourceware.org
Cc: Peter Toft <pto@linuxbog.dk>
Subject: Re: Single stepping a simple C-program, but...
Date: Mon, 19 May 2008 20:48:00 -0000	[thread overview]
Message-ID: <200805192148.18788.pedro@codesourcery.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0805192201460.20752@petertoft.dk>

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 <stdio.h>       
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


  parent reply	other threads:[~2008-05-19 20:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-19 20:19 Peter Toft
2008-05-19 20:39 ` Daniel Jacobowitz
2008-05-20  7:19   ` Peter Toft
2008-05-19 20:48 ` Pedro Alves [this message]
2008-05-19 22:39   ` Pedro Alves
2008-05-20  7:11     ` Peter Toft
2008-05-20 11:05       ` Pedro Alves
2008-05-20 18:33     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200805192148.18788.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=gdb@sourceware.org \
    --cc=pto@linuxbog.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox