简体   繁体   中英

GDB remote debugging doesn't stop at some points

I am doing remote debugging with gdb and gdbserver on an ARM9 platform. Both these programs are compiled on an Ubuntu system with gdbserver compiled using a cross-compiler.

In general, the program under debug is able to stop at the set breakpoints. However, single-stepping using next or step works most of the time except at some locations of the code. In particular, the one that I find consistently giving me problems are switch blocks. For eg.

1    inchar = getchar();
2
3    switch (inchar)
4    {
5        case 'a':
6            ....
7            break;
8        case 'b':
9            ....
10           break;
11       case 'c':
12           ....
13           break;
14   }

If I set a breakpoint at line 1, the program stops at this line without issues. But if I subsequently used next or step , after hitting line 3, the next step will not cause the program to stop at either of the cases. Instead, it continues to run until the next breakpoint is hit or until I do a ctrl-c.

However, if I put a breakpoint at line 6 (for eg), without the breakpoint at line 1, the program can stop correctly at this line.

Has anyone encountered this? Where does the problem lie? How can I fix this behaviour?

Thanks.

First of all, disable optimizations. They can cause the compiler to swap certain lines, or omit entire sections if you mistakenly created code that does not run, eg

bool condition = false;
xxx;
if (condition)
   printf("this code will not run");

The default level of optimization is -O2, and the best option for debug is -Og. Try finding and changing those.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM