[Lldb-commits] [lldb] r262711 - Add reverse file remapping for breakpoint set

Tamas Berghammer via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 4 03:26:44 PST 2016


Author: tberghammer
Date: Fri Mar  4 05:26:44 2016
New Revision: 262711

URL: http://llvm.org/viewvc/llvm-project?rev=262711&view=rev
Log:
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 compliation 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.

Differential revision: http://reviews.llvm.org/D17848

Modified:
    lldb/trunk/include/lldb/Target/PathMappingList.h
    lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
    lldb/trunk/source/Target/PathMappingList.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Target/PathMappingList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/PathMappingList.h?rev=262711&r1=262710&r2=262711&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/PathMappingList.h (original)
+++ lldb/trunk/include/lldb/Target/PathMappingList.h Fri Mar  4 05:26:44 2016
@@ -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.
     ///

Modified: lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py?rev=262711&r1=262710&r2=262711&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py Fri Mar  4 05:26:44 2016
@@ -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'])

Modified: lldb/trunk/source/Target/PathMappingList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/PathMappingList.cpp?rev=262711&r1=262710&r2=262711&view=diff
==============================================================================
--- lldb/trunk/source/Target/PathMappingList.cpp (original)
+++ lldb/trunk/source/Target/PathMappingList.cpp Fri Mar  4 05:26:44 2016
@@ -215,6 +215,27 @@ PathMappingList::RemapPath (const char *
 }
 
 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())

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=262711&r1=262710&r2=262711&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Fri Mar  4 05:26:44 2016
@@ -348,6 +348,13 @@ Target::CreateBreakpoint (const FileSpec
                           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 FileSpec
                 break;
                 
             case eInlineBreakpointsHeaders:
-                if (file.IsSourceImplementationFile())
+                if (remapped_file.IsSourceImplementationFile())
                     check_inlines = eLazyBoolNo;
                 else
                     check_inlines = eLazyBoolYes;
@@ -374,7 +381,7 @@ Target::CreateBreakpoint (const FileSpec
     {
         // 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 FileSpec
         move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo;
 
     BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine(nullptr,
-                                                                    file,
+                                                                    remapped_file,
                                                                     line_no,
                                                                     check_inlines,
                                                                     skip_prologue,




More information about the lldb-commits mailing list