[Bug c/60907] New: Can't break inside empty loop (without any optimization)
a3at.mail at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Apr 20 23:52:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60907
Bug ID: 60907
Summary: Can't break inside empty loop (without any
optimization)
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: a3at.mail at gmail dot com
It is very useful to break inside empty loops for debugging with gdb.
But unfortunately code generated by gcc don't allow to do this, unlike clang
(3.4-2)
Steps to reproduce:
==================
$ cat test.c
#include <stdio.h>
int main()
{
for (int i = 0; i < 10; ++i) {
}
return 0;
}
$ gcc -std=c99 -g3 -O0 test.c -o test; gdb -ex 'dprintf 5,"i: %i\n", i' -ex run
-batch ./test
Dprintf 1 at 0x4004c4: file test.c, line 5.
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
No symbol "i" in current context.
**We hit en error here because the breakpoint is installed behind the loop.**
$ clang -std=c99 -g3 -O0 test.c -o test; gdb -ex 'dprintf 5,"i: %i\n", i' -ex
run -batch ./test
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
i: 0
i: 1
i: 2
i: 3
i: 4
i: 5
i: 6
i: 7
i: 8
i: 9
[Inferior 1 (process 13274) exited normally]
More information:
================
$ gcc -Wall -Werror -std=c99 -g3 -O0 test.c -o test; gdb -ex 'disas/m main' -ba
tch ./test
Dump of assembler code for function main:
3 {
0x00000000004004ad <+0>: push rbp
0x00000000004004ae <+1>: mov rbp,rsp
4 for (int i = 0; i < 10; ++i) {
0x00000000004004b1 <+4>: mov DWORD PTR [rbp-0x4],0x0
0x00000000004004b8 <+11>: jmp 0x4004be <main+17>
0x00000000004004ba <+13>: add DWORD PTR [rbp-0x4],0x1
0x00000000004004be <+17>: cmp DWORD PTR [rbp-0x4],0x9
0x00000000004004c2 <+21>: jle 0x4004ba <main+13>
5
6 }
7 return 0;
0x00000000004004c4 <+23>: mov eax,0x0
8 }
0x00000000004004c9 <+28>: pop rbp
0x00000000004004ca <+29>: ret
End of assembler dump.
$ clang -Wall -Werror -std=c99 -g3 -O0 test.c -o test; gdb -ex 'disas/m main' -
batch ./test
Dump of assembler code for function main:
3 {
0x00000000004004d0 <+0>: push rbp
0x00000000004004d1 <+1>: mov rbp,rsp
0x00000000004004d4 <+4>: mov DWORD PTR [rbp-0x4],0x0
4 for (int i = 0; i < 10; ++i) {
0x00000000004004db <+11>: mov DWORD PTR [rbp-0x8],0x0
0x00000000004004e2 <+18>: cmp DWORD PTR [rbp-0x8],0xa
0x00000000004004e9 <+25>: jge 0x400504 <main+52>
0x00000000004004f4 <+36>: mov eax,DWORD PTR [rbp-0x8]
0x00000000004004f7 <+39>: add eax,0x1
0x00000000004004fc <+44>: mov DWORD PTR [rbp-0x8],eax
0x00000000004004ff <+47>: jmp 0x4004e2 <main+18>
0x0000000000400504 <+52>: mov eax,0x0
5
6 }
0x00000000004004ef <+31>: jmp 0x4004f4 <main+36>
7 return 0;
0x0000000000400509 <+57>: pop rbp
0x000000000040050a <+58>: ret
End of assembler dump.
So, jmp just after 6 line, allow us to breaking inside loop.
Versions:
========
gcc (Debian 4.8.2-16) 4.8.2
Debian clang version 3.4-2 (tags/RELEASE_34/final) (based on LLVM 3.4)
(just in case):
GNU gdb (GDB) 7.6.2 (Debian 7.6.2-1)
More information about the Gcc-bugs
mailing list