[Bug gdb/21221] gdb hangs while stepping an empty loop

luis.machado at linaro dot org sourceware-bugzilla@sourceware.org
Wed Oct 9 23:59:00 GMT 2019


https://sourceware.org/bugzilla/show_bug.cgi?id=21221

Luis Machado <luis.machado at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |luis.machado at linaro dot org

--- Comment #6 from Luis Machado <luis.machado at linaro dot org> ---
After investigating this in more detail, we're really dealing with some
corner/degenerate cases here. It seems unlikely we will be able to fix all of
the variations of this annoyance without some more complex changes. Then the
question that comes to mind is if it is really worth the effort.

In the worst case, we have an empty loop, a jump instruction that jumps to
itself. GDB won't see line changes when we next/step over this. So it will be
equally "stuck" (in reality it keeps moving, as Omair said, but it appears to
the user that it is stuck).

Then there are other cases where we have some tight/empty loop that is written
in some particular way that will cause compilers to not generate a line
transition from the for loop header to the statements in the body.

More generally, even non-corner-case code will hit this annoyance if we craft
the code in a particular way. For example, if we construct a for loop, complete
with header and non-empty body, but write it in a single line, GDB will also
display the same behavior. But in this particular case we could argue that it
is a GDB problem for not noticing the column transitions as opposed to line
transitions.

In summary, each particular case may require a slightly different approach to
get the compiler to output a meaningful line transition. Take, for example, the
following testcase:

1  int main (void)
2  {
3    while (1)
4    {
5      for (unsigned int i = 0U; i < 0xFFFFFU; i++)
6      {
7        ;
8      }
9    }
10 }

We could force GCC to output a line transition to line 8 when we reach the
instruction that jumps back to the header. Then again, is that jump really
properly mapped to the for loop's body's closing brace? What would happen if we
just opt to not have the opening/closing braces? What would the right
transition be in that case?

Another example is the following:

1  int main(void)
2  {
3  int var = 0;
4  
5  for (;;)
6  {
7    var++;
8  }
9  
10 return 0;
11 }

The above will also confuse GDB due to not having a proper for loop header. So
we jump into line 7, but then we don't have a line transition when we do the
next iteration. The instruction that jumps to the header is now mapped to line
7. It doesn't map to line 8 (the for loop's closing brace) or 5 (the for loop's
header).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Gdb-prs mailing list