【问题标题】:How to interpret GDB "info frame" output?如何解释 GDB“信息框”输出?
【发布时间】:2011-07-05 21:48:36
【问题描述】:

请帮助我理解这一点:-

(gdb) info frame
Stack level 0, frame at 0xb75f7390:
 eip = 0x804877f in base::func() (testing.cpp:16); saved eip 0x804869a
 called by frame at 0xb75f73b0
 source language c++.
 Arglist at 0xb75f7388, args: this=0x0
 Locals at 0xb75f7388, Previous frame's sp is 0xb75f7390
 Saved registers:
  ebp at 0xb75f7388, eip at 0xb75f738c

“ebp, eip Locals at and Previous Frame's sp”是什么意思?请解释

【问题讨论】:

    标签: gdb


    【解决方案1】:

    要了解“ebp, eip Locals at and Previous Frame's sp”是什么意思,你需要了解x86 calling convention

    一旦你了解了frames are laid out 的原理,其他所有事情都会一目了然。

    【讨论】:

      【解决方案2】:

      (gdb) 信息框

      堆栈级别 0

      • 回溯帧数,0为当前执行帧,向下增长,与栈一致。

      帧在 0xb75f7390

      • 此堆栈帧的起始内存地址

      eip = 0x804877f in base::func() (testing.cpp:16);保存的eip 0x804869a

      • eip 是要执行的下一条指令的寄存器(也称为程序计数器)。 所以此时下一个要执行的是“0x804877f”,也就是testing.cpp的第16行。

      • 保存的eip“0x804869a”就是所谓的“返回地址”,即从这个被调用栈返回后在调用栈帧中恢复的指令。它在“CALL”指令时被压入堆栈(保存以供返回)。

      在 0xb75f73b0 帧调用

      • 调用者栈帧的地址

      源语言 c++

      • 使用哪种语言

      参数列表位于 0xb75f7388,参数:this=0x0

      • 参数的起始地址

      0xb75f7388 的本地人

      局部变量的地址。

      上一帧的 sp 为 0xb75f7390

      这是前一帧的堆栈指针指向的位置(调用者帧),在调用的时刻,它也是被调用堆栈帧的起始内存地址。

      已保存的寄存器: 这是被调用者堆栈上的两个地址,用于两个保存的寄存器。

      • ebp 在 0xb75f7388 这是保存调用者堆栈帧的“ebp”寄存器的地址(请注意,它是寄存器,而不是调用者的堆栈地址)。 即,对应于“PUSH %ebp”。 “ebp”是寄存器,通常被认为是这个栈帧的locals的起始地址,它使用“offset”来寻址。 也就是说,局部变量的操作都使用了这个“ebp”,所以你会看到mov -0x4(%ebp), %eax之类的东西。

      • eip 位于 0xb75f738c 如前所述,但这里是堆栈的地址(包含值“0x804877f”)。

      【讨论】:

      • 很好的答案,但是我想为最后一点指出一个不同的答案。 “已保存的 eip 0x804869a”显示已保存指令指针的值,即在程序中确切返回的位置。但是,此值会保存到堆栈中的特定地址。要找出保存 eip 的堆栈上的地址,请查看“保存的寄存器”下的最后两行,其中显示“eip at 0xb75f738c”。换句话说,“保存的eip”的地址是0xb75f738c,包含值0x804869a而不是值0x804877f。值 0x804877f 存储在寄存器 eip 中。
      • 同理,之前的 ebp 也保存在堆栈中,堆栈地址为 0xb75f7388。据我了解,寄存器 ebp 的值指向保存前一个 ebp 的堆栈地址。然后它作为各种计算的参考点,例如ebp+4, ebp+8.
      • 听说可以通过“信息框”信息判断是否为内联函数。我们如何推断这些信息来确定函数是否内联?
      【解决方案3】:

      我知道这个问题来自...... 8 年前。但是对于未来的用户,我发现here的信息轮廓非常清晰。

      这是从上述链接中提取的:

      info frame
      info f
      
      This command prints a verbose description of the selected stack frame, including:
      
          the address of the frame
          the address of the next frame down (called by this frame)
          the address of the next frame up (caller of this frame)
          the language in which the source code corresponding to this frame is written
          the address of the frame’s arguments
          the address of the frame’s local variables
          the program counter saved in it (the address of execution in the caller frame)
          which registers were saved in the frame 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-28
        • 2014-10-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多