堆栈粉碎后的错误信息如何处理
我的 C 程序在 Linux 上遇到一些问题。它在 Windows 上编译并运行得很好。 Linux终端返回此信息:
*** stack smashing detected ***: ./student terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x4b)[0xb7e908ab]
/lib/libc.so.6(__fortify_fail+0x0)[0xb7e90860]
./student[0x8048c09]
./student[0x80486dd]
/lib/libc.so.6(__libc_start_main+0xe5)[0xb7dc0775]
./student[0x80485e1]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 00:11 11222 /mnt/win/POT03/Eclipse/student
0804a000-0804b000 r--p 00001000 00:11 11222 /mnt/win/POT03/Eclipse/student
0804b000-0804c000 rw-p 00002000 00:11 11222 /mnt/win/POT03/Eclipse/student
0804c000-0821a000 rw-p 0804c000 00:00 0 [heap]
b7da9000-b7daa000 rw-p b7da9000 00:00 0
b7daa000-b7eeb000 r-xp 00000000 75:00 116292 /lib/libc-2.9.so
b7eeb000-b7eed000 r--p 00141000 75:00 116292 /lib/libc-2.9.so
b7eed000-b7eee000 rw-p 00143000 75:00 116292 /lib/libc-2.9.so
b7eee000-b7ef1000 rw-p b7eee000 00:00 0
b7ef4000-b7f01000 r-xp 00000000 75:00 116275 /lib/libgcc_s.so.1
b7f01000-b7f02000 r--p 0000c000 75:00 116275 /lib/libgcc_s.so.1
b7f02000-b7f03000 rw-p 0000d000 75:00 116275 /lib/libgcc_s.so.1
b7f03000-b7f06000 rw-p b7f03000 00:00 0
b7f06000-b7f22000 r-xp 00000000 75:00 116288 /lib/ld-2.9.so
b7f22000-b7f23000 r--p 0001b000 75:00 116288 /lib/ld-2.9.so
b7f23000-b7f24000 rw-p 0001c000 75:00 116288 /lib/ld-2.9.so
bf8eb000-bf900000 rw-p bf8eb000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
Aborted
What can I do with this information to track the Problem?
I'm experiencing some problems with my C program on Linux. It compiles and runs just fine on Windows. The Linux terminal returns this information:
*** stack smashing detected ***: ./student terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x4b)[0xb7e908ab]
/lib/libc.so.6(__fortify_fail+0x0)[0xb7e90860]
./student[0x8048c09]
./student[0x80486dd]
/lib/libc.so.6(__libc_start_main+0xe5)[0xb7dc0775]
./student[0x80485e1]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 00:11 11222 /mnt/win/POT03/Eclipse/student
0804a000-0804b000 r--p 00001000 00:11 11222 /mnt/win/POT03/Eclipse/student
0804b000-0804c000 rw-p 00002000 00:11 11222 /mnt/win/POT03/Eclipse/student
0804c000-0821a000 rw-p 0804c000 00:00 0 [heap]
b7da9000-b7daa000 rw-p b7da9000 00:00 0
b7daa000-b7eeb000 r-xp 00000000 75:00 116292 /lib/libc-2.9.so
b7eeb000-b7eed000 r--p 00141000 75:00 116292 /lib/libc-2.9.so
b7eed000-b7eee000 rw-p 00143000 75:00 116292 /lib/libc-2.9.so
b7eee000-b7ef1000 rw-p b7eee000 00:00 0
b7ef4000-b7f01000 r-xp 00000000 75:00 116275 /lib/libgcc_s.so.1
b7f01000-b7f02000 r--p 0000c000 75:00 116275 /lib/libgcc_s.so.1
b7f02000-b7f03000 rw-p 0000d000 75:00 116275 /lib/libgcc_s.so.1
b7f03000-b7f06000 rw-p b7f03000 00:00 0
b7f06000-b7f22000 r-xp 00000000 75:00 116288 /lib/ld-2.9.so
b7f22000-b7f23000 r--p 0001b000 75:00 116288 /lib/ld-2.9.so
b7f23000-b7f24000 rw-p 0001c000 75:00 116288 /lib/ld-2.9.so
bf8eb000-bf900000 rw-p bf8eb000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
Aborted
What can I do with this information to trace the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用调试信息编译程序,然后使用 valgrind 运行。
要尝试调试器:
Compile your program with debug info then run with valgrind.
To try a debugger:
首先你需要一个地图文件。从映射文件中您可以查找内存地址(0x8048c09)。该函数实际上将从堆栈中地址之前的地址开始。从这里你知道你在哪个函数中崩溃了,并且通过对生成的汇编程序的一些了解,你可以弄清楚它崩溃到函数中的程度。然后你查看代码并尝试找出你做错了什么。
如果失败......使用调试器。然后您将能够看到它崩溃的位置。从那里您甚至可以(如果您正在运行优化的构建,您将能够)查看您到底在调用什么以及参数是什么。然后您可以查看导致问题的原因并阻止其发生。
Firstly you need a map file. From the map file you can look up the memory address (0x8048c09). The function will actually start at an address prior to the address in the stack. From here you know which function you are crashed in and with a bit of knowledge of the assembler generated you can figure out how far into the function it crashed. You then look at the code and try to figure out what you are doing wrong.
Failing that ... use a debugger. You'll then be able to see whereabouts it crashed. From there you may even be able (if you are running an optimised build you WILL be able) to see what exactly you are calling and what the parameters are. You can then see what is causing the problem and you can stop it from occurring.