wallace updated this revision to Diff 260501. wallace added a comment. Added a test, which was easier than I thought! I tested it on mac as well, so I hope it'll work well on the buildbots.
I also removed that bad use of auto. It seems that all StringRefs gotten from the JSON object are null-terminated. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D78839/new/ https://reviews.llvm.org/D78839 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/linux-x86_64.core lldb/test/API/tools/lldb-vscode/coreFile/linux-x86_64.out lldb/tools/lldb-vscode/README.md lldb/tools/lldb-vscode/lldb-vscode.cpp lldb/tools/lldb-vscode/package.json
Index: lldb/tools/lldb-vscode/package.json =================================================================== --- lldb/tools/lldb-vscode/package.json +++ lldb/tools/lldb-vscode/package.json @@ -218,8 +218,12 @@ }, "exitCommands": { "type": "array", - "description": "Commands executed at the end of debugging session.", - "default": [] + "description": "Commands executed at the end of debugging session.", + "default": [] + }, + "coreFile": { + "type": "string", + "description": "Path to the core file to debug." } } } Index: lldb/tools/lldb-vscode/lldb-vscode.cpp =================================================================== --- lldb/tools/lldb-vscode/lldb-vscode.cpp +++ lldb/tools/lldb-vscode/lldb-vscode.cpp @@ -530,7 +530,9 @@ g_vsc.stop_commands = GetStrings(arguments, "stopCommands"); g_vsc.exit_commands = GetStrings(arguments, "exitCommands"); auto attachCommands = GetStrings(arguments, "attachCommands"); - g_vsc.stop_at_entry = GetBoolean(arguments, "stopOnEntry", false); + llvm::StringRef core_file = GetString(arguments, "coreFile"); + g_vsc.stop_at_entry = + core_file.empty() ? GetBoolean(arguments, "stopOnEntry", false) : true; const auto debuggerRoot = GetString(arguments, "debuggerRoot"); // This is a hack for loading DWARF in .o files on Mac where the .o files @@ -569,7 +571,10 @@ // Disable async events so the attach will be successful when we return from // the launch call and the launch will happen synchronously g_vsc.debugger.SetAsync(false); - g_vsc.target.Attach(attach_info, error); + if (core_file.empty()) + g_vsc.target.Attach(attach_info, error); + else + g_vsc.target.LoadCore(core_file.data(), error); // Reenable async events g_vsc.debugger.SetAsync(true); } else { @@ -584,7 +589,7 @@ SetSourceMapFromArguments(*arguments); - if (error.Success()) { + if (error.Success() && core_file.empty()) { auto attached_pid = g_vsc.target.GetProcess().GetProcessID(); if (attached_pid == LLDB_INVALID_PROCESS_ID) { if (attachCommands.empty()) Index: lldb/tools/lldb-vscode/README.md =================================================================== --- lldb/tools/lldb-vscode/README.md +++ lldb/tools/lldb-vscode/README.md @@ -181,15 +181,15 @@ ### Loading a Core File -Loading a core file can use the `"attach"` request along with the -`"attachCommands"` to implement a custom attach: +This loads the coredump file `/cores/123.core` associated with the program +`/tmp/a.out`: ```javascript { - "name": "Attach to Name (wait)", + "name": "Load coredump", "type": "lldb-vscode", "request": "attach", - "attachCommands": ["target create -c /path/to/123.core /path/to/executable"], - "stopOnEntry": false + "coreFile": "/cores/123.core", + "program": "/tmp/a.out" } ``` Index: lldb/test/API/tools/lldb-vscode/coreFile/TestVSCode_coreFile.py =================================================================== --- /dev/null +++ lldb/test/API/tools/lldb-vscode/coreFile/TestVSCode_coreFile.py @@ -0,0 +1,36 @@ +""" +Test lldb-vscode coreFile attaching +""" + + +import unittest2 +import vscode +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +import lldbvscode_testcase +import os + + +class TestVSCode_coreFile(lldbvscode_testcase.VSCodeTestCaseBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipIfWindows + @skipIfRemote + @skipIfLLVMTargetMissing("X86") + def test_core_file(self): + 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() + self.attach(exe_file, coreFile=core_file) + + frames = self.get_stackFrames() + self.assertEquals( + frames, + [{'column': 0, 'id': 524288, 'line': 4, 'name': 'bar', 'source': {'name': 'main.c', 'path': '/home/labath/test/main.c'}}, + {'column': 0, 'id': 524289, 'line': 10, 'name': 'foo', 'source': {'name': 'main.c', 'path': '/home/labath/test/main.c'}}, + {'column': 0, 'id': 524290, 'line': 16, 'name': '_start', 'source': {'name': 'main.c', 'path': '/home/labath/test/main.c'}}] + ) 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 @@ -450,7 +450,7 @@ def request_attach(self, program=None, pid=None, waitFor=None, trace=None, initCommands=None, preRunCommands=None, stopCommands=None, exitCommands=None, - attachCommands=None): + attachCommands=None, coreFile=None): args_dict = {} if pid is not None: args_dict['pid'] = pid @@ -471,6 +471,8 @@ args_dict['exitCommands'] = exitCommands if attachCommands: args_dict['attachCommands'] = attachCommands + if coreFile: + args_dict['coreFile'] = coreFile 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 @@ -239,7 +239,7 @@ def attach(self, program=None, pid=None, waitFor=None, trace=None, initCommands=None, preRunCommands=None, stopCommands=None, - exitCommands=None, attachCommands=None): + exitCommands=None, attachCommands=None, coreFile=None): '''Build the default Makefile target, create the VSCode debug adaptor, and attach to the process. ''' @@ -257,7 +257,7 @@ program=program, pid=pid, waitFor=waitFor, trace=trace, initCommands=initCommands, preRunCommands=preRunCommands, stopCommands=stopCommands, exitCommands=exitCommands, - attachCommands=attachCommands) + attachCommands=attachCommands, coreFile=coreFile) if not (response and response['success']): self.assertTrue(response['success'], 'attach failed (%s)' % (response['message']))
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits