diff options
| -rw-r--r-- | lldb/include/lldb/Target/PathMappingList.h | 4 | ||||
| -rw-r--r-- | lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py | 18 | ||||
| -rw-r--r-- | lldb/source/Target/PathMappingList.cpp | 21 | ||||
| -rw-r--r-- | lldb/source/Target/Target.cpp | 13 |
4 files changed, 52 insertions, 4 deletions
diff --git a/lldb/include/lldb/Target/PathMappingList.h b/lldb/include/lldb/Target/PathMappingList.h index 17185cb6849..1a486c4642d 100644 --- a/lldb/include/lldb/Target/PathMappingList.h +++ b/lldb/include/lldb/Target/PathMappingList.h @@ -116,7 +116,9 @@ public: bool RemapPath (const char *path, std::string &new_path) const; - + bool + ReverseRemapPath (const ConstString &path, ConstString &new_path) const; + //------------------------------------------------------------------ /// Finds a source file given a file spec using the path remappings. /// diff --git a/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py b/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py index 1a59fe46e90..b4bffaf6863 100644 --- a/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py +++ b/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py @@ -170,3 +170,21 @@ class SourceManagerTestCase(TestBase): # Display the source code again. We should see the updated line. self.expect("source list -f main.c -l %d" % self.line, SOURCE_DISPLAYED_CORRECTLY, substrs = ['Hello lldb']) + + def test_set_breakpoint_with_absloute_path(self): + self.build() + self.runCmd("settings set target.source-map %s %s" % (os.getcwd(), os.path.join(os.getcwd(), "hidden"))) + + exe = os.path.join(os.getcwd(), "a.out") + main = os.path.join(os.getcwd(), "hidden", "main.c") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line (self, main, self.line, num_expected_locations=1, loc_exact=False) + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'main.c:%d' % self.line, + 'stop reason = breakpoint']) diff --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp index bc14be1785d..2372c2f9dd9 100644 --- a/lldb/source/Target/PathMappingList.cpp +++ b/lldb/source/Target/PathMappingList.cpp @@ -215,6 +215,27 @@ PathMappingList::RemapPath (const char *path, std::string &new_path) const } bool +PathMappingList::ReverseRemapPath (const ConstString &path, ConstString &new_path) const +{ + const char *path_cstr = path.GetCString(); + if (!path_cstr) + return false; + + for (const auto& it : m_pairs) + { + const size_t prefixLen = it.second.GetLength(); + if (::strncmp (it.second.GetCString(), path_cstr, prefixLen) == 0) + { + std::string new_path_str (it.first.GetCString()); + new_path_str.append(path.GetCString() + prefixLen); + new_path.SetCString(new_path_str.c_str()); + return true; + } + } + return false; +} + +bool PathMappingList::FindFile (const FileSpec &orig_spec, FileSpec &new_spec) const { if (!m_pairs.empty()) diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 9ba667690c8..7455c2035d0 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -348,6 +348,13 @@ Target::CreateBreakpoint (const FileSpecList *containingModules, bool hardware, LazyBool move_to_nearest_code) { + FileSpec remapped_file; + ConstString remapped_path; + if (GetSourcePathMap().ReverseRemapPath(ConstString(file.GetPath().c_str()), remapped_path)) + remapped_file.SetFile(remapped_path.AsCString(), true); + else + remapped_file = file; + if (check_inlines == eLazyBoolCalculate) { const InlineStrategy inline_strategy = GetInlineStrategy(); @@ -358,7 +365,7 @@ Target::CreateBreakpoint (const FileSpecList *containingModules, break; case eInlineBreakpointsHeaders: - if (file.IsSourceImplementationFile()) + if (remapped_file.IsSourceImplementationFile()) check_inlines = eLazyBoolNo; else check_inlines = eLazyBoolYes; @@ -374,7 +381,7 @@ Target::CreateBreakpoint (const FileSpecList *containingModules, { // Not checking for inlines, we are looking only for matching compile units FileSpecList compile_unit_list; - compile_unit_list.Append (file); + compile_unit_list.Append (remapped_file); filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list); } else @@ -387,7 +394,7 @@ Target::CreateBreakpoint (const FileSpecList *containingModules, move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo; BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine(nullptr, - file, + remapped_file, line_no, check_inlines, skip_prologue, |

