<div dir="ltr">#include "llvm/Support/Process.h" // I think it's in process.h, going from memory here.<div><br></div><div>void foo()</div><div>{</div><div> llvm::sys::printStackTrace(llvm::outs); // print to stdout</div><div><span style="line-height:1.5;font-size:13.1999998092651px">}</span><br></div><div><span style="line-height:1.5;font-size:13.1999998092651px"><br></span></div><div><span style="line-height:1.5;font-size:13.1999998092651px">If you want to write it to a std::string instead you can use an llvm::raw_string_ostream.</span></div><div><span style="line-height:1.5;font-size:13.1999998092651px"><br></span></div><div><span style="line-height:1.5;font-size:13.1999998092651px">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)</span></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 27, 2015 at 11:14 PM Schlottke-Lakemper, Michael <<a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de">m.schlottke-lakemper@aia.rwth-aachen.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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?<br>
<br>
Michael<br>
<br>
PS: Maybe this is getting too OT; if yes, please let me know.<br>
________________________________________<br>
From: Zachary Turner [<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>]<br>
Sent: Tuesday, July 28, 2015 7:13 AM<br>
To: Schlottke-Lakemper, Michael; <a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a><br>
Subject: Re: [lldb-dev] Use lldb.so to create stack trace<br>
<br>
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.<br>
<br>
On Mon, Jul 27, 2015 at 10:12 PM Schlottke-Lakemper, Michael <<a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" target="_blank">m.schlottke-lakemper@aia.rwth-aachen.de</a><mailto:<a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" target="_blank">m.schlottke-lakemper@aia.rwth-aachen.de</a>>> wrote:<br>
Hi folks,<br>
<br>
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.<br>
<br>
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<br>
<br>
- has someone here done or seen something like this before?<br>
- is there a tutorial for linking to lldb.so and making use of it through C++?<br>
- would this also work when compiling with other compilers than clang?<br>
<br>
Any help or pointers to relevant projects/documentation etc is greatly appreciated!<br>
<br>
Regards,<br>
<br>
Michael<br>
<br>
--<br>
Michael Schlottke-Lakemper<br>
<br>
SimLab Highly Scalable Fluids & Solids Engineering<br>
Jülich Aachen Research Alliance (JARA-HPC)<br>
RWTH Aachen University<br>
<br>
Wüllnerstraße 5a<br>
52062 Aachen<br>
Germany<br>
<br>
Phone: +49 (241) 80 95188<br>
Fax: +49 (241) 80 92257<br>
Mail: <a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" target="_blank">m.schlottke-lakemper@aia.rwth-aachen.de</a><mailto:<a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" target="_blank">m.schlottke-lakemper@aia.rwth-aachen.de</a>><br>
Web: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.jara.org_jara-2Dhpc&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=DDUMf06MYELAe1Nlv7KChiwJLLHbYha4jtK_AOiWqwQ&m=PaXYNlvb0koMPUsuM5RfvDyF52FpfWJsctZSEVrgbGg&s=_-2iDtI6H-ovTpN0EfpVFfRmtOk5zFTA2YX5hLuIhPM&e=" rel="noreferrer" target="_blank">http://www.jara.org/jara-hpc</a><br>
<br>
_______________________________________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a><mailto:<a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a>><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
</blockquote></div>