回溯上的错误跟踪

时间:2010-11-05 22:23:21

标签: c++ eclipse debugging

我在输出中得到了这个。该程序仍然正常运行并完成,但我想追踪错误。有人能告诉我如何使用tis数据跟踪堆栈或其他东西来追踪导致错误的原因。我正在使用eclipse和gdb来运行C / C ++代码。这是输出:

*** glibc detected *** /home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos: free(): invalid pointer: 0x08061790 ***
======= Backtrace: =========
/lib/libc.so.6[0xf74ac5fb]
/lib/libc.so.6[0xf74aded4]
/lib/libc.so.6(cfree+0x6d)[0xf74b10cd]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xf769d851]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x8049a99]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x80498a7]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x8049799]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x804a139]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x8050486]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x804aeba]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x804c042]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x804ecad]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x8050e65]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x8052829]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x80512ce]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x804ff91]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x80495e4]
/lib/libc.so.6(__libc_start_main+0xfe)[0xf7455ace]
/home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos[0x8049481]
======= Memory map: ========
08048000-08059000 r-xp 00000000 00:15 24682418                           /home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos
08059000-0805a000 r-xp 00010000 00:15 24682418                           /home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos
0805a000-0805b000 rwxp 00011000 00:15 24682418                           /home/f85/njvanbal/workspace/nachos2_v2/userprog/nachos
0805b000-0807c000 rwxp 00000000 00:00 0                                  [heap]
f7300000-f7321000 rwxp 00000000 00:00 0 
f7321000-f7400000 ---p 00000000 00:00 0 
f743d000-f743f000 rwxp 00000000 00:00 0 
f743f000-f7598000 r-xp 00000000 08:01 913457                             /lib/libc-2.10.1.so
f7598000-f7599000 ---p 00159000 08:01 913457                             /lib/libc-2.10.1.so
f7599000-f759b000 r-xp 00159000 08:01 913457                             /lib/libc-2.10.1.so
f759b000-f759c000 rwxp 0015b000 08:01 913457                             /lib/libc-2.10.1.so
f759c000-f759f000 rwxp 00000000 00:00 0 
f759f000-f75bc000 r-xp 00000000 08:01 912324                             /lib/libgcc_s.so.1
f75bc000-f75bd000 r-xp 0001c000 08:01 912324                             /lib/libgcc_s.so.1
f75bd000-f75be000 rwxp 0001d000 08:01 912324                             /lib/libgcc_s.so.1
f75be000-f75e5000 r-xp 00000000 08:01 912355                             /lib/libm-2.10.1.so
f75e5000-f75e6000 r-xp 00027000 08:01 912355                             /lib/libm-2.10.1.so
f75e6000-f75e7000 rwxp 00028000 08:01 912355                             /lib/libm-2.10.1.so
f75e7000-f76cb000 r-xp 00000000 08:01 1057029                            /usr/lib/libstdc++.so.6.0.12
f76cb000-f76cf000 r-xp 000e4000 08:01 1057029                            /usr/lib/libstdc++.so.6.0.12
f76cf000-f76d0000 rwxp 000e8000 08:01 1057029                            /usr/lib/libstdc++.so.6.0.12
f76d0000-f76d7000 rwxp 00000000 00:00 0 
f7731000-f7733000 rwxp 00000000 00:00 0 
f7733000-f7751000 r-xp 00000000 08:01 913452                             /lib/ld-2.10.1.so
f7751000-f7752000 r-xp 0001d000 08:01 913452                             /lib/ld-2.10.1.so
f7752000-f7753000 rwxp 0001e000 08:01 913452                             /lib/ld-2.10.1.so
ffdac000-ffdc2000 rwxp 00000000 00:00 0                                  [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0       

                       [vdso]

1 个答案:

答案 0 :(得分:0)

听起来你正试图释放你不拥有的记忆。我建议在valgrind下运行你的程序。

http://valgrind.org/docs/manual/quick-start.html

作为旁注,这样的错误通常来自于在c ++中进行显式内存管理。你通常不应该在c ++中“手动”释放或删除内存,而是使用标准容器或智能指针来管理内存。