How to debug a clang compiled executable.

I have a clang compiled executable that is aborting during runtime whereas a GCC compiled version runs just fine. Since I am completely new to debugging a compiler not sure how I should proceed. I tried using gdb (from Xcode 3.1.4 on OS X 10.5) to debug the executable but it seems that no debug symbols are being compiled in? gdb did catch the abort and I tried to get a backtrace with "bt" and I got the following:

Program received signal SIGABRT, Aborted.
0x92993e42 in __kill ()
(gdb) bt
#0 0x92993e42 in __kill ()
#1 0x92993e34 in kill$UNIX2003 ()
#2 0x92a0623a in raise ()
#3 0x92a12622 in __abort ()
#4 0x929de43e in __chk_fail ()
#5 0x929c1ca9 in __strncat_chk ()
Die: DW_TAG_restrict_type (abbrev = 33, offset = 7574)
  has children: FALSE
  attributes:
    DW_AT_type (DW_FORM_ref4) constant ref: 3194 (adjusted)
    DW_AT_decl_file (DW_FORM_data1) constant: 2
    DW_AT_decl_line (DW_FORM_data1) constant: 0
Dwarf Error: Cannot find type of die [in module /Users/Shared/Kitware-CVS/VTK-clang-dbg-i386/bin/vtkWrapJava]

The program was compiled with the following:

/Users/Shared/Toolkits/llvm/bin/clang -DVTK_IN_VTK -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -Wunused -Wpointer-arith -Winvalid-pch -Wcast-align -Wdisabled-optimization -Wnewline-eof -fdiagnostics-show-option -Wno-deprecated-declarations -Wno-uninitialized -g -fstack-protector-all -D_FORTIFY_SOURCE=2 -g -arch i386 ....

Clang itself was compiled as a "Release with Assertions" as part of a llvm build using CMake.
515:[mjackson@ferb:tools]$ clang --version
clang version 2.8 (trunk 109582)
Target: i386-apple-darwin9
Thread model: posix

Any help would be appreciated. Thanks

strncat_chk is used because you defined _FORTIFY_SOURCE. IIRC, it helps
check for overruns using C string functions. I believe in 10.5 the
_FORTIFY_SOURCE version of strncat was screwy, ah, here you go:

<http://lists.apple.com/archives/xcode-users/2008/Jul/msg00848.html&gt;

I think it's fixed on 10.6.

Try again without -D_FORTIFY_SOURCE=2, and maybe remove -fstack-
protector-all too.

Ewww...don't remove the "-fstack-protector-all". It's your friend. :slight_smile: If it's aborting because of the stack protector, then you have a definite buffer overrun.

-bw

strncat_chk is used because you defined _FORTIFY_SOURCE. IIRC, it helps
check for overruns using C string functions. I believe in 10.5 the
_FORTIFY_SOURCE version of strncat was screwy, ah, here you go:

<http://lists.apple.com/archives/xcode-users/2008/Jul/msg00848.html&gt;

I think it's fixed on 10.6.

Try again without -D_FORTIFY_SOURCE=2, and maybe remove -fstack-
protector-all too.

Ewww...don't remove the "-fstack-protector-all". It's your friend. :slight_smile: If

It is one's friend, in general.

it's aborting because of the stack protector, then you have a definite
buffer overrun.

That's fallacious. It could be aborting because of a bug with -fstack-
protector-all, which is exactly what I'm saying. See <rdar://6105964>
if you have access.

FWIW That bug got fixed in 2008 and the fix shipped with SnowLeopard.

-Chris