Is there a way to perform home path expansion for target.source-map in .lldbinit?

26 Views Asked by At

In .lldbinit it is possible to use a '~' for home path expansion for certain commands such as command script import

For example,

command script import ~/MyScripts/foo.py

is perfectly acceptable.

This does not work for settings set target.source-map, however.

We have a build user that packages and archives our programs from its own home directory, and sometimes it is necessary to read the symbols in and debug the packaged programs locally.

This is not an issue in and of itself. We do have to remap the source from the build service's home directory to our own home directory when we debug in order to have source resolution.

settings set target.source-map /Users/builduser/src /Users/myname/src

We would like to be able to have a line in .lldbinit that allows for mapping from the build users home directory to the current users home directory without having to edit it for every user.

For example:

settings set target.source-map /Users/builduser/src ~/src

This seems like it should be straightforward seeing how path expansion works already in commands like command script import, but instead we get the following error:

error: the replacement path doesn't exist: "~/src"

Is there any way to make this work?

There may be a convoluted way involving python imports, but we would like to keep it to one file if possible. (Although a two file python solution would be better than nothing)

1

There are 1 best solutions below

1
Jim Ingham On

The lldb command language has no facilities for this sort of thing. It was kept deliberately simple, and all the programming-like tasks delegated to Python.

As you suspect, it would be straightforward to write a lldb python-based command that generates and sets the correct settings set command and have that run in the ~/.lldbinit. The docs for writing commands are here:

https://lldb.llvm.org/use/python-reference.html#create-a-new-lldb-command-using-a-python-function

and the API reference is:

https://lldb.llvm.org/python_api.html

There aren't good API's for the settings, yet, so you will have to set it with SBDebugger.HandleCommand().

Note that command script import, which is the lldb way to import python modules into lldb, takes a --relative-to-command-file argument, so you can put the .py file with your command in a known location relative to the .lldbinit (I put my script files in ~/.lldb), and the relative argument means you don't have to put user-specific paths into your .lldbinit.