[Lldb-commits] [lldb] r231310 - Introduce lldbassert(x)
Zachary Turner
zturner at google.com
Wed Mar 4 15:13:06 PST 2015
Doesn't LLVM already have this functionality built in? How is this
different than writing:
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc_, argv_);
in main?
On Wed, Mar 4, 2015 at 3:06 PM Enrico Granata <egranata at apple.com> wrote:
> Author: enrico
> Date: Wed Mar 4 16:59:20 2015
> New Revision: 231310
>
> URL: http://llvm.org/viewvc/llvm-project?rev=231310&view=rev
> Log:
> Introduce lldbassert(x)
>
> We would like it if LLDB never crashed, especially if we never caused LLDB
> to crash
> On the other hand, having assertions can sometimes be useful
>
> lldbassert(x) is the best of both worlds:
> - in debug builds, it turns into a regular assert, which is fine because
> we don't mind debug LLDB to crash on development machines
> - 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
>
>
> Added:
> lldb/trunk/include/lldb/Utility/LLDBAssert.h
> lldb/trunk/source/Utility/LLDBAssert.cpp
> Modified:
> lldb/trunk/lldb.xcodeproj/project.pbxproj
>
> Added: lldb/trunk/include/lldb/Utility/LLDBAssert.h
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/
> lldb/Utility/LLDBAssert.h?rev=231310&view=auto
> ============================================================
> ==================
> --- lldb/trunk/include/lldb/Utility/LLDBAssert.h (added)
> +++ lldb/trunk/include/lldb/Utility/LLDBAssert.h Wed Mar 4 16:59:20 2015
> @@ -0,0 +1,30 @@
> +//===----------------- LLDBAssert.h --------------------------------*-
> C++ -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===------------------------------------------------------
> ----------------===//
> +
> +#ifndef utility_LLDBAssert_h_
> +#define utility_LLDBAssert_h_
> +
> +#include <assert.h>
> +
> +#ifdef LLDB_CONFIGURATION_DEBUG
> +#define lldbassert(x) assert(x)
> +#else
> +#define lldbassert(x) lldb_private::lldb_assert(x, #x, __FUNCTION__,
> __FILE__, __LINE__)
> +#endif
> +
> +namespace lldb_private {
> + void
> + lldb_assert (int expression,
> + const char* expr_text,
> + const char* func,
> + const char* file,
> + unsigned int line);
> +}
> +
> +#endif // utility_LLDBAssert_h_
>
> Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.
> xcodeproj/project.pbxproj?rev=231310&r1=231309&r2=231310&view=diff
> ============================================================
> ==================
> --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
> +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Wed Mar 4 16:59:20 2015
> @@ -770,6 +770,7 @@
> 942AFF0719F84C02007B43B4 /* LibCxxInitializerList.cpp in
> Sources */ = {isa = PBXBuildFile; fileRef = 942AFF0619F84C02007B43B4 /*
> LibCxxInitializerList.cpp */; };
> 94380B8219940B0A00BFE4A8 /* StringLexer.cpp in Sources */
> = {isa = PBXBuildFile; fileRef = 94380B8119940B0A00BFE4A8 /*
> StringLexer.cpp */; };
> 9439FB1A19EF140C006FD6A4 /* NSIndexPath.cpp in Sources */
> = {isa = PBXBuildFile; fileRef = 9439FB1919EF140C006FD6A4 /*
> NSIndexPath.cpp */; };
> + 943BDEFE1AA7B2F800789CE8 /* LLDBAssert.cpp in Sources */ =
> {isa = PBXBuildFile; fileRef = 943BDEFD1AA7B2F800789CE8 /* LLDBAssert.cpp
> */; };
> 944372DC171F6B4300E57C32 /* RegisterContextDummy.cpp in
> Sources */ = {isa = PBXBuildFile; fileRef = 944372DA171F6B4300E57C32 /*
> RegisterContextDummy.cpp */; };
> 944372DD171F6B4300E57C32 /* RegisterContextDummy.h in
> Headers */ = {isa = PBXBuildFile; fileRef = 944372DB171F6B4300E57C32 /*
> RegisterContextDummy.h */; };
> 9443B122140C18C40013457C /* SBData.cpp in Sources */ =
> {isa = PBXBuildFile; fileRef = 9443B121140C18C10013457C /* SBData.cpp */; };
> @@ -2397,6 +2398,8 @@
> 94380B8019940B0300BFE4A8 /* StringLexer.h */ = {isa =
> PBXFileReference; lastKnownFileType = sourcecode.c.h; name = StringLexer.h;
> path = include/lldb/Utility/StringLexer.h; sourceTree = "<group>"; };
> 94380B8119940B0A00BFE4A8 /* StringLexer.cpp */ = {isa =
> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp;
> name = StringLexer.cpp; path = source/Utility/StringLexer.cpp; sourceTree
> = "<group>"; };
> 9439FB1919EF140C006FD6A4 /* NSIndexPath.cpp */ = {isa =
> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp;
> name = NSIndexPath.cpp; path = source/DataFormatters/NSIndexPath.cpp;
> sourceTree = "<group>"; };
> + 943BDEFC1AA7B2DE00789CE8 /* LLDBAssert.h */ = {isa =
> PBXFileReference; lastKnownFileType = sourcecode.c.h; name = LLDBAssert.h;
> path = include/lldb/Utility/LLDBAssert.h; sourceTree = "<group>"; };
> + 943BDEFD1AA7B2F800789CE8 /* LLDBAssert.cpp */ = {isa =
> PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp;
> name = LLDBAssert.cpp; path = source/Utility/LLDBAssert.cpp; sourceTree =
> "<group>"; };
> 944372DA171F6B4300E57C32 /* RegisterContextDummy.cpp */ =
> {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
> sourcecode.cpp.cpp; name = RegisterContextDummy.cpp; path =
> Utility/RegisterContextDummy.cpp; sourceTree = "<group>"; };
> 944372DB171F6B4300E57C32 /* RegisterContextDummy.h */ =
> {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
> sourcecode.c.h; name = RegisterContextDummy.h; path =
> Utility/RegisterContextDummy.h; sourceTree = "<group>"; };
> 9443B120140C18A90013457C /* SBData.h */ = {isa =
> PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBData.h; path
> = include/lldb/API/SBData.h; sourceTree = "<group>"; };
> @@ -3455,6 +3458,8 @@
> 4C73152119B7D71700F865A4 /* Iterable.h */,
> 942829541A89614000521B30 /* JSON.h */,
> 942829551A89614C00521B30 /* JSON.cpp */,
> + 943BDEFC1AA7B2DE00789CE8 /* LLDBAssert.h
> */,
> + 943BDEFD1AA7B2F800789CE8 /* LLDBAssert.cpp
> */,
> 26D1804416CEE12500EDFB5B /* KQueue.h */,
> 26D1803C16CEBFD300EDFB5B /* KQueue.cpp */,
> 94031A9F13CF5B3D00DCFF3C /*
> PriorityPointerPair.h */,
> @@ -5946,6 +5951,7 @@
> 2689006413353E0E00698AC0 /*
> ClangUserExpression.cpp in Sources */,
> 4C3ADCD61810D88B00357218 /*
> BreakpointResolverFileRegex.cpp in Sources */,
> 2689006513353E0E00698AC0 /*
> ClangUtilityFunction.cpp in Sources */,
> + 943BDEFE1AA7B2F800789CE8 /* LLDBAssert.cpp
> in Sources */,
> 26474CB418D0CB180073DEBA /*
> RegisterContextLinux_x86_64.cpp in Sources */,
> 2689006613353E0E00698AC0 /*
> DWARFExpression.cpp in Sources */,
> 2689006713353E0E00698AC0 /* ASTDumper.cpp
> in Sources */,
>
> Added: lldb/trunk/source/Utility/LLDBAssert.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/
> Utility/LLDBAssert.cpp?rev=231310&view=auto
> ============================================================
> ==================
> --- lldb/trunk/source/Utility/LLDBAssert.cpp (added)
> +++ lldb/trunk/source/Utility/LLDBAssert.cpp Wed Mar 4 16:59:20 2015
> @@ -0,0 +1,38 @@
> +//===--------------------- LLDBAssert.cpp --------------------------*-
> C++ -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===------------------------------------------------------
> ----------------===//
> +
> +#include "lldb/Utility/LLDBAssert.h"
> +#include "lldb/Core/StreamString.h"
> +#include "lldb/Host/Host.h"
> +
> +using namespace lldb_private;
> +
> +void
> +lldb_private::lldb_assert (int expression,
> + const char* expr_text,
> + const char* func,
> + const char* file,
> + unsigned int line)
> +{
> + if (expression)
> + ;
> + else
> + {
> + StreamString stream;
> + stream.Printf("Assertion failed: (%s), function %s, file %s, line
> %u\n",
> + expr_text,
> + func,
> + file,
> + line);
> + stream.Printf("backtrace leading to the failure:\n");
> + Host::Backtrace(stream, 1000);
> + stream.Printf("please file a bug report against lldb reporting
> this failure log, and as many details as possible\n");
> + printf("%s\n", stream.GetData());
> + }
> +}
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150304/682b9f07/attachment.html>
More information about the lldb-commits
mailing list