<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Clang's debug info not as accurate as GCC's"
href="https://llvm.org/bugs/show_bug.cgi?id=25198">25198</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang's debug info not as accurate as GCC's
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>scott+llvm+bugzilla@pakin.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=15084" name="attach_15084" title="Sample C program for testing debug info">attachment 15084</a> <a href="attachment.cgi?id=15084&action=edit" title="Sample C program for testing debug info">[details]</a></span>
Sample C program for testing debug info
Clang is producing inferior debug info than GCC, at least for the
attached piece of code. Here's what happens when I compile with clang
and debug with gdb:
$ clang --version
clang version 3.7.0 (tags/RELEASE_370/final 246655)
Target: x86_64-unknown-linux-gnu
Thread model: posix
$ clang -O3 -g -o bad-debug bad-debug.c
$ gdb --args ./bad-debug 123
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<<a href="http://gnu.org/licenses/gpl.html">http://gnu.org/licenses/gpl.html</a>>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<<a href="http://www.gnu.org/software/gdb/bugs/">http://www.gnu.org/software/gdb/bugs/</a>>.
Find the GDB manual and other documentation resources online at:
<<a href="http://www.gnu.org/software/gdb/documentation/">http://www.gnu.org/software/gdb/documentation/</a>>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./bad-debug...done.
(gdb) b main
Breakpoint 1 at 0x400590: file bad-debug.c, line 6.
(gdb) r
Starting program: /tmp/bad-debug 123
Breakpoint 1, main (argc=2, argv=0x7fffffffe3f8) at bad-debug.c:6
6 volatile int iters = atoi(argv[1]);
(gdb) n
7 volatile int val = 0;
(gdb)
10 for (i = 0; i < iters; i++)
(gdb)
11 val = (val + 19191923) * 282833;
(gdb)
10 for (i = 0; i < iters; i++)
(gdb)
11 val = (val + 19191923) * 282833;
(gdb)
10 for (i = 0; i < iters; i++)
(gdb)
11 val = (val + 19191923) * 282833;
(gdb)
10 for (i = 0; i < iters; i++)
(gdb)
11 val = (val + 19191923) * 282833;
(gdb) p i
$1 = 0
(gdb) p val
$2 = 0
(gdb) n
10 for (i = 0; i < iters; i++)
(gdb) p i
$3 = 0
(gdb) p val
$4 = 1613956150
(gdb) n
11 val = (val + 19191923) * 282833;
(gdb) p i
$5 = 0
(gdb) p val
$6 = <optimized out>
(gdb)
That is, at each step, variables i and val are some combination of
zero, correct (only for val, not i), or optimized out. The exact same
behavior appears when optimizing with -O2 or -O1; -O0 works as
expected, however.
GCC, on the other hand, is providing more meaningful values for i and
val:
$ gcc --version
gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc -O3 -g -o bad-debug bad-debug.c
$ gdb --args ./bad-debug 123
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<<a href="http://gnu.org/licenses/gpl.html">http://gnu.org/licenses/gpl.html</a>>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<<a href="http://www.gnu.org/software/gdb/bugs/">http://www.gnu.org/software/gdb/bugs/</a>>.
Find the GDB manual and other documentation resources online at:
<<a href="http://www.gnu.org/software/gdb/documentation/">http://www.gnu.org/software/gdb/documentation/</a>>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./bad-debug...done.
(gdb) b main
Breakpoint 1 at 0x4004b0: file bad-debug.c, line 5.
(gdb) r
Starting program: /tmp/bad-debug 123
Breakpoint 1, main (argc=2, argv=0x7fffffffe3f8) at bad-debug.c:5
5 {
(gdb) n
6 volatile int iters = atoi(argv[1]);
(gdb)
7 volatile int val = 0;
(gdb)
10 for (i = 0; i < iters; i++)
(gdb)
11 val = (val + 19191923) * 282833;
(gdb)
10 for (i = 0; i < iters; i++)
(gdb)
11 val = (val + 19191923) * 282833;
(gdb)
10 for (i = 0; i < iters; i++)
(gdb)
11 val = (val + 19191923) * 282833;
(gdb)
10 for (i = 0; i < iters; i++)
(gdb)
11 val = (val + 19191923) * 282833;
(gdb) p i
$1 = 3
(gdb) p val
$2 = 1616115193
(gdb) n
10 for (i = 0; i < iters; i++)
(gdb) p i
$3 = 3
(gdb) p val
$4 = -1915599316
(gdb) n
11 val = (val + 19191923) * 282833;
(gdb) p i
$5 = 4
(gdb) p val
$6 = -1915599316
(gdb)
The inner loops are semantically quite similar:
Clang | GCC
-------------------------------------+-------------------------------------
.LBB0_1: | .L4:
imull $282833, %esi, %eax | movl 8(%rsp), %eax
addl $-729504285, %eax | addl $19191923, %eax
movl %eax, 16(%rsp) | imull $282833, %eax, %eax
incl 12(%rsp) | movl %eax, 8(%rsp)
movl 12(%rsp), %eax | movl 12(%rsp), %eax
cmpl 20(%rsp), %eax | addl $1, %eax
movl 16(%rsp), %esi | movl %eax, 12(%rsp)
jl .LBB0_1 | movl 12(%rsp), %edx
| movl 4(%rsp), %eax
| cmpl %eax, %edx
| jl .L4
This leads me to believe that the debug info is at fault, as opposed
to Clang performing some optimization that makes it impossible to
relate names to variables. I'm no DWARF expert, but I believe GCC's
DWARF information is indicating (correctly) that the variables reside
on the stack, while Clang's DWARF information is indicating that val
maps to %eax and i is a constant 0.
Any chance Clang can be updated to make its output more debuggable?</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>