http://anadoxin.org/blog

"Lost connection" when debugging with lldb on Mavericks

Fri, 22 January 2016 :: #macos :: #lldb

Lost connection on simple debugging session

Sometimes you just have to use older system to develop some things. Not because you want to, but simply because you have to.

When trying to use lldb on Mavericks I had a following problem:

box:default$ ./binary
[log] starting binary...
[log] it works!

box:default$ lldb
(lldb) file binary
Current executable set to 'binary' (i386).
(lldb) proc launch
error: process exited with status -1 (lost connection)
(lldb)

So, after compiling my own small program, I couldn't launch it in the lldb debugger. Error code "lost connection" wasn't helping much.

It turns out the solution is easy.

$ sudo /usr/sbin/DevToolsSecurity --enable
Password:
Developer mode is now enabled.

This might happen if you'll try to use commandline development tools without ever running Xcode, I guess.

This applies also to Sierra, High Sierra, Mojave and probably Catalina as well.

But wait, there's more.

Lost connection on attaching to forked process

lldb isn't a bad debugger, but sometimes it feels like step back from gdb. For example, there's no fork follow mode? Instead of this mode, lldb allows to attach to a process when it'll be created. You need two terminals; first one with your debugged program, waiting just before fork(), and second terminal with clean and fresh lldb. Issue this command into the new lldb session, in which you'd like to debug your child process:

lldb> process attach --name <name_of_executable_of_your_process> --waitfor

It should wait for your process to fork, and it should start debugging it (remember about putting some breakpoint before that). In order to make parent process fork, just step over the fork() function call in your first lldb session. The second lldb should now react.

However, in my case, it only dumped an error: lost connection:

(lldb) process attach -n testprogram  -w
error: attach failed: lost connection

In order to fix this case or 'lost connection' error, try issuing this command:

sudo dscl . append /Groups/_developer GroupMembership <your_username>

Now, relogin with ssh or restart your terminal and try again. For me it started working flawlessly.

You can also try methods from this post if you're getting other errors, like "unable to attach".