[LLVMdev] Is clang -g (gdb) support broken for mingw builds?

Kyle McKay mackyle at gmail.com
Sat Oct 8 05:41:57 PDT 2011


My test environment:

1. Installed mingw/MSYS from sourceforge.net/projects/mingw using the  
"Automated MinGW Installer" mingw-get-inst-20110802.exe (installed  
everything except Fortran).
2. Installed Python 2.7 from www.python.org/download using  
python-2.7.2.msi
3. MSYS bash path set to /c/MinGW/bin:/bin:/c/Python27:/c/WINDOWS/ 
system32:/c/WINDOWS:/c/WINDOWS/system32/wbem
4. Built clang according to the instructions at clang.llvm.org/ 
get_started.html using revision r141407 (2011-10-07 12:55:21 -0700)  
for both the llvm/trunk and cfe/trunk checkouts -- it built without  
any problems.

My test source file tenline.c:

----- BEGIN tenline.c -----
#include <stdio.h>
int main()
{
puts("line 4");
puts("line 5");
puts("line 6");
puts("line 7");
puts("line 8");
return 0;
}
----- END tenline.c -----

The problem is that the gdb included with MinGW/MSYS doesn't work on  
the debug information created by clang -- either that or clang is  
failing to produce full debug information.  I tested as follows:

gdb --version reports:
   GNU gdb (GDB) 7.2
   This GDB was configured as "mingw32".

Compiling the tenline.c source file with MinGW/MSYS's gcc and with the  
just-built clang as follows:

gcc -O0 -g -o tenline_gcc tenline.c

clang -O0 -g -o tenline_clang tenline.c

Both the tenline_gcc and tenline_clang executables run correctly and  
produce the expected 5 lines of output.

However, attempting to set a breakpoint at line 7 (or any line for  
that matter) fails with the clang-built version, but succeeds with the  
gcc-built version.

I tested the gcc-built version like so:

echo "b 7" | gdb -q tenline_gcc
   Reading symbols from tenline_gcc.exe...done.
   (gdb) Breakpoint 1 at 0x4013f2: file tenline.c, line 7.

That's the expected behavior, but the clang-built version does this:

echo "b 7" | gdb -q tenline_clang
   Reading symbols from tenline_clang.exe...done.
   (gdb) No line 7 in file "tenline.c".

And yet clearly there's some kind of debugging information present in  
the clang-built version according to the following:

printf "b 7 \n info source" | gdb -q tenline_clang
   Reading symbols from tenline_clang.exe...done.
   (gdb) No line 7 in file "tenline.c".
   (gdb) Current source file is tenline.c
   Compilation directory is clangtest
   Located in clangtest/tenline.c
   Source language is c.
   Compiled with DWARF 2 debugging format.
   Does not include preprocessor macro info.

The same command using the gcc-built version reports:

printf "b 7 \n info source" | gdb -q tenline_gcc
   Reading symbols from tenline_gcc.exe...done.
   (gdb) Breakpoint 1 at 0x4013f2: file tenline.c, line 7.
   (gdb) Current source file is tenline.c
   Compilation directory is clangtest
   Located in clangtest/tenline.c
   Source language is c.
   Compiled with DWARF 2 debugging format.
   Does not include preprocessor macro info.

Inspecting the debugging line information in tenline_clang produces an  
empty list:

echo "interpreter-exec mi '-symbol-list-lines tenline.c'" |
       gdb -q tenline_clang.exe
   Reading symbols from tenline_clang.exe...done.
   (gdb) ^done,lines=[]

But doing the same thing with the tenline_gcc produces several entries:

echo "interpreter-exec mi '-symbol-list-lines tenline.c'" |
       gdb -q tenline_gcc.exe
   Reading symbols from tenline_gcc.exe...done.
   (gdb) ^done,lines=[{pc="0x004013c0",line="3"}, 
{pc="0x004013c9",line="3"},{pc="0x004013ce",line="4"}, 
{pc="0x004013da",line="5"},{pc="0x004013e6",line="6"}, 
{pc="0x004013f2",line="7"},{pc="0x004013fe",line="8"}, 
{pc="0x0040140a",line="9"},{pc="0x0040140f",line="10"}, 
{pc="0x00401411",line="0"}]

So clearly gdb is not able to read any line number debugging  
information from the clang-built executable.

Is there any way to get a version of clang built for mingw to produce  
debugging line information that's compatible with a mingw-built gdb?

As a side note, I had previously tried the pre-built mingw clang  
version 2.9 from llvm.org/releases/download.html with the same results  
(except that the pre-built 2.9 version compiles tenline.c in less than  
2 seconds whereas the clang I built takes just over 60 seconds to  
compile tenline.c).  Also I attempted to use the -integrated-as option  
with the clang I built, but when both -g and -integrated-as are  
combined using the mingw build of clang, clang errors out with  
"EmitRawText called on an MCStreamer that doesn't support it,  
something must not be fully mc'ized".  I also installed the very  
latest MinGW/MSYS environment for one attempt which gives a gdb  
version 7.3 instead of 7.2 but that also produces the same results as  
using gdb version 7.2 does.

Should the current trunk of llvm/clang support producing DWARF-2 debug  
information for a mingw build that's sufficient to set line-oriented  
breakpoints using mingw's gdb or is that a known not-implemented-yet  
feature?

Thanks,

Kyle



More information about the llvm-dev mailing list