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

  • From: asmwarrior <asmwarrior@xxxxxxxxx>
  • To: hellogcc@xxxxxxxxxxxxx
  • Date: Sat, 29 Oct 2011 21:46:25 +0800

On 2011-10-29 21:35, Yao Qi wrote:
这样的问题就是gcc在产生 debug info 不是很准确造成的。我没有办法在我的
gcc 4.4 上重现这个问题,但是我相信这个问题是存在的。

在dwarf里边,.debug_line这个段是用来记录把地址映射回到源代码
行号的。你可以用 readelf -wl 1.exe 看看,就能看明白。这样的问题一般
都是gcc 产生的debug info不对,虽然在也是gcc的bug,但是这样的bug优先级
比较低,所以,可能没有人修吧。
谢谢。我对dwarf是不太懂,今天去gcc help上面发了个贴,似乎没有人回答。
gdb的邮件列表里面有人回复了我,我用

objdump -dSC a.exe
这个命令输出了结果看了一下,我不太看得懂内容,但是从里面有一段话的情况来看,似乎同一个行号,对应了很多指令地址:

00401660<main>:

#include<string>
#include<map>

int main()
{
  401660:       55                      push   %ebp
  401661:       89 e5                   mov    %esp,%ebp
  401663:       53                      push   %ebx
  401664:       83 e4 f0                and    $0xfffffff0,%esp
  401667:       83 ec 40                sub    $0x40,%esp
  40166a:       e8 c1 ca 00 00          call   40e130<__main>
    std::map<int, std::string>  m;
  40166f:       8d 44 24 20             lea    0x20(%esp),%eax
  401673:       89 04 24                mov    %eax,(%esp)
  401676:       e8 3d aa 01 00          call   41c0b8<std::map<int, std::string, std::less<int>, 
std::allocator<std::pair<int const, std::string>  >  >::map()>
    m[0] = "000";
  40167b:       c7 44 24 38 00 00 00    movl   $0x0,0x38(%esp)
  401682:       00
  401683:       8d 44 24 38             lea    0x38(%esp),%eax
  401687:       89 44 24 04             mov    %eax,0x4(%esp)
  40168b:       8d 44 24 20             lea    0x20(%esp),%eax
  40168f:       89 04 24                mov    %eax,(%esp)
  401692:       e8 49 aa 01 00          call   41c0e0<std::map<int, std::string, std::less<int>, 
std::allocator<std::pair<int const, std::string>  >  >::operator[](int&&)>
  401697:       c7 44 24 04 86 f0 41    movl   $0x41f086,0x4(%esp)
  40169e:       00
  40169f:       89 04 24                mov    %eax,(%esp)
  4016a2:       e8 a9 a6 01 00          call   41bd50<std::string::operator=(char 
const*)>
    m[1] = "111";
  4016a7:       c7 44 24 3c 01 00 00    movl   $0x1,0x3c(%esp)
  4016ae:       00
  4016af:       8d 44 24 3c             lea    0x3c(%esp),%eax
  4016b3:       89 44 24 04             mov    %eax,0x4(%esp)
  4016b7:       8d 44 24 20             lea    0x20(%esp),%eax
  4016bb:       89 04 24                mov    %eax,(%esp)
  4016be:       e8 1d aa 01 00          call   41c0e0<std::map<int, std::string, std::less<int>, 
std::allocator<std::pair<int const, std::string>  >  >::operator[](int&&)>
  4016c3:       c7 44 24 04 8a f0 41    movl   $0x41f08a,0x4(%esp)
  4016ca:       00
  4016cb:       89 04 24                mov    %eax,(%esp)
  4016ce:       e8 7d a6 01 00          call   41bd50<std::string::operator=(char 
const*)>
    for( int i = 0; i<  3; i++)
  4016d3:       c7 44 24 1c 00 00 00    movl   $0x0,0x1c(%esp)
  4016da:       00
  4016db:       eb 2f                   jmp    40170c<main+0xac>
    {
        m[i] = "ssss";
  4016dd:       8d 44 24 1c             lea    0x1c(%esp),%eax
  4016e1:       89 44 24 04             mov    %eax,0x4(%esp)
  4016e5:       8d 44 24 20             lea    0x20(%esp),%eax
  4016e9:       89 04 24                mov    %eax,(%esp)
  4016ec:       e8 1f ab 01 00          call   41c210<std::map<int, std::string, std::less<int>, 
std::allocator<std::pair<int const, std::string>  >  >::operator[](int const&)>
  4016f1:       c7 44 24 04 8e f0 41    movl   $0x41f08e,0x4(%esp)
  4016f8:       00
  4016f9:       89 04 24                mov    %eax,(%esp)
  4016fc:       e8 4f a6 01 00          call   41bd50<std::string::operator=(char 
const*)>
int main()
{
    std::map<int, std::string>  m;
    m[0] = "000";
    m[1] = "111";
    for( int i = 0; i<  3; i++)
  401701:       8b 44 24 1c             mov    0x1c(%esp),%eax
  401705:       83 c0 01                add    $0x1,%eax
  401708:       89 44 24 1c             mov    %eax,0x1c(%esp)
  40170c:       8b 44 24 1c             mov    0x1c(%esp),%eax
  401710:       83 f8 02                cmp    $0x2,%eax
  401713:       0f 9e c0                setle  %al
  401716:       84 c0                   test   %al,%al
  401718:       75 c3                   jne    4016dd<main+0x7d>
    {
        m[i] = "ssss";
    }
    return 0;
  40171a:       bb 00 00 00 00          mov    $0x0,%ebx
#include<string>
#include<map>

int main()
{
    std::map<int, std::string>  m;
  40171f:       8d 44 24 20             lea    0x20(%esp),%eax
  401723:       89 04 24                mov    %eax,(%esp)
  401726:       e8 a1 a9 01 00          call   41c0cc<std::map<int, std::string, std::less<int>, 
std::allocator<std::pair<int const, std::string>  >  >::~map()>
  40172b:       89 d8                   mov    %ebx,%eax
    for( int i = 0; i<  3; i++)
    {
        m[i] = "ssss";
    }
    return 0;
}
  40172d:       8b 5d fc                mov    -0x4(%ebp),%ebx
  401730:       c9                      leave
  401731:       c3                      ret
  401732:       89 c3                   mov    %eax,%ebx
#include<string>
#include<map>

int main()
{
    std::map<int, std::string>  m;
  401734:       8d 44 24 20             lea    0x20(%esp),%eax
  401738:       89 04 24                mov    %eax,(%esp)
  40173b:       e8 8c a9 01 00          call   41c0cc<std::map<int, std::string, std::less<int>, 
std::allocator<std::pair<int const, std::string>  >  >::~map()>
  401740:       89 d8                   mov    %ebx,%eax
  401742:       89 04 24                mov    %eax,(%esp)
  401745:       e8 26 f4 00 00          call   410b70<_Unwind_Resume>
  40174a:       90                      nop
  40174b:       90                      nop
  40174c:       00 00                   add    %al,(%eax)
        ...


上面这段话的意思,是不是说:当return语句之后,接下来的语句,又跳回到main的开头行号了?




Other related posts: