perror函数在定位段错误或内存溢出时的神效

*** Error in `/home/fulinux/libcanbus/test/.libs/lt-client-cycle2snd': free(): invalid next size (normal): 0x00000000022afaf0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x80996)[0x7f5ceb3ff996]
/lib/x86_64-linux-gnu/libc.so.6(fclose+0x14d)[0x7f5ceb3ed9bd]
/home/fulinux/libcanbus/src/.libs/libcanbus.so.0(can_send+0x342)[0x7f5ceb749b52]
/home/fulinux/libcanbus/src/.libs/libcanbus.so.0(cycle2sndpkt+0x233)[0x7f5ceb749e33]
/lib/x86_64-linux-gnu/libc.so.6(+0x36ff0)[0x7f5ceb3b5ff0]
/home/fulinux/libcanbus/test/.libs/lt-client-cycle2snd(main+0x1cd)[0x4009dd]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f5ceb3a0de5]
/home/fulinux/libcanbus/test/.libs/lt-client-cycle2snd[0x400a2c]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:01 278103                             /home/fulinux/libcanbus/test/.libs/lt-client-cycle2snd
00600000-00601000 r--p 00000000 08:01 278103                             /home/fulinux/libcanbus/test/.libs/lt-client-cycle2snd
00601000-00602000 rw-p 00001000 08:01 278103                             /home/fulinux/libcanbus/test/.libs/lt-client-cycle2snd
022af000-022d0000 rw-p 00000000 00:00 0                                  [heap]
7f5ceaf4c000-7f5ceaf61000 r-xp 00000000 08:01 1703941                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f5ceaf61000-7f5ceb160000 ---p 00015000 08:01 1703941                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f5ceb160000-7f5ceb161000 r--p 00014000 08:01 1703941                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f5ceb161000-7f5ceb162000 rw-p 00015000 08:01 1703941                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f5ceb162000-7f5ceb179000 r-xp 00000000 08:01 1708215                    /lib/x86_64-linux-gnu/libpthread-2.17.so
7f5ceb179000-7f5ceb379000 ---p 00017000 08:01 1708215                    /lib/x86_64-linux-gnu/libpthread-2.17.so
7f5ceb379000-7f5ceb37a000 r--p 00017000 08:01 1708215                    /lib/x86_64-linux-gnu/libpthread-2.17.so
7f5ceb37a000-7f5ceb37b000 rw-p 00018000 08:01 1708215                    /lib/x86_64-linux-gnu/libpthread-2.17.so
7f5ceb37b000-7f5ceb37f000 rw-p 00000000 00:00 0 
7f5ceb37f000-7f5ceb53c000 r-xp 00000000 08:01 1708100                    /lib/x86_64-linux-gnu/libc-2.17.so
7f5ceb53c000-7f5ceb73c000 ---p 001bd000 08:01 1708100                    /lib/x86_64-linux-gnu/libc-2.17.so
7f5ceb73c000-7f5ceb740000 r--p 001bd000 08:01 1708100                    /lib/x86_64-linux-gnu/libc-2.17.so
7f5ceb740000-7f5ceb742000 rw-p 001c1000 08:01 1708100                    /lib/x86_64-linux-gnu/libc-2.17.so
7f5ceb742000-7f5ceb747000 rw-p 00000000 00:00 0 
7f5ceb747000-7f5ceb74b000 r-xp 00000000 08:01 277688                     /home/fulinux/libcanbus/src/.libs/libcanbus.so.0.0.0
7f5ceb74b000-7f5ceb94a000 ---p 00004000 08:01 277688                     /home/fulinux/libcanbus/src/.libs/libcanbus.so.0.0.0
7f5ceb94a000-7f5ceb94b000 r--p 00003000 08:01 277688                     /home/fulinux/libcanbus/src/.libs/libcanbus.so.0.0.0
7f5ceb94b000-7f5ceb94c000 rw-p 00004000 08:01 277688                     /home/fulinux/libcanbus/src/.libs/libcanbus.so.0.0.0
7f5ceb94c000-7f5ceb96f000 r-xp 00000000 08:01 1708076                    /lib/x86_64-linux-gnu/ld-2.17.so
7f5cebb55000-7f5cebb58000 rw-p 00000000 00:00 0 
7f5cebb6a000-7f5cebb6e000 rw-p 00000000 00:00 0 
7f5cebb6e000-7f5cebb6f000 r--p 00022000 08:01 1708076                    /lib/x86_64-linux-gnu/ld-2.17.so
7f5cebb6f000-7f5cebb71000 rw-p 00023000 08:01 1708076                    /lib/x86_64-linux-gnu/ld-2.17.so
7fffb03f5000-7fffb0416000 rw-p 00000000 00:00 0                          [stack]
7fffb0494000-7fffb0496000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)

当你碰到这个问题时,你也许通过backtrace函数或者其他内存溢出(段错误)分析工具都无从下手时你可以用一个简单的方式定位,那就是:

perror("fulinux");

函数来定位,有些时候你前面出现段错误或者内存溢出,但是却没有任何警告,通常是在你调用一个系统调用时,才会向你反映段错误或者内存溢出的问题。虽说

printf()

函数也是系统调用,但是却不能可以达到上面的效果。今后大家要是遇到很棘手的段错误或内存溢出时无法定位时,不妨在内存操作的附近放上perror函数,如果出现错误,它会及时的向你反映错误。


你可能感兴趣的:(free,core,Invalid,next,perror,aborted,backtrace,SI,dumped)