[lldb-dev] Use lldb.so to create stack trace

Schlottke-Lakemper, Michael m.schlottke-lakemper at aia.rwth-aachen.de
Tue Jul 28 23:15:18 PDT 2015


This seems to work now, thanks. For my MWE I get nicely formatted stack traces.

However, one problem remains: if I try to link my actual application using virtually the same libraries on the command line, it fails with the following error:

/usr/lib64/gcc/x86_64-suse-linux/4.9/../../../../x86_64-suse-linux/bin/ld: /pds/opt/llvm/lib/libLLVMSupport.a(Path.cpp.o): undefined reference to symbol '_ZNSs4_Rep10_M_destroyERKSaIcE@@GLIBCXX_3.4'
/usr/lib64/libstdc++.so.6: error adding symbols: DSO missing from command line

Selectively removing or adding libraries at the end of the linker command does not help. Any ideas what might be wrong here?

Michael

PS: this is the full command minus some object files omitted for clarity (llvm lives in /pds/opt/llvm):

 /pds/opt/llvm/bin/clang++   -O0 -g3 -fno-inline -DCOMPILER_ATTRIBUTES -std=c++11 -stdlib=libc++ -Wall -Wextra -pedantic -Wshadow -Wfloat-equal -Wcast-align -Wfloat-equal -Wdisabled-optimization -Wformat=2 -Winvalid-pch -Winit-self -Wmissing-include-dirs -Wredundant-decls -Wpacked -Wpointer-arith -Wstack-protector -Wswitch-default -Wwrite-strings -Wno-type-safety -Werror -Wunused -Wno-infinite-recursion  -Wl,-rpath,/pds/opt/openmpi/lib64:/pds/opt/PointwiseV17.0R2/linux_x86_64/plugins:/pds/opt/intel/composer_xe_2015/lib/intel64/:/pds/opt/llvm/lib:/pds/opt/StarCD/lib:/pds/opt/torque/lib src/CMakeFiles/zfs.dir/zfscartesiangrid_inst_fv.cpp.o <many more object files here...> src/CMakeFiles/zfs.dir/main.cpp.o  -o src/zfs  -rdynamic /pds/opt/netcdf/lib64/libnetcdf.a /pds/opt/fftw/lib64/libfftw3.a /pds/opt/parallel-netcdf/lib/libpnetcdf.a /pds/opt/openmpi/lib64/libmpi_cxx.so /pds/opt/openmpi/lib64/libmpi.so /pds/opt/llvm/lib/libLLVMSupport.a -lrt -ldl -ltinfo -lpthread -lz -lm /pds/opt/llvm/lib/libc++abi.a -lpthread -lz -lm /pds/opt/llvm/lib/libc++abi.a -Wl,-rpath,/pds/opt/openmpi/lib64


-------- Original message --------
From: David Jones <djones at xtreme-eda.com>
Date: 28/07/2015 19:05 (GMT+01:00)
To: "Schlottke-Lakemper, Michael" <m.schlottke-lakemper at aia.rwth-aachen.de>
Cc: Zachary Turner <zturner at google.com>, lldb-dev at cs.uiuc.edu
Subject: Re: [lldb-dev] Use lldb.so to create stack trace

Linking is order-dependent:

clang++ -std=c++11 -stdlib=libc++ -I/pds/opt/llvm/include mwe.cpp -o main -lc++ -lc++abi /pds/opt/llvm/lib/libLLVMSupport.a

You are linking in LLVMSupport.a *after* libstdc++, so libstdc++ won't be used to resolve any symbols from LLVMSupport.a.

Interchange the order of the linking, putting -lc++ at the end ought to work.


On Tue, Jul 28, 2015 at 12:02 PM, Schlottke-Lakemper, Michael <m.schlottke-lakemper at aia.rwth-aachen.de<mailto:m.schlottke-lakemper at aia.rwth-aachen.de>> wrote:
Hi Zachary,

I tried to compile the following MWE

#include "llvm/Support/Signals.h"
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include "llvm/Support/raw_ostream.h"

int main() {
  llvm::sys::PrintStackTrace(llvm::errs());
}

using the following command:

clang++ -std=c++11 -stdlib=libc++ -I/pds/opt/llvm/include mwe.cpp -o main -lc++ -lc++abi /pds/opt/llvm/lib/libLLVMSupport.a

This throws an error about missing the pthread library, so I add “-lpthread” to the end of the above line. However, this results in many, may errors like this:

