Fix LLDB core dumps loading in separate debug targets #1396
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Environment:
Problem overview:
When we load a core in LLDB, we do so by first sending
-file-exec-and-symbols
, followed by a non-MI commandtarget create --core
. However, this approach causes LLDB to create two separate debug targets: one with the desired executable loaded, and another one that only has the core file loaded.We can see this when manually running the above in an lldb-mi instance, and observing the output of
target list
(reformatted for readability):The core is loaded in selected debug target 1, threads/PID/stop reason and all, but does not have an executable file associated with it at all, because that one is in debug target 0:
Resulting behavior:
When MIEngine then submits its other initialization commands to actually begin debugging, LLDB still does not have an executable file loaded. So what it will do instead, is try to locate the binary using the module file name recorded in the core dump itself.
This may or may not work, depending on whether a binary with the same name happens to be in the solib search paths, but it is most certainly not the executable file the user wanted to load. Thus, in effect, the executable file input field in Visual Studio's core dump dialog is completely ignored.
You can observe this behavior in Visual Studio by loading a core file with a different executable file name than what was recorded by the core file. LLDB will fail to find the file, will be unable to load any modules, and Visual Studio will not be able to resolve (or even show) any thread call stacks.
For example, in this screenshot the Modules list is empty, and the call stack is not displayed at all:
This problem does not occur with GDB.
Proposed solution:
According to LLDB's built-in documentation, the correct method to load an executable file and a core file into the same target, is by specifying both in the same
target create
(orfile
for short) command, e.g.file example.elf -c my_core
.This patch attempts to implement this solution, by merging the
-file-exec-and-symbols
andtarget create
commands into onefile
command. GDB behavior is left unchanged (still two separate commands) since that appears to work fine.I've tried to adhere to the surrounding code style - please do let me know if something needs to be changed. :)
Thank you very much for your time!