1 #include "string" 2 using namespace std; 3 4 bool m_bInited = true; 5 int m_imaxsize = 100; 6 7 int test() 8 { 9 if (!m_bInited) 10 { 11 return -1; 12 } 13 14 std::string gbkInput = ""; 15 std::string utf8Input = ""; 16 if (gbkInput.size() > m_imaxsize) 17 { 18 return 1; 19 } 20 return 0; 21 } 22 23 int main() 24 { 25 test(); 26 return 0; 27 }
when using the gdb step from line 16, the debugging sequence:
line 16 β line 20 β line 18 β line 21.
(gdb) b 16 (gdb) r Breakpoint 1, test () at main.cpp:16 16 if (gbkInput.size() > m_imaxsize) (gdb) n 20 return 0; (gdb) n 18 return 1; (gdb) n 21 }
compile: g ++ -g main.cpp -o test
why does gdb display line 18? and the return value of test () is 0.
My gcc version is 4.1.2. GNU gdb Fedora (6.8-37.el5) or GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-37.el5). The gdb version also has this problem.
BTW: if the translation line is 14, line 15 (these two lines are var) to line 9, this will be fine. gdb does not display line 18! it seemed like the var line was causing this error.
Can everyone help me? Thanks!
source share