<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hi Zachary,
<div class=""><br class="">
</div>
<div class="">I tried to compile the following MWE</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">#include "llvm/Support/Signals.h"</div>
<div class="">#define __STDC_LIMIT_MACROS</div>
<div class="">#define __STDC_CONSTANT_MACROS</div>
<div class="">#include "llvm/Support/raw_ostream.h"</div>
<div class=""><br class="">
</div>
<div class="">int main() {</div>
<div class="">  llvm::sys::PrintStackTrace(llvm::errs());</div>
<div class="">}</div>
<div class=""><br class="">
</div>
<div class="">using the following command:</div>
<div class=""><br class="">
</div>
<div class="">clang++ -std=c++11 -stdlib=libc++ -I/pds/opt/llvm/include mwe.cpp -o main -lc++ -lc++abi /pds/opt/llvm/lib/libLLVMSupport.a</div>
<div class=""><br class="">
</div>
<div class="">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:</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">/pds/opt/llvm/lib/libLLVMSupport.a(Debug.cpp.o): In function `llvm::isCurrentDebugType(char const*)':</div>
<div class="">/pds/opt/install/llvm/llvm-20150720-r242680-src/lib/Support/Debug.cpp:(.text._ZN4llvm18isCurrentDebugTypeEPKc+0xd7): undefined reference to `std::string::compare(char const*) const'</div>
</div>
<div class="">
<div class="">/pds/opt/llvm/lib/libLLVMSupport.a(Triple.cpp.o): In function `llvm::Triple::getLittleEndianArchVariant() const':</div>
<div class="">/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&)’</div>
</div>
<div class="">…</div>
<div class=""><br class="">
</div>
<div class="">Any idea what I’m doing wrong?</div>
<div class=""><br class="">
</div>
<div class="">Regards,</div>
<div class=""><br class="">
</div>
<div class="">Michael</div>
<div>
<blockquote type="cite" class="">
<div class="">On 28 Jul 2015, at 08:24 , Zachary Turner <<a href="mailto:zturner@google.com" class="">zturner@google.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">#include "llvm/Support/Process.h"  // I think it's in process.h, going from memory here.
<div class=""><br class="">
</div>
<div class="">void foo()</div>
<div class="">{</div>
<div class="">  llvm::sys::printStackTrace(llvm::outs);  // print to stdout</div>
<div class=""><span style="line-height:1.5;font-size:13.1999998092651px" class="">}</span><br class="">
</div>
<div class=""><span style="line-height:1.5;font-size:13.1999998092651px" class=""><br class="">
</span></div>
<div class=""><span style="line-height:1.5;font-size:13.1999998092651px" class="">If you want to write it to a std::string instead you can use an llvm::raw_string_ostream.</span></div>
<div class=""><span style="line-height:1.5;font-size:13.1999998092651px" class=""><br class="">
</span></div>
<div class=""><span style="line-height:1.5;font-size:13.1999998092651px" class="">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 class="">
<div class="gmail_quote">
<div dir="ltr" class="">On Mon, Jul 27, 2015 at 11:14 PM Schlottke-Lakemper, Michael <<a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" class="">m.schlottke-lakemper@aia.rwth-aachen.de</a>> wrote:<br class="">
</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 class="">
<br class="">
Michael<br class="">
<br class="">
PS: Maybe this is getting too OT; if yes, please let me know.<br class="">
________________________________________<br class="">
From: Zachary Turner [<a href="mailto:zturner@google.com" target="_blank" class="">zturner@google.com</a>]<br class="">
Sent: Tuesday, July 28, 2015 7:13 AM<br class="">
To: Schlottke-Lakemper, Michael; <a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank" class="">
lldb-dev@cs.uiuc.edu</a><br class="">
Subject: Re: [lldb-dev] Use lldb.so to create stack trace<br class="">
<br class="">
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 class="">
<br class="">
On Mon, Jul 27, 2015 at 10:12 PM Schlottke-Lakemper, Michael <<a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" target="_blank" class="">m.schlottke-lakemper@aia.rwth-aachen.de</a><mailto:<a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" target="_blank" class="">m.schlottke-lakemper@aia.rwth-aachen.de</a>>>
 wrote:<br class="">
Hi folks,<br class="">
<br class="">
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 class="">
<br class="">
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 class="">
<br class="">
- has someone here done or seen something like this before?<br class="">
- is there a tutorial for linking to lldb.so and making use of it through C++?<br class="">
- would this also work when compiling with other compilers than clang?<br class="">
<br class="">
Any help or pointers to relevant projects/documentation etc is greatly appreciated!<br class="">
<br class="">
Regards,<br class="">
<br class="">
Michael<br class="">
<br class="">
--<br class="">
Michael Schlottke-Lakemper<br class="">
<br class="">
SimLab Highly Scalable Fluids & Solids Engineering<br class="">
Jülich Aachen Research Alliance (JARA-HPC)<br class="">
RWTH Aachen University<br class="">
<br class="">
Wüllnerstraße 5a<br class="">
52062 Aachen<br class="">
Germany<br class="">
<br class="">
Phone: +49 (241) 80 95188<br class="">
Fax: +49 (241) 80 92257<br class="">
Mail: <a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" target="_blank" class="">
m.schlottke-lakemper@aia.rwth-aachen.de</a><mailto:<a href="mailto:m.schlottke-lakemper@aia.rwth-aachen.de" target="_blank" class="">m.schlottke-lakemper@aia.rwth-aachen.de</a>><br class="">
Web: <a href="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=" rel="noreferrer" target="_blank" class="">
http://www.jara.org/jara-hpc</a><br class="">
<br class="">
_______________________________________________<br class="">
lldb-dev mailing list<br class="">
<a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank" class="">lldb-dev@cs.uiuc.edu</a><mailto:<a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank" class="">lldb-dev@cs.uiuc.edu</a>><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br class="">
</blockquote>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>