[Lldb-commits] [PATCH] Move full initialization to lldb/API

Zachary Turner zturner at google.com
Thu Mar 26 15:43:00 PDT 2015


So the way I had to fix this was to change the semantics of Initialization and Termination slightly.  I wanted to hold off on doing this until after this went in, but it seems there's no way to get around doing it now.

Basically, the original problem was this:

When running lldb the executable, we call SBDebugger::Initialize() and SBDebugger::Terminate().  Later, when ScriptInterpreterPython is initialized, it does an "import lldb", which implicitly calls SBDebugger::Initialize() *again*, which increments the refcount again.  But there's only ever that one call to SBDebugger::Terminate -- the one we write explicitly.  To account for this we had this hack where we decremented the refcount after the import statement if the import increased the refcount.

What this hack was really doing was saying "if we are running inside of lldb.exe, decrement the refcount after this import statement, so that at the end of the program, SBDebugger::Terminate() actually causes a clean shutdown.  If we are running inside of python, leave the refcount alone, because there's only a single SBDebugger::Initialize() anyway -- the one that implicitly happens when you import -- so the atexit SBDebugger::Terminate will work".

To fix this in what I believe is the "correct" way, we simply kill the notion of a refcount entirely.  It's either initialized or it's not.  You can call Initialize() as many times as you want, and only the first call ever does anything.  The rest of the calls just exit.  And the first time you call Terminate() it really terminates.

This matches both the python usage pattern as well as the lldb.exe usage pattern.  In the former, SBDebugger::Initialize() is called twice, but the second is a no-op, and the atexit handler to call SBDebugger::Terminate does the right thing.  In the latter, there's only a single SBDebugger::Initialize and terminate, so everything works fine.

This also satisfies Greg's requirement that "import lldb" should be all you need to get up and running, since the SBDebugger.Initialize() is still there.

A side benefit of this change is that if someone accidentally calls SBDebugger.Initialize() from python, with this patch everything will still work.  Prior to this patch, that would have raised the refcount to 2, and the single SBDebugger.Terminate() call we have in the atexit handler would only drop it to 1.


http://reviews.llvm.org/D8462

Files:
  include/lldb/API/SystemInitializerFull.h
  include/lldb/Core/Debugger.h
  include/lldb/Initialization/InitializeLLDB.h
  include/lldb/Initialization/SystemInitializer.h
  include/lldb/Initialization/SystemInitializerCommon.h
  include/lldb/Initialization/SystemLifetimeManager.h
  include/lldb/Interpreter/ScriptInterpreter.h
  include/lldb/Interpreter/ScriptInterpreterPython.h
  lldb.xcodeproj/project.pbxproj
  source/API/CMakeLists.txt
  source/API/SBCommandInterpreter.cpp
  source/API/SBDebugger.cpp
  source/API/SystemInitializerFull.cpp
  source/Core/Debugger.cpp
  source/Initialization/CMakeLists.txt
  source/Initialization/InitializeLLDB.cpp
  source/Initialization/SystemInitializer.cpp
  source/Initialization/SystemInitializerCommon.cpp
  source/Initialization/SystemLifetimeManager.cpp
  source/Interpreter/ScriptInterpreter.cpp
  source/Interpreter/ScriptInterpreterPython.cpp
  tools/lldb-server/lldb-server.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8462.22765.patch
Type: text/x-patch
Size: 103303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150326/3848afec/attachment.bin>


More information about the lldb-commits mailing list