gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 11:13:18 27 4
gpt4 key购买 nike

当我在 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 $0x9542c,%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

看起来非常好。但奇怪的是,如果我使用“si”进入“get_pc_thunk”函数,它甚至没有输入第一个 nop 就出现段错误。

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

最佳答案

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

检查您的程序是否存在无限(或非常深)递归。

另外,这个:

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

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

关于c - x86 程序集中出现奇怪的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31806068/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com