debugger icon indicating copy to clipboard operation
debugger copied to clipboard

Instruciton pointer is off-by-one when using LLDB adapter to connect to gdbserver running on Linux

Open xusheng6 opened this issue 1 year ago • 0 comments

Setup:

  1. Use the helloworld file in our test binaries: https://github.com/Vector35/debugger/blob/dev/test/binaries/Linux-x86_64/helloworld
  2. Run gdbserver 0.0.0.0:31337 -- ./helloworld on Linux
    • The gdbserver is the one that comes with Ubuntu 22.04 -- GNU gdbserver (Ubuntu 12.1-0ubuntu1~22.04) 12.1
  3. In Binary Ninja, connect to it via Menu -> Debugger -> Connect to remote process
  4. In the dialog that pops up, select gdb-server (which is the default), and put the IP address of the Linux system in it. Set the port to 31337
  5. Once connected, resume the target to let the program run to its entry point
  6. See the rip is reported as 0x555555555081 while the entry point is at 0x555555555080

Screenshot 2024-01-30 at 2 04 16 PM

This off-by-one will cause weird crashes when single stepping in the code, which users have been complaining but I am unable to reproduce -- because this is highly reliant on the specific instruction that is being executed. Now that I know the cause of this and become patient, I notice if I get to the main function in the helloworld, and single step a few times, the crash will happen -- the target will be killed due to a sigsegv.

This is probably an LLDB bug, since I can reproduce it using the lldb command line directly. Also, we all know debuggers do need to subtract one from the instruction pointer when a int3 breakpoint is hit -- I feel like LLDB and gdbserver do not reach an agreement on who should do it

xusheng6 avatar Jan 30 '24 06:01 xusheng6