<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 4, 2015, at 3:13 PM, 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="">Doesn't LLVM already have this functionality built in? How is this different than writing:<br class=""><br class=""><div class=""> llvm::sys::PrintStackTraceOnErrorSignal();</div></div></div></blockquote><div><br class=""></div><div>This one is triggered on an error signal, <b class="">and then exits</b>. I don’t want to exit.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""> llvm::PrettyStackTraceProgram X(argc_, argv_);</div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>This looks like a program-wide <b class="">crash handler</b>. I don’t want to crash.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">in main?</div></div><br class=""></div></blockquote><div><br class=""></div><div>I want this to work everywhere, not only in main.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote">On Wed, Mar 4, 2015 at 3:06 PM Enrico Granata <<a href="mailto:egranata@apple.com" class="">egranata@apple.com</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: enrico<br class="">
Date: Wed Mar 4 16:59:20 2015<br class="">
New Revision: 231310<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=231310&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-<u class=""></u>project?rev=231310&view=rev</a><br class="">
Log:<br class="">
Introduce lldbassert(x)<br class="">
<br class="">
We would like it if LLDB never crashed, especially if we never caused LLDB to crash<br class="">
On the other hand, having assertions can sometimes be useful<br class="">
<br class="">
lldbassert(x) is the best of both worlds:<br class="">
- in debug builds, it turns into a regular assert, which is fine because we don't mind debug LLDB to crash on development machines<br class="">
- in non-debug builds, it emits a message formatted just like assert(x) would, but then instead of crashing, it dumps a backtrace, suggests filing a bug, and keeps running<br class="">
<br class="">
<br class="">
Added:<br class="">
lldb/trunk/include/lldb/<u class=""></u>Utility/LLDBAssert.h<br class="">
lldb/trunk/source/Utility/<u class=""></u>LLDBAssert.cpp<br class="">
Modified:<br class="">
lldb/trunk/lldb.xcodeproj/<u class=""></u>project.pbxproj<br class="">
<br class="">
Added: lldb/trunk/include/lldb/<u class=""></u>Utility/LLDBAssert.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/LLDBAssert.h?rev=231310&view=auto" target="_blank" class="">http://llvm.org/viewvc/llvm-<u class=""></u>project/lldb/trunk/include/<u class=""></u>lldb/Utility/LLDBAssert.h?rev=<u class=""></u>231310&view=auto</a><br class="">
==============================<u class=""></u>==============================<u class=""></u>==================<br class="">
--- lldb/trunk/include/lldb/<u class=""></u>Utility/LLDBAssert.h (added)<br class="">
+++ lldb/trunk/include/lldb/<u class=""></u>Utility/LLDBAssert.h Wed Mar 4 16:59:20 2015<br class="">
@@ -0,0 +1,30 @@<br class="">
+//===----------------- LLDBAssert.h ------------------------------<u class=""></u>--*- C++ -*-===//<br class="">
+//<br class="">
+// The LLVM Compiler Infrastructure<br class="">
+//<br class="">
+// This file is distributed under the University of Illinois Open Source<br class="">
+// License. See LICENSE.TXT for details.<br class="">
+//<br class="">
+//===------------------------<u class=""></u>------------------------------<u class=""></u>----------------===//<br class="">
+<br class="">
+#ifndef utility_LLDBAssert_h_<br class="">
+#define utility_LLDBAssert_h_<br class="">
+<br class="">
+#include <assert.h><br class="">
+<br class="">
+#ifdef LLDB_CONFIGURATION_DEBUG<br class="">
+#define lldbassert(x) assert(x)<br class="">
+#else<br class="">
+#define lldbassert(x) lldb_private::lldb_assert(x, #x, __FUNCTION__, __FILE__, __LINE__)<br class="">
+#endif<br class="">
+<br class="">
+namespace lldb_private {<br class="">
+ void<br class="">
+ lldb_assert (int expression,<br class="">
+ const char* expr_text,<br class="">
+ const char* func,<br class="">
+ const char* file,<br class="">
+ unsigned int line);<br class="">
+}<br class="">
+<br class="">
+#endif // utility_LLDBAssert_h_<br class="">
<br class="">
Modified: lldb/trunk/lldb.xcodeproj/<u class=""></u>project.pbxproj<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=231310&r1=231309&r2=231310&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-<u class=""></u>project/lldb/trunk/lldb.<u class=""></u>xcodeproj/project.pbxproj?rev=<u class=""></u>231310&r1=231309&r2=231310&<u class=""></u>view=diff</a><br class="">
==============================<u class=""></u>==============================<u class=""></u>==================<br class="">
--- lldb/trunk/lldb.xcodeproj/<u class=""></u>project.pbxproj (original)<br class="">
+++ lldb/trunk/lldb.xcodeproj/<u class=""></u>project.pbxproj Wed Mar 4 16:59:20 2015<br class="">
@@ -770,6 +770,7 @@<br class="">
942AFF0719F84C02007B43B4 /* LibCxxInitializerList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 942AFF0619F84C02007B43B4 /* LibCxxInitializerList.cpp */; };<br class="">
94380B8219940B0A00BFE4A8 /* StringLexer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94380B8119940B0A00BFE4A8 /* StringLexer.cpp */; };<br class="">
9439FB1A19EF140C006FD6A4 /* NSIndexPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9439FB1919EF140C006FD6A4 /* NSIndexPath.cpp */; };<br class="">
+ 943BDEFE1AA7B2F800789CE8 /* LLDBAssert.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 943BDEFD1AA7B2F800789CE8 /* LLDBAssert.cpp */; };<br class="">
944372DC171F6B4300E57C32 /* RegisterContextDummy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */; };<br class="">
944372DD171F6B4300E57C32 /* RegisterContextDummy.h in Headers */ = {isa = PBXBuildFile; fileRef = 944372DB171F6B4300E57C32 /* RegisterContextDummy.h */; };<br class="">
9443B122140C18C40013457C /* SBData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9443B121140C18C10013457C /* SBData.cpp */; };<br class="">
@@ -2397,6 +2398,8 @@<br class="">
94380B8019940B0300BFE4A8 /* StringLexer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = StringLexer.h; path = include/lldb/Utility/<u class=""></u>StringLexer.h; sourceTree = "<group>"; };<br class="">
94380B8119940B0A00BFE4A8 /* StringLexer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringLexer.cpp; path = source/Utility/StringLexer.<u class=""></u>cpp; sourceTree = "<group>"; };<br class="">
9439FB1919EF140C006FD6A4 /* NSIndexPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NSIndexPath.cpp; path = source/DataFormatters/<u class=""></u>NSIndexPath.cpp; sourceTree = "<group>"; };<br class="">
+ 943BDEFC1AA7B2DE00789CE8 /* LLDBAssert.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = LLDBAssert.h; path = include/lldb/Utility/<u class=""></u>LLDBAssert.h; sourceTree = "<group>"; };<br class="">
+ 943BDEFD1AA7B2F800789CE8 /* LLDBAssert.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LLDBAssert.cpp; path = source/Utility/LLDBAssert.cpp; sourceTree = "<group>"; };<br class="">
944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RegisterContextDummy.cpp; path = Utility/RegisterContextDummy.<u class=""></u>cpp; sourceTree = "<group>"; };<br class="">
944372DB171F6B4300E57C32 /* RegisterContextDummy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RegisterContextDummy.h; path = Utility/RegisterContextDummy.<u class=""></u>h; sourceTree = "<group>"; };<br class="">
9443B120140C18A90013457C /* SBData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBData.h; path = include/lldb/API/SBData.h; sourceTree = "<group>"; };<br class="">
@@ -3455,6 +3458,8 @@<br class="">
4C73152119B7D71700F865A4 /* Iterable.h */,<br class="">
942829541A89614000521B30 /* JSON.h */,<br class="">
942829551A89614C00521B30 /* JSON.cpp */,<br class="">
+ 943BDEFC1AA7B2DE00789CE8 /* LLDBAssert.h */,<br class="">
+ 943BDEFD1AA7B2F800789CE8 /* LLDBAssert.cpp */,<br class="">
26D1804416CEE12500EDFB5B /* KQueue.h */,<br class="">
26D1803C16CEBFD300EDFB5B /* KQueue.cpp */,<br class="">
94031A9F13CF5B3D00DCFF3C /* PriorityPointerPair.h */,<br class="">
@@ -5946,6 +5951,7 @@<br class="">
2689006413353E0E00698AC0 /* ClangUserExpression.cpp in Sources */,<br class="">
4C3ADCD61810D88B00357218 /* BreakpointResolverFileRegex.<u class=""></u>cpp in Sources */,<br class="">
2689006513353E0E00698AC0 /* ClangUtilityFunction.cpp in Sources */,<br class="">
+ 943BDEFE1AA7B2F800789CE8 /* LLDBAssert.cpp in Sources */,<br class="">
26474CB418D0CB180073DEBA /* RegisterContextLinux_x86_64.<u class=""></u>cpp in Sources */,<br class="">
2689006613353E0E00698AC0 /* DWARFExpression.cpp in Sources */,<br class="">
2689006713353E0E00698AC0 /* ASTDumper.cpp in Sources */,<br class="">
<br class="">
Added: lldb/trunk/source/Utility/<u class=""></u>LLDBAssert.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/LLDBAssert.cpp?rev=231310&view=auto" target="_blank" class="">http://llvm.org/viewvc/llvm-<u class=""></u>project/lldb/trunk/source/<u class=""></u>Utility/LLDBAssert.cpp?rev=<u class=""></u>231310&view=auto</a><br class="">
==============================<u class=""></u>==============================<u class=""></u>==================<br class="">
--- lldb/trunk/source/Utility/<u class=""></u>LLDBAssert.cpp (added)<br class="">
+++ lldb/trunk/source/Utility/<u class=""></u>LLDBAssert.cpp Wed Mar 4 16:59:20 2015<br class="">
@@ -0,0 +1,38 @@<br class="">
+//===--------------------- LLDBAssert.cpp --------------------------*- C++ -*-===//<br class="">
+//<br class="">
+// The LLVM Compiler Infrastructure<br class="">
+//<br class="">
+// This file is distributed under the University of Illinois Open Source<br class="">
+// License. See LICENSE.TXT for details.<br class="">
+//<br class="">
+//===------------------------<u class=""></u>------------------------------<u class=""></u>----------------===//<br class="">
+<br class="">
+#include "lldb/Utility/LLDBAssert.h"<br class="">
+#include "lldb/Core/StreamString.h"<br class="">
+#include "lldb/Host/Host.h"<br class="">
+<br class="">
+using namespace lldb_private;<br class="">
+<br class="">
+void<br class="">
+lldb_private::lldb_assert (int expression,<br class="">
+ const char* expr_text,<br class="">
+ const char* func,<br class="">
+ const char* file,<br class="">
+ unsigned int line)<br class="">
+{<br class="">
+ if (expression)<br class="">
+ ;<br class="">
+ else<br class="">
+ {<br class="">
+ StreamString stream;<br class="">
+ stream.Printf("Assertion failed: (%s), function %s, file %s, line %u\n",<br class="">
+ expr_text,<br class="">
+ func,<br class="">
+ file,<br class="">
+ line);<br class="">
+ stream.Printf("backtrace leading to the failure:\n");<br class="">
+ Host::Backtrace(stream, 1000);<br class="">
+ stream.Printf("please file a bug report against lldb reporting this failure log, and as many details as possible\n");<br class="">
+ printf("%s\n", stream.GetData());<br class="">
+ }<br class="">
+}<br class="">
<br class="">
<br class="">
______________________________<u class=""></u>_________________<br class="">
lldb-commits mailing list<br class="">
<a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank" class="">lldb-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank" class="">http://lists.cs.uiuc.edu/<u class=""></u>mailman/listinfo/lldb-commits</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thanks,</div><div class=""><i class="">- Enrico</i><br class="">📩 egranata@<font color="#ff2600" class=""></font>.com ☎️ 27683</div><div class=""><br class=""></div></div></div></div></div></div><br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div>
<br class=""></body></html>