tberghammer created this revision. tberghammer added reviewers: labath, clayborg. tberghammer added a subscriber: lldb-commits.
Add reverse file remapping for breakpoint set LLDB can remap a source file to a new directory based on the "target.sorce-map" to handle the usecase when the source code moved between the compilation and the debugging. Previously the remapping was only used to display the content of the file. This CL fixes the scenario when a breakpoint is set based on the new an absolute path with adding an inverse remapping step before looking up the breakpoint location. http://reviews.llvm.org/D17848 Files: include/lldb/Target/PathMappingList.h packages/Python/lldbsuite/test/source-manager/TestSourceManager.py source/Target/PathMappingList.cpp source/Target/Target.cpp
Index: source/Target/Target.cpp =================================================================== --- source/Target/Target.cpp +++ source/Target/Target.cpp @@ -348,6 +348,13 @@ 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 @@ break; case eInlineBreakpointsHeaders: - if (file.IsSourceImplementationFile()) + if (remapped_file.IsSourceImplementationFile()) check_inlines = eLazyBoolNo; else check_inlines = eLazyBoolYes; @@ -374,7 +381,7 @@ { // 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 @@ move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo; BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine(nullptr, - file, + remapped_file, line_no, check_inlines, skip_prologue, Index: source/Target/PathMappingList.cpp =================================================================== --- source/Target/PathMappingList.cpp +++ source/Target/PathMappingList.cpp @@ -215,6 +215,27 @@ } 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()) Index: packages/Python/lldbsuite/test/source-manager/TestSourceManager.py =================================================================== --- packages/Python/lldbsuite/test/source-manager/TestSourceManager.py +++ packages/Python/lldbsuite/test/source-manager/TestSourceManager.py @@ -170,3 +170,21 @@ # 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']) Index: include/lldb/Target/PathMappingList.h =================================================================== --- include/lldb/Target/PathMappingList.h +++ include/lldb/Target/PathMappingList.h @@ -116,7 +116,9 @@ 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. ///
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits