[問題] gdb找crash的地方

作者: kylehsnu (kyle)   2013-11-08 03:21:01
我的hw3 complile會過,但是一執行就會crash,出現下面的錯誤訊息:
(gdb) run
Starting program: /home/playerk/Dropbox/DSnP/hw3/bin/modCalc
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr
Program received signal SIGABRT, Aborted.
0xb7fdd424 in __kernel_vsyscall ()
我想用where找是哪個pointer出問題(嗎?),但是前面幾個都看不太懂,請求指點,
感謝>//<
(gdb) where
#0 0xb7fdd424 in __kernel_vsyscall ()
#1 0xb7d3db1f in raise () from /lib/i386-linux-gnu/libc.so.6
#2 0xb7d410b3 in abort () from /lib/i386-linux-gnu/libc.so.6
#3 0xb7f2c91d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#4 0xb7f2a563 in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#5 0xb7f2a59f in std::terminate() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#6 0xb7f2a82e in __cxa_throw () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#7 0xb7f850c4 in std::__throw_out_of_range(char const*) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#8 0xb7f9265f in std::string::substr(unsigned int, unsigned int) const () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#9 0x0804b402 in CmdParser::getCmd (this=0x805b020, cmd=...) at cmdParser.cpp:255
#10 0x0804ac93 in CmdParser::regCmd (this=0x805b020, cmd=..., nCmp=3, e=0x806b148) at cmdParser.cpp:60
#11 0x08049cd5 in initCommonCmd () at cmdCommon.cpp:19
#12 0x08049a70 in main (argc=1, argv=0xbffff154) at main.cpp:54
(gdb)
作者: arsenefrog (柯蛙)   2012-01-08 04:20:00
其實what()後面的東西就是出問題的函數了只需檢查你寫的substr()裡面的開始跟結束pointer位置這時候手動丟幾個不同長度的cmd測測看好像比較直觀(?
作者: kylehsnu (kyle)   2012-01-08 10:36:00
已解決,謝謝!

Links booklink

Contact Us: admin [ a t ] ucptt.com