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

Zachary Turner zturner at google.com
Mon Jul 27 23:24:36 PDT 2015


#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
>
> _______________________________________________
> 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/20150728/3e152bf9/attachment.html>


More information about the lldb-dev mailing list