From b29444c83706f11ef99ac0463187a7a6e9ff3240 Mon Sep 17 00:00:00 2001 From: liujialiang Date: Sat, 13 Jul 2024 21:00:54 +0800 Subject: [PATCH] [LLDB]Add a new property "target.modules-search-paths" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When debugging remotely, we always need to remap paths of modules in remote to local paths. LLDB has given command "target modules search-paths add" but this command can only be used after target created. If we want to attach to a process, this command can not be used before attaching. So we add a property "target.modules-search-paths" to set the modules searching paths when initializing Target. User can set this property before command "attach" or "target create". This property consists of an array of pairs, the first element is a path prefix, and the second is its replacement. The syntax is `prefix1 replacement1 prefix2 replacement2...`. The pairs are checked in order, the first prefix that matches is used, and that prefix is substituted with the replacement. Issue:https://gitee.com/openharmony/third_party_llvm-project/issues/IACS4H Signed-off-by: liujialiang Change-Id: I668a9a6f78df677852f4bf1236fa89122cdf21e1 --- lldb/include/lldb/Target/Target.h | 2 ++ lldb/source/Target/Target.cpp | 14 ++++++++++++++ lldb/source/Target/TargetProperties.td | 3 +++ 3 files changed, 19 insertions(+) diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 294fd96bc313..3af8c71dd977 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -147,6 +147,8 @@ public: FileSpecList GetDebugFileSearchPaths(); + PathMappingList &GetModulesSearchPaths() const; + FileSpecList GetClangModuleSearchPaths(); bool GetEnableAutoImportClangModules() const; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index c6609b39199a..3d39fe8152a5 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -120,6 +120,11 @@ Target::Target(Debugger &debugger, const ArchSpec &target_arch, } UpdateLaunchInfoFromProperties(); + + // OHOS_LOCAL begin + // Init modules searching paths by property "target.modules-search-paths". + m_image_search_paths.Append(GetModulesSearchPaths(), false); + // OHOS_LOCAL end } Target::~Target() { @@ -4305,6 +4310,15 @@ FileSpecList TargetProperties::GetDebugFileSearchPaths() { return option_value->GetCurrentValue(); } +PathMappingList &TargetProperties::GetModulesSearchPaths() const { + const uint32_t idx = ePropertyModulesSearchPaths; + OptionValuePathMappings *option_value = + m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings(nullptr, + false, idx); + assert(option_value); + return option_value->GetCurrentValue(); +} + FileSpecList TargetProperties::GetClangModuleSearchPaths() { const uint32_t idx = ePropertyClangModuleSearchPaths; const OptionValueFileSpecList *option_value = diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index acee09ca0469..f9ba215c7793 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -43,6 +43,9 @@ let Definition = "target" in { def DebugFileSearchPaths: Property<"debug-file-search-paths", "FileSpecList">, DefaultStringValue<"">, Desc<"List of directories to be searched when locating debug symbol files. See also symbols.enable-external-lookup.">; + def ModulesSearchPaths: Property<"modules-search-paths", "PathMap">, + DefaultStringValue<"">, + Desc<"Module path remappings apply substitutions to the paths of modules, typically needed to debug remotely. The modules-search-paths property can be seen as a pre configuration instead of command `target modules search-paths add`. This property consists of an array of pairs, the first element is a path prefix, and the second is its replacement. The syntax is `prefix1 replacement1 prefix2 replacement2...`. The pairs are checked in order, the first prefix that matches is used, and that prefix is substituted with the replacement.">; def ClangModuleSearchPaths: Property<"clang-module-search-paths", "FileSpecList">, DefaultStringValue<"">, Desc<"List of directories to be searched when locating modules for Clang.">; -- Gitee