我的程序因segfault尝试将“1”写入字符串而失败。
(gdb) info frame
Stack level 0, frame at 0xb6b3c040:
eip = 0xb7877cdf; saved eip 0xb7858eae
called by frame at 0xb6b3cc50
Arglist at 0x91a1649, args:
Locals at 0x91a1649, Previous frame's sp is 0xb6b3c040
Saved registers:
ebx at 0xb6b3c02c, ebp at 0xb6b3c038, esi at 0xb6b3c030, edi at 0xb6b3c034, eip at 0xb6b3c03c
(gdb) bt
#0 0xb7877cdf in ?? () from /lib/i386-linux-gnu/libc.so.6
#1 0xb7858eae in vfprintf () from /lib/i386-linux-gnu/libc.so.6
#2 0xb787d91b in vsnprintf () from /lib/i386-linux-gnu/libc.so.6
#3 0x08ea7d7e in __gnu_cxx::__to_xstring<std::string, char> (__convf=0x85a2a50 <vsnprintf@plt>, __n=16, __fmt=0x91a1649 "%u") at /usr/include/c++/4.7/ext/string_conversions.h:95
#4 0x08ea6452 in std::to_string (__val=1) at /usr/include/c++/4.7/bits/basic_string.h:2871
...
我注意到根据gdb,Arglist不在堆栈中。怎么会发生?据我所知,* nix中有一个调用约定:参数被推送到堆栈,调用者清除堆栈帧。我通过回溯上下移动,其他地方arglist都在堆栈中。
答案 0 :(得分:0)
您可能会在不遵循标准调用约定和/或具有符号信息的汇编语言例程中崩溃。
可能,核心问题无论如何都高于第0帧。