[Bug 27639] New: LLDB python API segfaults during debugger teardown

Bug ID 27639
Summary LLDB python API segfaults during debugger teardown
Product lldb
Version unspecified
Hardware PC
OS All
Status NEW
Severity normal
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter progers7@gatech.edu
CC llvm-bugs@lists.llvm.org
Classification Unclassified

I'm hitting a segfault with a very simple python script using the lldb api:

Python script:
---------8<---------
import lldb
if __name__ == "__main__":
    debugger = lldb.SBDebugger.Create()
    target = debugger.CreateTarget("helloworld")
---------8<---------

helloworld.cpp is just a blank executable compiled with "g++ helloworld.cpp -o
helloworld".

Crash details:
"Python quit unexpectedly while using the _lldb.so plugin."
Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000008
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   org.python.python                 0x000000010f6a9fce 0x10f609000 + 659406
1   org.python.python                 0x000000010f6aa481 PyGILState_Ensure + 55
2   _lldb.so                          0x0000000112da937a
lldb_private::ScriptInterpreterPython::Locker::DoAcquireLock() + 28
3   _lldb.so                          0x0000000112daea6b
lldb_private::ScriptInterpreterPython::Clear() + 37
4   _lldb.so                          0x0000000112ae9510
lldb_private::Debugger::Clear() + 266
5   _lldb.so                          0x0000000112aea8ec
lldb_private::Debugger::~Debugger() + 28
6   _lldb.so                          0x0000000112aeac0e
lldb_private::Debugger::~Debugger() + 14
7   libc++.1.dylib                    0x00007fff95ee5cb8
std::__1::__shared_weak_count::__release_shared() + 44
8   _lldb.so                          0x0000000110b2b6cf
std::__1::__vector_base<std::__1::shared_ptr<lldb_private::TypeImpl>,
std::__1::allocator<std::__1::shared_ptr<lldb_private::TypeImpl> >
>::~__vector_base() + 49
9   libsystem_c.dylib                 0x00007fff91e0746b __cxa_finalize_ranges
+ 345
10  libsystem_c.dylib                 0x00007fff91e0776f exit + 55
11  libdyld.dylib                     0x00007fff8fd2f5b4 start + 8

Python version: 2.7.10 (2.7.10)
LLDB version: 350.0.21.9
OS: Mac OS X 10.11.4 (15E65)

This crash can be suppressed by manually cleaning up the objects:
debugger.DeleteTarget(target)
debugger.Terminate()

I've searched around and didn't find any other reports of this on OSX. Possibly
related to rdar://problem/24580184 / dc5ef2da510f3adba99cd8b2fe18c2e6d417227d ?