Vector35/debugger

Update remote debugging docs on how to specify the executable path and working directory

VinceQu opened this issue · 4 comments

Version and Platform (required):

  • Binary Ninja Version: [e.g. 4.1.5036-dev]
  • OS: Windows
  • OS Version: Windows 10
  • CPU Architecture: x64

Bug Description:
Remote Linux debugging not working due to replacement of "/" with "" in paths read from "Debug Adapter Settings".

Steps To Reproduce:
Please provide all steps required to reproduce the behavior:

  1. Setup: Host (Windows 10) -> Target (Ubuntu 22.04)
  2. Launch Debugserver (gdbserver or lldb-server, it makes no difference) on linux and connect with binary ninja
  3. Set Paths in "Debug Adapter Settings" to appropriate Linux paths ("/mnt/hgfs/CTFs/...")
  4. Click "Launch (F6)"
  5. LLDB Error pops up: "LLDB Failed to create target with '\mnt\hgfs\CTFs...' does not exist" (note that all slashes were replaced with backslashes, which obviously breaks linux paths)

For reference, this issue was initially raised in the binaryninja slack channel and i was pointed to this line of code as a potential culprit: https://github.com/Vector35/debugger/blob/dev/core/debuggercontroller.cpp#L260

Expected Behavior:
I would expect the binary to launch.

Yup, it seems to be the case that I did not consider the remote operating system when I wrote that code

here is a workaround for this issue using lldb-server:

  1. Do NOT set the executable path to the one on the Linux system. Leave it to be the path on Windows. During launch, LLDB will copy the binary to the remote system, and execute it. Per my test, the binary will be copied to the working directory of the lldb-server.
  2. Set the working diretory to an appropriate path on the Linux system, or leave it empty. If you leave it unchanged, there will be an error when the lldb-server tries to chdir to the Windows directory.

With the above two changes, you should be able to at least debug it. However, we should definitely make things more straightforward.

It turns out that LLDB actually does not support directly specifying a remote path when launching the target. We must supply the path for the executable on the local machine. Will need to update docs to reflect that.

Since the lldb-server always copies the binary to the working directory, we might wish to add run a command to alter the working directory to the one specified by the user. Relevant info: https://lldb.llvm.org/use/remote.html#changing-the-platform-working-directory