SBListener not using a shared_ptr internally? (Update: Segfault after r262863)

Hey again,

I've noticing segfaults after r262863
Could you try reproducing this bug with this code please?

int main() {
  using namespace lldb;


  SBDebugger debugger = SBDebugger::Create(true);
  if(!debugger.IsValid()) {
    return 1;

  SBTarget target = debugger.CreateTarget("/home/dev/helloWorld/main");
  if(!target.IsValid()) {
    return 1;

  const char* args = { "/home/dev/helloWorld/main", 0 };
  const char* env = { 0 };

  SBLaunchInfo launch_info(args);
  launch_info.SetEnvironmentEntries(env, true);

  SBError error;
  SBProcess process = target.Launch(launch_info, error);

  return 0;

I tried to build lldb with and without the above commit and it turns
out that the revision is causing the segfault when simply running that
code (When it's exiting).

This is the backtrace:

#0 0x0000555555b03b00 in ?? ()
#1 0x00007ffff71be1aa in
lldb_private::Broadcaster::BroadcasterImpl::RestoreBroadcaster() ()
from /usr/lib/
#2 0x00007ffff748b674 in
const*, unsigned long, StringExtractorGDBRemote&, bool) () from
#3 0x00007ffff748e89d in
bool, unsigned long, unsigned int) () from /usr/lib/
#4 0x00007ffff746fdab in
() from /usr/lib/
#5 0x00007ffff733938b in std::_Function_handler<void
const&, lldb_private::BreakpointSite*&&) () from
#6 0x00007ffff716ae4f in
(lldb_private::BreakpointSite*)> const&) () from
#7 0x00007ffff733ba9f in
lldb_private::Process::DisableAllBreakpointSites() () from
#8 0x00007ffff734a58c in lldb_private::Process::Destroy(bool) () from
#9 0x00007ffff734aa2d in lldb_private::Process::Finalize() () from
#10 0x00007ffff71d3fe0 in lldb_private::Debugger::Clear() () from
#11 0x00007ffff71d97cf in lldb_private::Debugger::~Debugger() () from
#12 0x00007ffff71da0c8 in
(__gnu_cxx::_Lock_policy)2>::_M_dispose() () from
#13 0x00007ffff71cdceb in
std::allocator<std::shared_ptr<lldb_private::Debugger> > >::~vector()
() from /usr/lib/
#14 0x00007ffff60d9c38 in __run_exit_handlers () from /usr/lib/
#15 0x00007ffff60d9c85 in exit () from /usr/lib/
#16 0x00007ffff60c4717 in __libc_start_main () from /usr/lib/
#17 0x0000555555554f69 in _start ()

lldb doesn't currently work if you leave the process of cleaning up to the C++ destructor chain. You need to call Debugger::Destroy on your way out.

I think there's a bunch more cleanup than just the broadcaster/listener stuff before we'll do this right.


Ah, Thanks adding Debugger::Destroy at the end of my code made the
segfaults disappear.
Also as far as I understood the lldb code (Core/Debugger.cpp) it
should also be possible to call SBDebugger::Terminate() for "destroy"
all instances of lldb related objects.

Yes, that should work too. The thing that doesn't work is to just let the C++ destructor chain tear down the debuggers you've made. It should be possible to make that work, but nobody's had time to make that happen, and given you can avoid the crashes if you exit cleanly, it hasn't been a terribly high priority.