When debugging with gdb, sometimes the running position displayed by gdb is strange?

345 views Asked by At

When debugging with gdb, sometimes the displayed running position is strange. When I use n to execute the next line, the instruction I want to focus on has already been executed. Below is an example. The cursor showing the execution position is not currently placed on any command enter image description here

When I use the n command, the result is as shown in the figure below.

enter image description here

You can see that the cursor does not stay on line 911. Sometimes skip several lines.

And the cursor often stays on the comment.

enter image description here

2

There are 2 answers

0
ks1322 On

When you are stepping with n in GDB tui mode, source code window can get broken. This can happen when the program is printing something to stdout, breaking layout of tui windows. Looks like this is what happening in 911 line in DPRINTF() call. To fix the layout you can press Ctrl+L and tui window will be refreshed.

0
Employed Russian On

When debugging with gdb, sometimes the displayed running position is strange.

This usually happens for one or two reasons:

  • Your source is out of date with respect to the binary you are debugging (i.e. you've edited the source, but didn't rebuild the binary to match the new source), or
  • Your binary is built with optimization on (see this answer).