Discussion:
[Bug gdb/21221] New: gdb hangs while stepping an empty loop
prakhar.bahuguna at arm dot com
2017-03-06 13:20:28 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21221

Bug ID: 21221
Summary: gdb hangs while stepping an empty loop
Product: gdb
Version: HEAD
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: prakhar.bahuguna at arm dot com
Target Milestone: ---

Created attachment 9871
--> https://sourceware.org/bugzilla/attachment.cgi?id=9871&action=edit
Reproducer test case

Given the empty for loop in the reproducer with a large number of iterations,
gdb hangs while attempting to step over a single iteration of the loop. The
server hangs and must be interrupted manually.

The issue does not present itself if the loop contains an instruction - adding
__asm("NOP"); inside the loop is sufficient to suppress the bug and allow the
loop to be stepped correctly.

This issue can be reproduced on trunk for both ARM and x86 platforms.
--
You are receiving this mail because:
You are on the CC list for the bug.
ilg at livius dot net
2017-03-06 14:42:14 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21221

Liviu Ionescu <ilg at livius dot net> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |ilg at livius dot net
--
You are receiving this mail because:
You are on the CC list for the bug.
omair.javaid at linaro dot org
2018-02-20 08:51:11 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21221

Omair Javaid <omair.javaid at linaro dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |omair.javaid at linaro dot org

--- Comment #1 from Omair Javaid <omair.javaid at linaro dot org> ---
This is line info generation issue and not a gdb bug.

I did a test build of attached sample code on Ubuntu 16.04 (x86_64)

With gcc version 5.4.0:
gcc -ggdb3 -O0 -o file-gcc file.c

(gdb) info line file.c:8
Line 8 of "file.c" is at address 0x4004f0 <main+26> but contains no code.

With clang version 5.0.0-3~16.04.1:
clang-5.0 -ggdb3 -O0 -o file-clang file.c

(gdb) info line file.c:8
Line 8 of "file.c" starts at address 0x4004df <main+31>
and ends at 0x4004e4 <main+36>.

gcc generates no line information for empty brace and considers the for loop as
a single statement but clang generates line information for empty braces as
well. Therefore you will see clang generated exe doing stepping between start
and end of inner loop. GCC however will wait for the loop to complete for
successful step. gdb native or remote debugging does not hang but rather
stepping for the loop statement requires a lot of time. For example
RaspberryPi2 Model B+ completes 50 loop iterations in one second.
--
You are receiving this mail because:
You are on the CC list for the bug.
maxim.kuvyrkov at gmail dot com
2018-04-29 11:09:34 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21221

Maxim Kuvyrkov <maxim.kuvyrkov at gmail dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |maxim.kuvyrkov at gmail dot com

--- Comment #2 from Maxim Kuvyrkov <maxim.kuvyrkov at gmail dot com> ---
Hi Omair,

Do I understand correctly that GCC generates wrong line information? If that's
the case, would you please post listing of current debug line info (the buggy
one) and what should be the correct line info.

We'll then take this into GCC community to investigate and fix.

Thank you.
--
You are receiving this mail because:
You are on the CC list for the bug.
omair.javaid at linaro dot org
2018-05-07 11:09:50 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=21221

--- Comment #3 from Omair Javaid <omair.javaid at linaro dot org> ---
GCC Code Generated for main.c:
objdump -S gcc.out

int main (void)
{
4004d6: 55 push %rbp
4004d7: 48 89 e5 mov %rsp,%rbp
while (1)
{
for (unsigned int i = 0U; i < 0xFFFFFU; i++)
4004da: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
4004e1: eb 04 jmp 4004e7 <main+0x11>
4004e3: 83 45 fc 01 addl $0x1,-0x4(%rbp)
4004e7: 81 7d fc fe ff 0f 00 cmpl $0xffffe,-0x4(%rbp)
4004ee: 76 f3 jbe 4004e3 <main+0xd>
{
;
}
}
4004f0: eb e8 jmp 4004da <main+0x4>
4004f2: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
4004f9: 00 00 00
4004fc: 0f 1f 40 00 nopl 0x0(%rax)

GCC Line info:
objdump --dwarf=decodedline gcc.out

CU: ./main.c:
File name Line number Starting address
main.c 2 0x4004d6
main.c 5 0x4004da
main.c 5 0x4004e3
main.c 5 0x4004e7
main.c 9 0x4004f0

Gcc generates 3 line infos for addresses corresponding to loop.
There is no line info generated against:
4004ee: 76 f3 jbe 4004e3 <main+0xd>
Which should be line no 8 in this case.

Clang Code Generated for main.c:
objdump -S clang.out

int main (void)
{
4004c0: 55 push %rbp
4004c1: 48 89 e5 mov %rsp,%rbp
4004c4: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
while (1)
{
for (unsigned int i = 0U; i < 0xFFFFFU; i++)
4004cb: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%rbp)
4004d2: 81 7d f8 ff ff 0f 00 cmpl $0xfffff,-0x8(%rbp)
4004d9: 0f 83 13 00 00 00 jae 4004f2 <main+0x32>
{
;
}
4004df: e9 00 00 00 00 jmpq 4004e4 <main+0x24>
int main (void)
{
while (1)
{
for (unsigned int i = 0U; i < 0xFFFFFU; i++)
4004e4: 8b 45 f8 mov -0x8(%rbp),%eax
4004e7: 83 c0 01 add $0x1,%eax
4004ea: 89 45 f8 mov %eax,-0x8(%rbp)
4004ed: e9 e0 ff ff ff jmpq 4004d2 <main+0x12>
int main (void)
{
while (1)
4004f2: e9 d4 ff ff ff jmpq 4004cb <main+0xb>
4004f7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
4004fe: 00 00


Clang Line info:
objdump --dwarf=decodedline clang.out

CU: main.c:
File name Line number Starting address
main.c 2 0x4004c0
main.c 5 0x4004cb
main.c 5 0x4004d2
main.c 5 0x4004d9
main.c 8 0x4004df
main.c 5 0x4004e4
main.c 5 0x4004ed
main.c 3 0x4004f2

Clang generates 2 separate line information 1 for start of the loop at line no
5
and other for last brace which is at line no 8 at address 0x4004df
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...