[Lldb-commits] [PATCH] Move full initialization to lldb/API
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 103303 bytes
Desc: not available
More information about the lldb-commits