x86 程序集中出现奇怪的分段错误

Strange segmentation fault in x86 assembly

当我在 x86-Linux 中调试分段错误时,我 运行 遇到了这个问题:

这是来自 GDB 的段错误消息

0xe2a5a99f in my_function (pSt=pSt@entry=0xe1d09000, version=43)

这是错误的程序集:

0xe2a5a994 <my_function>      push   %ebp
0xe2a5a995 <my_function+1>    push   %edi
0xe2a5a996 <my_function+2>    push   %esi
0xe2a5a997 <my_function+3>    push   %ebx
0xe2a5a998 <my_function+4>    lea    -0x100b0c(%esp),%esp
0xe2a5a99f <my_function+11>   call   0xe29966cb <__x86.get_pc_thunk.bx>
0xe2a5a9a4 <my_function+16>   add    [=11=]x9542c,%ebx

正如您在上面看到的,故障线是 "call get_pc_thunk",它只是获取 pc 值。 而且,我检查了 0xe29966cb 处的内存是否有效并且可以使用以下命令访问:

(gdb) x/10i 0xe29966cb
   0xe29966cb <__x86.get_pc_thunk.bx>:  nop
   0xe29966cc <__x86.get_pc_thunk.bx+1>:        nop
   0xe29966cd <__x86.get_pc_thunk.bx+2>:        nop
   0xe29966ce <__x86.get_pc_thunk.bx+3>:        nop
   0xe29966cf <__x86.get_pc_thunk.bx+4>:        nop
   0xe29966d0 <__x86.get_pc_thunk.bx+5>:        nop
   0xe29966d1 <__x86.get_pc_thunk.bx+6>:        nop
   0xe29966d2 <__x86.get_pc_thunk.bx+7>:        nop
   0xe29966d3 <__x86.get_pc_thunk.bx+8>:        mov    (%esp),%ebx
   0xe29966d6 <__x86.get_pc_thunk.bx+11>:       ret    

看起来非常好。 但是 St运行gely,如果我使用 "si" 进入 "get_pc_thunk" 函数,它甚至没有输入第一个 nop 就出现段错误。

如有任何帮助,我们将不胜感激。

CALL(或 PUSH,属于 MOV (%esp))指令的崩溃几乎总是由于堆栈溢出。

检查你的程序是否有无限(或非常深)递归。

另外,这个:

0xe2a5a998 <my_function+4>    lea    -0x100b0c(%esp),%esp

意味着 my_function 正在为当前堆栈帧分配略多于 1MB 的局部变量。现在你知道为什么这可能不是一个好主意了。