0
我在輸出中得到了這個。該程序仍然運行並正常結束,但我想追查錯誤。有人可以告訴我如何使用這些數據來追蹤堆棧或追查什麼導致錯誤。我使用edb和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-f00 rwxp 00000000 00:00 0
f00-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]
不幸的是,對於這個項目來說,唯一的C++是其他所有的類都在c中。它本質上是面向對象的c:/ – user381261 2010-11-05 22:50:54
使用c風格的內存管理來編寫正確的C++基本上是不可能的。這是因爲異常會打破c風格的「malloc,do work,then free」控制流。 – catphive 2010-11-11 00:04:00