Open DavidSpickett opened 4 months ago
Friendly neighborhood GDB expert informs me that anything target remote
in gdb is treated as a remote even if the port is on the host. So it would not have this issue.
Turns out Pavel made a specific change to prevent the qemu-user platform from having this problem: https://github.com/llvm/llvm-project/commit/1dc39378c46643ec9d2544da671aca78e7c6967a
(I tested an lldb 15 which does exhibit this problem when using qemu-user)
@llvm/issue-subscribers-lldb
Author: David Spickett (DavidSpickett)
This also effects lldb 16.0 which does not include Pavel's change.
Since https://gitlab.com/qemu-project/qemu/-/commit/dc14a7a6e95571122ec2428abb355fe2c43e05c6, qemu userspace emulation returns a valid PID which is that of qemu itself. This fools lldb into loading qemu not the emulated binary, meaning any breakpoints are placed in qemu itself, if the host and emulated architecture happen to match.
Previously qemu returned a PID of 1, we'd fail to find a binary for that, and use the one the user originally chose. You can see this happening by enabling some of the logs.
This is what used to happen:
This line is supposed to print a binary name if one was found but it was not:
And after the QEMU change:
I am emulating AArch64 on an AArch64 host, so it's possible that if they're mismatched, lldb will reject the host binary and this issue won't happen.
I am guessing this from the fact that https://gitlab.com/qemu-project/qemu/-/commit/6c78de6eb6f986b2e06e95fabad62731a44aaafd fixed a follow up bug in QEMU when using lldb to debug Hexagon, but not this specific issue. So if they are doing x86 -> Hexagon debugging, the PID lookup may just be failing to find a compatible binary.
If you use the qemu-user platform this issue does not happen because it does not implement
GetProcessInfo
.I think the fundamental issue is that if you connect to a
gdb-remote
using anything that looks like a localhost address, we assume it's the host platform. Likely because this is how normal debugging works, we start alldb-server
on the host on your behalf.A lot of gdb-remotes are in fact embedded simulators e.g. msp430, console emulators, etc. which don't have anything to do with the host. I expect 99% of the time they are a different architecture, or if they do return a PID it's 1 or one that doesn't match the host.
Not sure what a fix here would be given that this localhost assumption makes other parts of lldb work properly. Perhaps there is some way to spell "localhost:port" in a way that lldb won't detect as being on the host.
This issue was discovered by a colleague who was trying to debug AArch64 SME code (emulated by qemu) on an AArch64 host (that lacks SME).