rivers horse | 11 Aug 2012 05:14
Picon

execution does not run in the source line's order

hi,
     I  debug gdb using itself,  i find  a strange  issue  :
              the programme  being  debugged  execute  not in line
order,for example,  it goes into  line 20,then it goes  into line 18 ,
    which are simply assignment operations,

    what is the reasin for this?

thanks!

Jan Kratochvil | 11 Aug 2012 08:24
Picon
Favicon

Re: execution does not run in the source line's order

On Sat, 11 Aug 2012 05:14:41 +0200, rivers horse wrote:
>      I  debug gdb using itself,  i find  a strange  issue  :
>               the programme  being  debugged  execute  not in line
> order,for example,  it goes into  line 20,then it goes  into line 18 ,
>     which are simply assignment operations,
> 
>     what is the reasin for this?

You have probably compiled the file with -O2, use/force -O0 (gcc options).

Regards,
Jan

Eli Zaretskii | 11 Aug 2012 08:30
Picon

Re: execution does not run in the source line's order

> Date: Sat, 11 Aug 2012 11:14:41 +0800
> From: rivers horse <horserivers <at> gmail.com>
> 
>      I  debug gdb using itself,  i find  a strange  issue  :
>               the programme  being  debugged  execute  not in line
> order,for example,  it goes into  line 20,then it goes  into line 18 ,
>     which are simply assignment operations,
> 
>     what is the reasin for this?

Compiler optimizations are known to reorder code, if doing so cannot
affect the result.  If your GDB is compiled with optimizations, that's
the reason.


Gmane