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

David Jones djones at xtreme-eda.com
Tue Jul 28 10:05:45 PDT 2015


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> 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> 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> 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]
>> Sent: Tuesday, July 28, 2015 7:13 AM
>> To: Schlottke-Lakemper, Michael; 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>> 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
>> Fax: +49 (241) 80 92257
>> Mail: 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>
>> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
>>
>
>
> _______________________________________________
> lldb-dev mailing list
> 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/20150728/fff677da/attachment.html>


More information about the lldb-dev mailing list