/pds/opt/llvm/lib/libLLVMSupport.a(Debug.cpp.o): In function `llvm::isCurrentDebugType(char const*)':
/pds/opt/install/llvm/llvm-20150720-r242680-src/lib/Support/Debug.cpp:(.text._ZN4llvm18isCurrentDebugTypeEPKc+0xd7): undefined reference to `std::string::compare(char const*) const'
/pds/opt/llvm/lib/libLLVMSupport.a(Triple.cpp.o): In function `llvm::Triple::getLittleEndianArchVariant() const':
/pds/opt/install/llvm/llvm-20150720-r242680-src/lib/Support/Triple.cpp:(.text._ZNK4llvm6Triple26getLittleEndianArchVariantEv+0xb): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)’
…

Any idea what I’m doing wrong?

Regards,

Michael
On 28 Jul 2015, at 08:24 , Zachary Turner <zturner at google.com<mailto:zturner at google.com>> wrote:

#include "llvm/Support/Process.h"  // I think it's in process.h, going from memory here.

void foo()
{
  llvm::sys::printStackTrace(llvm::outs);  // print to stdout
}

If you want to write it to a std::string instead you can use an llvm::raw_string_ostream.

If you need more help I can do so tomorrow or Wednesday when I'm back in the office.  The above should work across multiple platforms though (Windows, Mac, Linux) and be fully symbolized (if your program is built with debug information)

On Mon, Jul 27, 2015 at 11:14 PM Schlottke-Lakemper, Michael <m.schlottke-lakemper at aia.rwth-aachen.de<mailto:m.schlottke-lakemper at aia.rwth-aachen.de>> wrote:
That would work for me too - I just did not know that there is such a capability in LLVM itself. I believe I found the printStackTrace method to be in libLLVMSupport.a. Would you happen to know what I have to do (or where to find more help) to make use of it?

Michael

PS: Maybe this is getting too OT; if yes, please let me know.
________________________________________
From: Zachary Turner [zturner at google.com<mailto:zturner at google.com>]
Sent: Tuesday, July 28, 2015 7:13 AM
To: Schlottke-Lakemper, Michael; lldb-dev at cs.uiuc.edu<mailto:lldb-dev at cs.uiuc.edu>
Subject: Re: [lldb-dev] Use lldb.so to create stack trace

Instead of linking lldb.so, which is basically an entire debugger, maybe you could just link llvm?  I don't remember which library has the stack trace function in llvm, but the function I believe is called llvm::sys::printStackTrace().  This will give you a much smaller overhead than bringing in all of lldb unnecessarily.

On Mon, Jul 27, 2015 at 10:12 PM Schlottke-Lakemper, Michael <m.schlottke-lakemper at aia.rwth-aachen.de<mailto:m.schlottke-lakemper at aia.rwth-aachen.de><mailto:m.schlottke-lakemper at aia.rwth-aachen.de<mailto:m.schlottke-lakemper at aia.rwth-aachen.de>>> wrote:
Hi folks,

We are looking for a way to use lldb.so to print out a stack trace programmatically. In our scientific simulation tool (written in C++) ,  we use a custom terminate function where we are already able to print stack traces in case of an abnormal abort, which uses some gcc-specific magic.

My idea is to link our tool to lldb.so when compiling for debugging and to use the library to print a stack trace programmatically, including demangled names and correct line numbers. However, I don't really know how to start thus I am wondering

- has someone here done or seen something like this before?
- is there a tutorial for linking to lldb.so and making use of it through C++?
- would this also work when compiling with other compilers than clang?

Any help or pointers to relevant projects/documentation etc is greatly appreciated!

Regards,

Michael

--
Michael Schlottke-Lakemper

SimLab Highly Scalable Fluids & Solids Engineering
Jülich Aachen Research Alliance (JARA-HPC)
RWTH Aachen University

Wüllnerstraße 5a
52062 Aachen
Germany

Phone: +49 (241) 80 95188<tel:%2B49%20%28241%29%2080%2095188>
Fax: +49 (241) 80 92257<tel:%2B49%20%28241%29%2080%2092257>
Mail: m.schlottke-lakemper at aia.rwth-aachen.de<mailto:m.schlottke-lakemper at aia.rwth-aachen.de><mailto:m.schlottke-lakemper at aia.rwth-aachen.de<mailto:m.schlottke-lakemper at aia.rwth-aachen.de>>
Web: http://www.jara.org/jara-hpc<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.jara.org_jara-2Dhpc&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=DDUMf06MYELAe1Nlv7KChiwJLLHbYha4jtK_AOiWqwQ&m=e5biF0KrgwLV9z9kT0mgwqOW3D8g4dmTLWxt_TkPFHA&s=Rn4LbHZiRQmZnGqtm7LWoWd7UuqIIGKIzP_YMNsmDo8&e=>

_______________________________________________
lldb-dev mailing list
lldb-dev at cs.uiuc.edu<mailto:lldb-dev at cs.uiuc.edu><mailto:lldb-dev at cs.uiuc.edu<mailto:lldb-dev at cs.uiuc.edu>>
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev


_______________________________________________
lldb-dev mailing list
lldb-dev at cs.uiuc.edu<mailto:lldb-dev at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20150729/a1822951/attachment.html>


More information about the lldb-dev mailing list