Depends on: * https://github.com/llvm/llvm-project/pull/187229 (only second commit and onwards are relevant) This patch implements the base infrastructure described in this [RFC re. Moving libc++ data-formatters out of LLDB](https://discourse.llvm.org/t/rfc-lldb-moving-libc-data-formatters-out-of-lldb/89591) The intention is to provide vendors with a way to pre-configure a set of paths that LLDB can automatically ingest formatter scripts from. Three main changes: 1. Adds a CMake variable `LLDB_SAFE_AUTO_LOAD_PATHS` which is a semi-colon separated list of paths. This is intended to be set by vendors when building LLDB for distribution. 2. Adds a setting that only exists in asserts mode called `testing.safe-auto-load-paths` which allows setting the paths without a CMake configuration. Used for local development and, more crucially, the shell and unit tests 3. Adds a `LocateScriptingResourcesFromSafePaths` which `Platform::LocateExecutableScriptingResources` calls by default (and hence used by all platforms). I add a `LocateExecutableScriptingResourcesImpl` that platforms can override if they have platform-specific resource script locations (e.g., dSYMs on Darwin). Whenever we load an image, we check the safe path (starting with the last appended path) for a directory called `/safe/path/to/<module>/<module>.py`. If such script exists, we import it as a Python module. If not, we move on to the next safe path. Currently the default for `LLDB_SAFE_AUTO_LOAD_PATHS` is empty. Eventually the plan is to make those point to the libc++ installation (where the formatters will live) depending on platform/vendor. For macOS we'll add a special `$SDK_ROOT` that can be used in the path variable, which `LocateScriptingResourcesFromSafePaths` will resolve to an actual SDK path. *AI Usage*: * Claude assisted with the CMake machinery which I then reviewed and cleaned up. I'm not sure this is the most idiomatic way of letting a user provide lists of paths, but I couldn't find a better way. * Wrote the basic auto-load Shell tests myself and asked claude to stamp out a bunch more for different scenarios. Reviewed and cleaned those up myself.
25 lines
728 B
Plaintext
25 lines
728 B
Plaintext
# REQUIRES: python, asserts, !system-windows
|
|
|
|
# Test that LLDB auto-loads <safe-path>/<module-name>/<module-name>.py on
|
|
# module load.
|
|
|
|
# RUN: split-file %s %t
|
|
# RUN: %clang_host %t/main.c -o %t/TestModule.out
|
|
# RUN: mkdir -p %t/safe-path/TestModule
|
|
|
|
# RUN: cp %t/script.py %t/safe-path/TestModule/TestModule.py
|
|
# RUN: %lldb -b \
|
|
# RUN: -o 'settings set target.load-script-from-symbol-file true' \
|
|
# RUN: -o 'settings append testing.safe-auto-load-paths %t/safe-path' \
|
|
# RUN: -o 'target create %t/TestModule.out' 2>&1 | FileCheck %s
|
|
|
|
# CHECK: AUTOLOAD_SUCCESS
|
|
|
|
#--- main.c
|
|
int main() { return 0; }
|
|
|
|
#--- script.py
|
|
import sys
|
|
def __lldb_init_module(debugger, internal_dict):
|
|
print("AUTOLOAD_SUCCESS", file=sys.stderr)
|