分段错误
可能的重复:
btree 实现中的分段错误
我收到这样的错误,如何调试它?您能否提供一些方法来调试此错误:
*** glibc detected *** ./a.out: free(): invalid pointer: 0x0821b158 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0xbd7591]
/lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0xbd8de8]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xbdbecd]
./a.out[0x80490c3]
./a.out[0x8048bdc]
./a.out[0x8048642]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb82bd6]
./a.out[0x80484b1]
======= Memory map: ========
004e5000-00500000 r-xp 00000000 08:06 1192669 /lib/ld-2.11.1.so
00500000-00501000 r--p 0001a000 08:06 1192669 /lib/ld-2.11.1.so
00501000-00502000 rw-p 0001b000 08:06 1192669 /lib/ld-2.11.1.so
007aa000-007c7000 r-xp 00000000 08:06 1179731 /lib/libgcc_s.so.1
007c7000-007c8000 r--p 0001c000 08:06 1179731 /lib/libgcc_s.so.1
007c8000-007c9000 rw-p 0001d000 08:06 1179731 /lib/libgcc_s.so.1
0096b000-0096c000 r-xp 00000000 00:00 0 [vdso]
00b6c000-00cbf000 r-xp 00000000 08:06 1311379 /lib/tls/i686/cmov/libc-2.11.1.so
00cbf000-00cc0000 ---p 00153000 08:06 1311379 /lib/tls/i686/cmov/libc-2.11.1.so
00cc0000-00cc2000 r--p 00153000 08:06 1311379 /lib/tls/i686/cmov/libc-2.11.1.so
00cc2000-00cc3000 rw-p 00155000 08:06 1311379 /lib/tls/i686/cmov/libc-2.11.1.so
00cc3000-00cc6000 rw-p 00000000 00:00 0
08048000-0804a000 r-xp 00000000 08:06 393339 /home/user/Desktop/a.out
0804a000-0804b000 r--p 00001000 08:06 393339 /home/user/Desktop/a.out
0804b000-0804c000 rw-p 00002000 08:06 393339 /home/user/Desktop/a.out
0821b000-0823c000 rw-p 00000000 00:00 0 [heap]
b7600000-b7621000 rw-p 00000000 00:00 0
b7621000-b7700000 ---p 00000000 00:00 0
b7708000-b7709000 rw-p 00000000 00:00 0
b771a000-b771e000 rw-p 00000000 00:00 0
bfc39000-bfc4e000 rw-p 00000000 00:00 0 [stack]
Aborted
Possible Duplicate:
Segmentation fault in btree implementation
I get an error like this, How can I debug it? Can you please give some some method to debug this error:
*** glibc detected *** ./a.out: free(): invalid pointer: 0x0821b158 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0xbd7591]
/lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0xbd8de8]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xbdbecd]
./a.out[0x80490c3]
./a.out[0x8048bdc]
./a.out[0x8048642]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb82bd6]
./a.out[0x80484b1]
======= Memory map: ========
004e5000-00500000 r-xp 00000000 08:06 1192669 /lib/ld-2.11.1.so
00500000-00501000 r--p 0001a000 08:06 1192669 /lib/ld-2.11.1.so
00501000-00502000 rw-p 0001b000 08:06 1192669 /lib/ld-2.11.1.so
007aa000-007c7000 r-xp 00000000 08:06 1179731 /lib/libgcc_s.so.1
007c7000-007c8000 r--p 0001c000 08:06 1179731 /lib/libgcc_s.so.1
007c8000-007c9000 rw-p 0001d000 08:06 1179731 /lib/libgcc_s.so.1
0096b000-0096c000 r-xp 00000000 00:00 0 [vdso]
00b6c000-00cbf000 r-xp 00000000 08:06 1311379 /lib/tls/i686/cmov/libc-2.11.1.so
00cbf000-00cc0000 ---p 00153000 08:06 1311379 /lib/tls/i686/cmov/libc-2.11.1.so
00cc0000-00cc2000 r--p 00153000 08:06 1311379 /lib/tls/i686/cmov/libc-2.11.1.so
00cc2000-00cc3000 rw-p 00155000 08:06 1311379 /lib/tls/i686/cmov/libc-2.11.1.so
00cc3000-00cc6000 rw-p 00000000 00:00 0
08048000-0804a000 r-xp 00000000 08:06 393339 /home/user/Desktop/a.out
0804a000-0804b000 r--p 00001000 08:06 393339 /home/user/Desktop/a.out
0804b000-0804c000 rw-p 00002000 08:06 393339 /home/user/Desktop/a.out
0821b000-0823c000 rw-p 00000000 00:00 0 [heap]
b7600000-b7621000 rw-p 00000000 00:00 0
b7621000-b7700000 ---p 00000000 00:00 0
b7708000-b7709000 rw-p 00000000 00:00 0
b771a000-b771e000 rw-p 00000000 00:00 0
bfc39000-bfc4e000 rw-p 00000000 00:00 0 [stack]
Aborted
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 (
gcc -g *.c
) 上进行调试构建,然后查看堆栈。具体来说,此错误是因为您在错误的指针上调用了
free
。一些代码可能会帮助我们更具体地查看您的问题。
Build with debug on (
gcc -g *.c
) and then look at your stack.Specifically this error is because you called
free
on a bad pointer.Some code might help us look at your problem more specifically.
您可能会发现调试此类错误的最简单方法是使用调试器。
正如 Starkey 建议的那样,请确保在编译时启用调试符号(通过 gcc 的
-g
选项)。您可能会发现,当您的程序因分段错误而崩溃时,它会生成一个核心文件。您可以使用调试器(例如gdb)打开核心文件并进行调查调用堆栈。使用调试器的优点是它会(如果您启用了调试符号)显示源文件中的行号,而不仅仅是提供内存位置。
如果您没有核心文件,您可以从 gdb 中运行应用程序,然后重现分段错误。
You'll probably find that the easiest way of debugging errors like this is with the use of a debugger.
As Starkey suggested, make sure that you enable debug symbols when you compile (through the
-g
option to gcc).You may find that when your program crashed with the segmentation fault that it generated a core file. You can use a debugger (eg. gdb) to open the core file and to investigate the call stack. The advantage of using the debugger is that it will (if you've enabled debug symbols) show you the line numbers within your source files, rather than just providing memory locations.
If you don't have a core file you can run your application from within gdb and then reproduce the segmentation fault.