[hellogcc] Re: Fwd: Why running the next command will jump back to the previous line position

  • From: xunxun <xunxun1982@xxxxxxxxx>
  • To: hellogcc@xxxxxxxxxxxxx
  • Date: Sat, 29 Oct 2011 15:38:01 +0800

于 2011/10/29 15:17, asmwarrior 写道:
这个问题困扰我很久了,就是调试的时候,gdb的运行行,为什么会回跳到前面 定义变量的地方??
我已经发到gdb邮件列表了,希望这里也有人能帮忙看看,谢谢。

Hi, I'm using MinGW 4.6.2 and GDB cvs head under Windows XP.

When debugging a sample program: (I build it with -g, and no optimization 
option is used)

#include<string>
#include<map>

int main()
{
     std::map<int, std::string>  m;
     m[0] = "000";
     m[1] = "111";
     for( int i = 0; i<  3; i++)
     {
         m[i] = "ssss";
     }
     return 0;
}


If I continuously run the command "next" under gdb, I found that when I hit the statement "return 0", if I run 
"next" again, It will take me backward to the line "std::map<int, std::string>  m;". If I run the 
"next" again, the instruction will go forward the closing bracket of the main function body.

This was quite strange, it looks like the instruction will return to some previous 
position. (I guess that the destructor of the "std::map" was called.

My question is: This behavior is quite anti-friendly, because if I'm debugging 
a large function, I always get the instruction line back to where some local 
variable (automatic variable) was defined.

Is it possible to solve it. I don't want the instruction line go backward when 
I leave some scope.

Thanks.

asmwarrior
ollydbg from codeblocks' forum

不清楚,应该是gcc的原因,最后插入了一些代码
我使用objdump -S看了下,最后确实call了前面的代码
不知道这样的用意是啥

--
Best Regards,
xunxun

Other related posts: