Effectively Debugging Clang

Hello,

I am having a more general question related to debugging clang.

I start gdb (in MacOS) as follows;

ggdb clang++


(ggdb) run -cc1 -std=c++11 -stdlib=libc++ -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1 test1.cpp

In most of the time during debugging session I am unable to evaluate and print values of a certain variable. Sometimes my debugger freezes for long time, sometime i get a segmentation faults.

For example if I execute following on a QualType variable I get a segmentation fault.

(gdb) p FnRetType.getAsString()
line 1: 39759 Segmentation fault: 11 ggdb /Users/thejaka/development/crest/pxc/llvm/350/Debug+Asserts/bin/clang++

So my question is, what are the techniques you use to effectively debug clang ? and how can I overcome crashes like above ?

Your feedback is greatly appreciated.

Thank you
Regards
Thejaka Amila

You can use Xcode (by generating Xcode project with CMake) or use lldb
instead of gdb. Kind of weakly-related note; lldb has vim integration
as well.

Probably not helpful: I’m always booting up a Windows machine and use VS if I really need to debug clang…

Hello,

I am having a more general question related to debugging clang.

I start gdb (in MacOS) as follows;

>ggdb clang++
....
....
(ggdb) run -cc1 -std=c++11 -stdlib=libc++
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1
test1.cpp

In most of the time during debugging session I am unable to evaluate and
print values of a certain variable. Sometimes my debugger freezes for long
time, sometime i get a segmentation faults.

For example if I execute following on a QualType variable I get a
segmentation fault.

(gdb) p FnRetType.getAsString()
line 1: 39759 Segmentation fault: 11 ggdb
/Users/thejaka/development/crest/pxc/llvm/350/Debug+Asserts/bin/clang++

So my question is, what are the techniques you use to effectively debug
clang ? and how can I overcome crashes like above ?

I debug Clang and LLVM on Linux using gdb all the time. Which version of
gdb are you using?

Hi David,

I am using 7.7.1.

Thanks
-Thejaka

Hi,

What compiler do you use to build clang? Older versions of GDB (7.2,
7.4) had problems understanding objects (or the debug info) created by
GCC 4.8 and higher (typical symptom: none of the local variables were
visible to the debugger).

GDB 7.7 (on Linux) seems to be better, but I switched to the latest
gdb 7.8 anyway, built from sources.

Csaba

Hi,

What compiler do you use to build clang?

Well.. I am using Clang to build clang. Specific version is as follows;

[~]>clang -v

Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)

Target: x86_64-apple-darwin13.4.0

Thread model: posix
Thanks
-Thejaka

Oh, so it's clang all the way down :slight_smile:

Anyway, you could try building GDB 7.8 from source and using that.
I never used lldb so I don't know how it would behave.

Csaba