[Lldb-commits] [PATCH] D112834: [lldb-vscode] Fix coredump load source mapping for first file

Ted Woodward via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 29 10:09:45 PDT 2021


ted created this revision.
ted requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

SetSourceMapFromArguments is called after the core is loaded. This means
that the source file for the crashing code won't have the source map applied.
Move the call to SetSourceMapFromArguments in request_attach to just after
the call to RunInitCommands, matching request_launch behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112834

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/test/API/tools/lldb-vscode/coreFile/TestVSCode_coreFile.py
  lldb/test/API/tools/lldb-vscode/coreFile/main.c
  lldb/tools/lldb-vscode/lldb-vscode.cpp


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -616,6 +616,8 @@
   // Run any initialize LLDB commands the user specified in the launch.json
   g_vsc.RunInitCommands();
 
+  SetSourceMapFromArguments(*arguments);
+
   lldb::SBError status;
   g_vsc.SetTarget(g_vsc.CreateTargetFromArguments(*arguments, status));
   if (status.Fail()) {
@@ -657,8 +659,6 @@
     g_vsc.target = g_vsc.debugger.GetSelectedTarget();
   }
 
-  SetSourceMapFromArguments(*arguments);
-
   if (error.Success() && core_file.empty()) {
     auto attached_pid = g_vsc.target.GetProcess().GetProcessID();
     if (attached_pid == LLDB_INVALID_PROCESS_ID) {
Index: lldb/test/API/tools/lldb-vscode/coreFile/main.c
===================================================================
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/coreFile/main.c
@@ -0,0 +1 @@
+/* Fake source file for core dump source mapping test */
Index: lldb/test/API/tools/lldb-vscode/coreFile/TestVSCode_coreFile.py
===================================================================
--- lldb/test/API/tools/lldb-vscode/coreFile/TestVSCode_coreFile.py
+++ lldb/test/API/tools/lldb-vscode/coreFile/TestVSCode_coreFile.py
@@ -41,3 +41,18 @@
 
         self.vscode.request_next(threadId=32259)
         self.assertEquals(self.get_stackFrames(), expected_frames)
+
+    @skipIfWindows
+    @skipIfRemote
+    def test_core_file_source_mapping(self):
+        ''' Test that sourceMap property is correctly applied when loading a core '''
+        current_dir = os.path.dirname(os.path.realpath(__file__))
+        exe_file = os.path.join(current_dir, "linux-x86_64.out")
+        core_file = os.path.join(current_dir, "linux-x86_64.core")
+
+        self.create_debug_adaptor()
+
+        source_map = [["/home/labath/test", current_dir]]
+        self.attach(exe_file, coreFile=core_file, sourceMap=source_map)
+
+        self.assertTrue(current_dir in self.get_stackFrames()[0]['source']['path'])
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -506,7 +506,8 @@
                        initCommands=None, preRunCommands=None,
                        stopCommands=None, exitCommands=None,
                        attachCommands=None, terminateCommands=None,
-                       coreFile=None, postRunCommands=None):
+                       coreFile=None, postRunCommands=None,
+                       sourceMap=None):
         args_dict = {}
         if pid is not None:
             args_dict['pid'] = pid
@@ -533,6 +534,8 @@
             args_dict['coreFile'] = coreFile
         if postRunCommands:
             args_dict['postRunCommands'] = postRunCommands
+        if sourceMap:
+            args_dict['sourceMap'] = sourceMap
         command_dict = {
             'command': 'attach',
             'type': 'request',
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
@@ -251,7 +251,7 @@
                initCommands=None, preRunCommands=None, stopCommands=None,
                exitCommands=None, attachCommands=None, coreFile=None,
                disconnectAutomatically=True, terminateCommands=None,
-               postRunCommands=None):
+               postRunCommands=None, sourceMap=None):
         '''Build the default Makefile target, create the VSCode debug adaptor,
            and attach to the process.
         '''
@@ -271,7 +271,8 @@
             initCommands=initCommands, preRunCommands=preRunCommands,
             stopCommands=stopCommands, exitCommands=exitCommands,
             attachCommands=attachCommands, terminateCommands=terminateCommands,
-            coreFile=coreFile, postRunCommands=postRunCommands)
+            coreFile=coreFile, postRunCommands=postRunCommands,
+            sourceMap=sourceMap)
         if not (response and response['success']):
             self.assertTrue(response['success'],
                             'attach failed (%s)' % (response['message']))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112834.383414.patch
Type: text/x-patch
Size: 4513 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211029/5b5cbc50/attachment.bin>


More information about the lldb-commits mailing list