Hey!
I am writing type formatting scripts in Python for lldb, as described in https://lldb.llvm.org/use/variable.html#python-scripting. I'm trying to pass an environment variable to lldb from Xcode to determine the path to the scripts in the project root, so the project is not bound to some predetermined path. I am having trouble doing this in Xcode.
What I have tried:
- lldbinit file
- Create a .lldbinit file in $(SRCROOT) with the following content:
platform shell echo $SRCROOT. - Set the path to the .lldbinit file in Edit Scheme... > Info > LLDB Init File (
$(SRCROOT)/.lldbinit). - Set the SRCROOT environment variable to
$(SRCROOT)in Edit Scheme... > Arguments > Environment Variables.
- Create a .lldbinit file in $(SRCROOT) with the following content:
- entry-point breakpoint
- Add a breakpoint to the entry-point of the application.
- Set the Automatically continue after evaluating actions option.
- Add the action
platform shell $(SRCROOT)orplatform shell $SRCROOT. - Set the SRCROOT environment variable to
$(SRCROOT)in Edit Scheme... > Arguments > Environment Variables.
What I expect to happen: The first line of the debug console is a path pointing to $(SRCROOT) What actually happens: No path is output
Is this functionality available in Xcode Version 26.0.1 (17A400)?
Thanks in advance, Barnabas
Xcode doesn't pass these environment variables to lldb when it runs it, nor does it preprocess the .lldbinit files to insert these variables.
We don't pass them to lldb as there's too much chance one of them really wouldn't be appropriate for lldb and cause hard to diagnose problems. And since .lldbinit files can contain arbitrary user expressions, preprocessing can also cause problems.
Instead, the suggested way to do this is to make a target specific lldbinit file - as you have done - and in that file bring in all the .py files you need using
command script import --relative-to-command-file ./my_python_files/my_python_file.py
That allows you to give the paths to all your python files relative to the target-specific .lldbinit file without having to know where any of them actually are.
Note, the same option exists for sourcing other files of lldb commands using command source.