Open DavidSpickett opened 1 month ago
@llvm/issue-subscribers-lldb
Author: David Spickett (DavidSpickett)
@JDevlieghere have we documented what is expected to work in a .lldbinit
file? https://lldb.llvm.org/search.html?q=lldbinit&check_keywords=yes&area=default# doesn't list anything.
I know we generally use them for interface things, prompt text, settings, aliases etc. but nowhere says you can't put debug commands in there.
The ~/.lldbinit file is meant to be read in "before any targets are created". For instance, if you do:
$ lldb foo
First the .lldbinit is read in, THEN target create foo
. So creating targets in the .lldbinit seems counter to this design.
Moreover, the .lldbinit is meant to be read in for EVERY lldb session, so making targets in the .lldbinit is a weird thing to do.
And putting the rest of your commands in a source file somewhere, making a shell alias for lldb -s my_special_setup
if this is something you are going to do over and over seems a quite straightforward solution.
So I don't think we need to make this work. But it would be a good idea to document that the commands in the .lldbinit file should all be ones that can run before the first target is created.
Really, the .lldbinit is the first in the chain of -S and -O options, none of those should do anything that requires or creates a target.
I don't think it's worth the effort to go through the commands marking which ones can run in the .lldbinit. This is kind of a corner case, so unless someone is really ambitious, seems to me good enough to just document this fact, and then enforce the restrictions by having violations of them not work.
This is adapted from a report received on Discord where someone was trying to debug a Linux kernel image and wanted to relocate a file using the value stored in a register as the offset.
I reproduced this with a simpler setup and I think it's down to behaviour differences for commands inside a
.lldbinit
file versus being in a sourced file using-s
or entered into the interactive prompt.The commands are:
What I expect to happen is we run to main and are able to read
sp
then use it to relocate the text section. This works fine if you source the file with-s
:It does not work if you put the same commands in a
.lldbinit
file:We even print that the target has stopped but then we say it isn't. So I suspect that the stop event does not propagate during the time a
.lldbinit
is running.