[lldb-dev] [PATCH] For SBDebugger::Create assertion failure
Matthew Gardiner
mg11 at csr.com
Fri Oct 3 05:46:23 PDT 2014
Hi folks,
Whilst starting to play with the lldb C++ API, I've noticed that this
simple little program causes an assertion failure (and hence a core
dump).
#include <cstdio>
#include "lldb/API/LLDB.h"
int main()
{
fprintf(stderr, "lldb-app\n");
// lldb::SBDebugger::Initialize();
lldb::SBDebugger dbgr = lldb::SBDebugger::Create(true);
fprintf(stderr, "SBDebugger::Create!\n");
return 0;
}
As guessed, by uncommenting out the Initialize call, the assertion is
satisfied by Create and friends, and the code runs to completion.
To me, this is bad on 2 counts:
1. If Create depends on Initialize then Initialize should be called
internally.
2. From a public API perspective, even if Create and Initialize need to
be called separately, a crash (failed assert) seems a little harsh.
Shouldn't an error return (or exception throw) be used to communicate
the user's mistake in this case?
I did some digging into SBDebugger::Initialize and it seems safe for
this to be called internally by Create.
So I'm proposing that I fix this issue with following patch:
Index: source/API/SBDebugger.cpp
===================================================================
--- source/API/SBDebugger.cpp (revision 218974)
+++ source/API/SBDebugger.cpp (working copy)
@@ -159,6 +159,8 @@
{
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+ Initialize();
+
SBDebugger debugger;
// Currently we have issues if this function is called
simultaneously on two different
@@ -210,6 +212,8 @@
sstr.GetData());
}
+ Terminate();
+
Debugger::Destroy (debugger.m_opaque_sp);
if (debugger.m_opaque_sp.get() != NULL)
Please shout out if you don't want me to.
thanks
Matt
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc.
New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
More information about the lldb-dev
mailing list