Skip to content

Alternative Debugging Technique

loarabia edited this page Jan 23, 2012 · 1 revision

If the original debugging technique doesn't work for you, you can try something like this to debug clang.

$> clang++ -v main.cpp
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.2 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier
-main-file-name main.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2   
-target-linker-version 127.2 -v -resource-dir /usr/bin/../lib/clang/3.0 -fdeprecated-macro -ferror-limit 19
-fmessage-length 238 -stack-protector 1 -fblocks -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o /var/folders/j2/rs3jg3ns4vl6c1b19qgv2fmr0000gn/T/cc-nPsPwn.o -x c++ main.cpp
clang -cc1 version 3.0 based upon llvm 3.0svn hosted on x86_64-apple-darwin11.2.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.2.1
 /usr/include/c++/4.2.1/backward
 /usr/local/include
 /usr/bin/../lib/clang/3.0/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.7.2 -o a.out -lcrt1.10.6.o    
/var/folders/j2/rs3jg3ns4vl6c1b19qgv2fmr0000gn/T/cc-nPsPwn.o -lstdc++ -lSystem  
/usr/bin/../lib/clang/3.0/lib/darwin/libclang_rt.osx.a

See the first line up there? The one that begins with "/usr/bin/clang" and ends a few newlines later at main.cpp. Copy all of that without the quotes and pass it into GDB:

$> gdb --args clang <40 some args that may be specific to what you passed in>

Make sure when you run clang++ -v or when you pass clang into gdb that you're passing the version you've built with debugging symbols. If you're working on OS X, its especially easy to forget that . . .

Clone this wiki locally