分段故障 [英] Segmentation fault

查看:222
本文介绍了分段故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/5471765/segmentation-fault-in-btree-implementation\">Segmentation故障B树实现


我是新的C编码和我面临的一个问题。我得到这样一个错误,我该怎么调试呢?能否请您给一些某种方法来调试这个错误:

  *** glibc的检测*** ./a.out:免费():无效的指针:0x0821b158 ***
    =======回溯:=========
    /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]
    =======存储器映射:========
    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堆]
    b7600000-RW b7621000-P 00000000 00:00 0
    b7621000-b7700000 --- p 00000000 00:00 0
    b7708000-RW b7709000-P 00000000 00:00 0
    b771a000-RW b771e000-P 00000000 00:00 0
    bfc39000-RW bfc4e000-P 00000000 00:00 0 [堆栈]
    中止


解决方案

您可能会发现,像这样的错误调试的最简单的方法是使用调试器。

随着斯塔基建议,请确保您启用调试符号编译时(通过 -g 选项GCC)。

您可能会发现,当你的程序与它生成的核心文件分割故障坠毁。你可以使用一个调试器(如 GDB )打开核心文件,并调查调用堆栈。使用调试器的优点是,它会(如果启用了调试符号)告诉你的行号源文件中,而不是仅仅提供存储位置。

如果您还没有一个核心文件,您可以从GDB中运行你的应用程序,然后重现分段错误。

Possible Duplicate:
Segmentation fault in btree implementation

I am new to C coding and I am facing a problem. 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

解决方案

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.

这篇关于分段故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