Segmentation fault [duplicate]

冷暖自知 提交于 2019-12-18 09:26:50

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5472379/segmentation-fault

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!