Vector35 / debugger

Binary Ninja debugger
Other
199 stars 12 forks source link

Error when connecting to local lldb server and trying to launch a process. #297

Closed 0cyn closed 1 year ago

0cyn commented 1 year ago

OS: macOS 12.4 (x86_64) SIP: Enabled

It's highly likely this can be reproduced for actual remote debugging sessions.

Program:

// clang wait.c -o wait
#include <pthread.h> 
int main(void) { 
pthread_cond_t cond = PTHREAD_COND_INITIALIZER; 
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; 
pthread_mutex_lock(&lock); 
pthread_cond_wait(&cond, &lock); // wait forever here.
pthread_mutex_unlock(&lock); 
return 0; }

Repro:

  1. Open a terminal and run 'wait'. It will wait indefinitely.
  2. Open built wait binary in BinaryNinja
  3. Terminal: sudo /Applications/Binary\ Ninja.app/Contents/MacOS/plugins/lldb/bin/debugserver localhost:8000
  4. BinaryNinja > Debugger > Connect to Debug Server > Enter 127.0.0.1 & 8000
  5. Click "Launch" image
0cyn commented 1 year ago

Explicitly specifying sudo /Applications/Binary\ Ninja.app/Contents/MacOS/plugins/lldb/bin/debugserver localhost:8000 --attach="wait" allows connecting with "Attach to remote process".

xusheng6 commented 1 year ago

Closed by error

xusheng6 commented 1 year ago

This used to work and this is actually the primary workflow that I used to test remote debugging. Seems like a regression

xusheng6 commented 1 year ago

This is NOT how the remote debugging is expected to work. You should be launching the lldb-server using path/to/lldb-server p --server --listen 0.0.0.0:31337. Then connect from within BN and it should work. Alternatively, you can use debugserver like ./debugserver 0.0.0.0:31337 /path/to/helloworld, but you MUST supply an executable path, or, as you have figured out, specify --attach to inform the debugsever to connect to a process. Simply launching the debugserver without supplying an executable path or attach information does not work. I guess this probably would not work if you cannot using the lldb command line as well.

Please see remote debugging documentation: https://dev-docs.binary.ninja/guide/remote-debugging.html#macos_1