From 86566d4f3ca8c334a2b17d1d81b9703d4476840d Mon Sep 17 00:00:00 2001 From: liujialiang Date: Fri, 24 May 2024 16:56:49 +0800 Subject: [PATCH] [LLDB]Optimize the logic for "process" in linux to get loaded module Description: check both th filename and directory when matching module in NativeProcessLinux::GetLoadedModuleFileSpec. For example, if we loaded a module named "/A/liba.so" when attaching, and then "/B/liba.so" is dlopened during runtime. With this pr, lldb will not match "/A/liba.so" to "/B/liba.so". Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I9RYMX Test: dlopen a lib with the lib with the same name(but different dir) which loaded before attached. The new lib will not be binded to the old module. Signed-off-by: liujialiang Change-Id: Id15ab47e6540918759c391bb32fff3d71f79c067 --- lldb/source/Host/ohos/HostInfoOHOS.cpp | 4 ++-- lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lldb/source/Host/ohos/HostInfoOHOS.cpp b/lldb/source/Host/ohos/HostInfoOHOS.cpp index e47d26e3e938..6a03da35197d 100644 --- a/lldb/source/Host/ohos/HostInfoOHOS.cpp +++ b/lldb/source/Host/ohos/HostInfoOHOS.cpp @@ -20,10 +20,10 @@ void HostInfoOHOS::ComputeHostArchitectureSupport(ArchSpec &arch_32, HostInfoLinux::ComputeHostArchitectureSupport(arch_32, arch_64); if (arch_32.IsValid()) { - arch_32.GetTriple().setEnvironment(llvm::Triple::UnknownEnvironment); + arch_32.GetTriple().setEnvironment(llvm::Triple::OpenHOS); } if (arch_64.IsValid()) { - arch_64.GetTriple().setEnvironment(llvm::Triple::UnknownEnvironment); + arch_64.GetTriple().setEnvironment(llvm::Triple::OpenHOS); } } diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index abee8dbebe75..ecd51abf3295 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -1734,7 +1734,11 @@ Status NativeProcessLinux::GetLoadedModuleFileSpec(const char *module_path, file_spec.Clear(); for (const auto &it : m_mem_region_cache) { - if (it.second.GetFilename() == module_file_spec.GetFilename()) { + // OHOS_LOCAL + const bool dir_check = (!m_arch.GetTriple().isOHOSFamily() || + it.second.GetDirectory() == module_file_spec.GetDirectory()); + // OHOS_LOCAL + if (it.second.GetFilename() == module_file_spec.GetFilename() && dir_check) { file_spec = it.second; return Status(); } -- Gitee