[Lldb-commits] [lldb] [lldb] Allow mapping object file paths (PR #101361)
https://github.com/aperez created https://github.com/llvm/llvm-project/pull/101361 This introduces a `target.object-map` which allows us to remap module locations, much in the same way as source mapping works today. This is useful, for instance, when debugging coredumps, so we can replace some of the locations where LLDB attempts to load shared libraries and executables from, without having to setup an entire sysroot. >From 5221c6f267fffd811c6dd39dbbcc211e2a93739c Mon Sep 17 00:00:00 2001 From: Alexandre Perez Date: Wed, 31 Jul 2024 09:38:38 -0700 Subject: [PATCH] [lldb] Allow mapping object file paths --- lldb/include/lldb/Target/Target.h | 2 ++ lldb/source/Target/Target.cpp | 21 ++-- lldb/source/Target/TargetProperties.td| 3 +++ .../postmortem/elf-core/TestLinuxCore.py | 24 +++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 5d5ae1bfcd3bd..119dff4d49819 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -141,6 +141,8 @@ class TargetProperties : public Properties { PathMappingList &GetSourcePathMap() const; + PathMappingList &GetObjectPathMap() const; + bool GetAutoSourceMapRelative() const; FileSpecList GetExecutableSearchPaths(); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index ec0da8a1378a8..129683c43f0c1 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2155,12 +2155,21 @@ bool Target::ReadPointerFromMemory(const Address &addr, Status &error, return false; } -ModuleSP Target::GetOrCreateModule(const ModuleSpec &module_spec, bool notify, - Status *error_ptr) { +ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec, + bool notify, Status *error_ptr) { ModuleSP module_sp; Status error; + // Apply any remappings specified in target.object-map: + ModuleSpec module_spec(orig_module_spec); + PathMappingList &obj_mapping = GetObjectPathMap(); + if (std::optional remapped_obj_file = + obj_mapping.RemapPath(orig_module_spec.GetFileSpec().GetPath(), +true /* only_if_exists */)) { +module_spec.GetFileSpec().SetPath(remapped_obj_file->GetPath()); + } + // First see if we already have this module in our module list. If we do, // then we're done, we don't need to consult the shared modules list. But // only do this if we are passed a UUID. @@ -4459,6 +4468,14 @@ PathMappingList &TargetProperties::GetSourcePathMap() const { return option_value->GetCurrentValue(); } +PathMappingList &TargetProperties::GetObjectPathMap() const { + const uint32_t idx = ePropertyObjectMap; + OptionValuePathMappings *option_value = + m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings(idx); + assert(option_value); + return option_value->GetCurrentValue(); +} + bool TargetProperties::GetAutoSourceMapRelative() const { const uint32_t idx = ePropertyAutoSourceMapRelative; return GetPropertyAtIndexAs( diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index 7f79218e0a6a4..4404a45492254 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -46,6 +46,9 @@ let Definition = "target" in { def SourceMap: Property<"source-map", "PathMap">, DefaultStringValue<"">, Desc<"Source path remappings apply substitutions to the paths of source files, typically needed to debug from a different host than the one that built the target. The source-map 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. A common pattern is to use source-map in conjunction with the clang -fdebug-prefix-map flag. In the build, use `-fdebug-prefix-map=/path/to/build_dir=.` to rewrite the host specific build directory to `.`. Then for debugging, use `settings set target.source-map . /path/to/local_dir` to convert `.` to a valid local path.">; + def ObjectMap: Property<"object-map", "PathMap">, +DefaultStringValue<"">, +Desc<"Object path remappings apply substitutions to the paths of object files, typically needed to debug from a different host than the one that built the target. The object-map 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 AutoSourceMapRelative: Property<"
[Lldb-commits] [lldb] [lldb] Allow mapping object file paths (PR #101361)
https://github.com/aperez updated https://github.com/llvm/llvm-project/pull/101361 >From 132b6fb0808385494a71c99533d7281420b743bd Mon Sep 17 00:00:00 2001 From: Alexandre Perez Date: Wed, 31 Jul 2024 09:38:38 -0700 Subject: [PATCH] [lldb] Allow mapping object file paths --- lldb/include/lldb/Target/Target.h | 2 ++ lldb/source/Target/Target.cpp | 21 +-- lldb/source/Target/TargetProperties.td| 3 +++ .../postmortem/elf-core/TestLinuxCore.py | 26 +++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 5d5ae1bfcd3bd..119dff4d49819 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -141,6 +141,8 @@ class TargetProperties : public Properties { PathMappingList &GetSourcePathMap() const; + PathMappingList &GetObjectPathMap() const; + bool GetAutoSourceMapRelative() const; FileSpecList GetExecutableSearchPaths(); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index ec0da8a1378a8..129683c43f0c1 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2155,12 +2155,21 @@ bool Target::ReadPointerFromMemory(const Address &addr, Status &error, return false; } -ModuleSP Target::GetOrCreateModule(const ModuleSpec &module_spec, bool notify, - Status *error_ptr) { +ModuleSP Target::GetOrCreateModule(const ModuleSpec &orig_module_spec, + bool notify, Status *error_ptr) { ModuleSP module_sp; Status error; + // Apply any remappings specified in target.object-map: + ModuleSpec module_spec(orig_module_spec); + PathMappingList &obj_mapping = GetObjectPathMap(); + if (std::optional remapped_obj_file = + obj_mapping.RemapPath(orig_module_spec.GetFileSpec().GetPath(), +true /* only_if_exists */)) { +module_spec.GetFileSpec().SetPath(remapped_obj_file->GetPath()); + } + // First see if we already have this module in our module list. If we do, // then we're done, we don't need to consult the shared modules list. But // only do this if we are passed a UUID. @@ -4459,6 +4468,14 @@ PathMappingList &TargetProperties::GetSourcePathMap() const { return option_value->GetCurrentValue(); } +PathMappingList &TargetProperties::GetObjectPathMap() const { + const uint32_t idx = ePropertyObjectMap; + OptionValuePathMappings *option_value = + m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings(idx); + assert(option_value); + return option_value->GetCurrentValue(); +} + bool TargetProperties::GetAutoSourceMapRelative() const { const uint32_t idx = ePropertyAutoSourceMapRelative; return GetPropertyAtIndexAs( diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index 7f79218e0a6a4..4404a45492254 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -46,6 +46,9 @@ let Definition = "target" in { def SourceMap: Property<"source-map", "PathMap">, DefaultStringValue<"">, Desc<"Source path remappings apply substitutions to the paths of source files, typically needed to debug from a different host than the one that built the target. The source-map 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. A common pattern is to use source-map in conjunction with the clang -fdebug-prefix-map flag. In the build, use `-fdebug-prefix-map=/path/to/build_dir=.` to rewrite the host specific build directory to `.`. Then for debugging, use `settings set target.source-map . /path/to/local_dir` to convert `.` to a valid local path.">; + def ObjectMap: Property<"object-map", "PathMap">, +DefaultStringValue<"">, +Desc<"Object path remappings apply substitutions to the paths of object files, typically needed to debug from a different host than the one that built the target. The object-map 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 AutoSourceMapRelative: Property<"auto-source-map-relative", "Boolean">, DefaultTrue, Desc<"Automatically deduce source path mappings based on source file breakpoint resolution. It only deduces source mapping if source file breakpoint request is using full path and if the debug info contains relative paths.">; diff --git a/lldb/test/API/functionalities/postmortem/e
[Lldb-commits] [lldb] [lldb] Allow mapping object file paths (PR #101361)
https://github.com/aperez closed https://github.com/llvm/llvm-project/pull/101361 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] eb3136f - Fix debugserver translation check
Author: Alexandre Perez Date: 2022-05-05T11:31:23-07:00 New Revision: eb3136f022b3e5061fe790e7886f4bb592d8a1d1 URL: https://github.com/llvm/llvm-project/commit/eb3136f022b3e5061fe790e7886f4bb592d8a1d1 DIFF: https://github.com/llvm/llvm-project/commit/eb3136f022b3e5061fe790e7886f4bb592d8a1d1.diff LOG: Fix debugserver translation check Currently, debugserver has a test to check if it was launched in translation. The intent was to cover the case where an x86_64 debugserver attempts to control an arm64/arm64e process, returning an error. However, this check also covers the case where users are attaching to an x86_64 process, exiting out before attempting to hand off control to the translated debugserver at `/Library/Apple/usr/libexec/oah/debugserver`. This diff delays the debugserver translation check until after determining whether to hand off control to `/Library/Apple/usr/libexec/oah/debugserver`. Only when the process is not translated and thus has not been handed off do we check if the debugserver is translated, erroring out in that case. Reviewed By: jasonmolenda Differential Revision: https://reviews.llvm.org/D124814 Added: Modified: lldb/tools/debugserver/source/DNB.cpp lldb/tools/debugserver/source/DNBDefs.h lldb/tools/debugserver/source/RNBRemote.cpp Removed: diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp index 59bb91b82c351..c037c48c02868 100644 --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -477,6 +477,10 @@ nub_process_t DNBProcessAttach(nub_process_t attach_pid, } } + if (DNBDebugserverIsTranslated()) { +return INVALID_NUB_PROCESS_ARCH; + } + pid_t pid = INVALID_NUB_PROCESS; MachProcessSP processSP(new MachProcess); if (processSP.get()) { diff --git a/lldb/tools/debugserver/source/DNBDefs.h b/lldb/tools/debugserver/source/DNBDefs.h index 657964215d0f3..ee31f1c7a4ba0 100644 --- a/lldb/tools/debugserver/source/DNBDefs.h +++ b/lldb/tools/debugserver/source/DNBDefs.h @@ -54,6 +54,7 @@ typedef uint32_t nub_event_t; typedef uint32_t nub_bool_t; #define INVALID_NUB_PROCESS ((nub_process_t)0) +#define INVALID_NUB_PROCESS_ARCH ((nub_process_t)-1) #define INVALID_NUB_THREAD ((nub_thread_t)0) #define INVALID_NUB_WATCH_ID ((nub_watch_t)0) #define INVALID_NUB_HW_INDEX UINT32_MAX diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp index c909cba872f7c..7c68f85225a24 100644 --- a/lldb/tools/debugserver/source/RNBRemote.cpp +++ b/lldb/tools/debugserver/source/RNBRemote.cpp @@ -3753,17 +3753,6 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) { char err_str[1024] = {'\0'}; std::string attach_name; -if (DNBDebugserverIsTranslated()) { - DNBLogError("debugserver is x86_64 binary running in translation, attach " - "failed."); - std::string return_message = "E96;"; - return_message += - cstring_to_asciihex_string("debugserver is x86_64 binary running in " - "translation, attached failed."); - SendPacket(return_message); - return rnb_err; -} - if (strstr(p, "vAttachWait;") == p) { p += strlen("vAttachWait;"); if (!GetProcessNameFrom_vAttach(p, attach_name)) { @@ -3823,6 +3812,17 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) { return HandlePacket_UNIMPLEMENTED(p); } +if (attach_pid == INVALID_NUB_PROCESS_ARCH) { + DNBLogError("debugserver is x86_64 binary running in translation, attach " + "failed."); + std::string return_message = "E96;"; + return_message += + cstring_to_asciihex_string("debugserver is x86_64 binary running in " + "translation, attach failed."); + SendPacket(return_message.c_str()); + return rnb_err; +} + if (attach_pid != INVALID_NUB_PROCESS) { if (m_ctx.ProcessID() != attach_pid) m_ctx.SetProcessID(attach_pid); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [SBProgress] Add swig support for `with` statement in Python (PR #133527)
aperez wrote: > @aperez Thoughts on this? I think this could be useful I think it could be useful as well. Couple things to note though: - If you allow for both sequences and iterators as arguments into `lldb.Progress.track` you might not know the total number steps in advance. - You'll need to handle the case when users exit the loop early, so that `Finalize()` is still called. https://github.com/llvm/llvm-project/pull/133527 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [SBProgress] Add swig support for `with` statement in Python (PR #133527)
@@ -52,6 +52,13 @@ Non-deterministic progresses behave the same, but omit the total in the construc # Explicitly send a progressEnd, otherwise this will be sent # when the python runtime cleans up this object. non_deterministic_progress.Finalize() + +Additionally for Python, progress is supported in a with statement. :: +with lldb.SBProgress('Non deterministic progress, 'Detail', lldb.SBDebugger) as progress: aperez wrote: Just a nit, the string in the first argument is not terminated: ``` with lldb.SBProgress('Non deterministic progress', 'Detail', lldb.SBDebugger) as progress: ``` https://github.com/llvm/llvm-project/pull/133527 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits