================
@@ -2,197 +2,184 @@
 Test lldb-dap coreFile attaching
 """
 
-import dap_server
 from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-import lldbdap_testcase
-import os
+from lldbsuite.test.tools.lldb_dap import DAPTestCaseBase
+from lldbsuite.test.tools.lldb_dap.types import (
+    AttachArgs,
+    ContinueArgs,
+    NextArgs,
+    Source,
+    StackFrame,
+)
 
 # The expected backtrace when loading the bundled linux-x86_64.core. Shared by
 # the tests that load this core through different mechanisms (the "coreFile"
 # attach key and "attachCommands") so we can assert they behave identically.
 EXPECTED_CORE_FRAMES = [
-    {
-        "column": 0,
-        "id": 524288,
-        "line": 4,
-        "moduleId": "01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D",
-        "name": "bar",
-        "source": {
-            "name": "main.c",
-            "path": "/home/labath/test/main.c",
-            "presentationHint": "deemphasize",
-        },
-        "instructionPointerReference": "0x40011C",
-    },
-    {
-        "column": 0,
-        "id": 524289,
-        "line": 10,
-        "moduleId": "01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D",
-        "name": "foo",
-        "source": {
-            "name": "main.c",
-            "path": "/home/labath/test/main.c",
-            "presentationHint": "deemphasize",
-        },
-        "instructionPointerReference": "0x400142",
-    },
-    {
-        "column": 0,
-        "id": 524290,
-        "line": 16,
-        "moduleId": "01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D",
-        "name": "_start",
-        "source": {
-            "name": "main.c",
-            "path": "/home/labath/test/main.c",
-            "presentationHint": "deemphasize",
-        },
-        "instructionPointerReference": "0x40015F",
-    },
+    StackFrame(
+        column=0,
+        id=524288,
+        line=4,
+        moduleId="01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D",
+        name="bar",
+        source=Source(
+            name="main.c",
+            path="/home/labath/test/main.c",
+            presentationHint="deemphasize",
+        ),
+        instructionPointerReference="0x40011C",
+    ),
+    StackFrame(
+        column=0,
+        id=524289,
+        line=10,
+        moduleId="01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D",
+        name="foo",
+        source=Source(
+            name="main.c",
+            path="/home/labath/test/main.c",
+            presentationHint="deemphasize",
+        ),
+        instructionPointerReference="0x400142",
+    ),
+    StackFrame(
+        column=0,
+        id=524290,
+        line=16,
+        moduleId="01DF54A6-045E-657D-3F8F-FB9CE1118789-14F8BD6D",
+        name="_start",
+        source=Source(
+            name="main.c",
+            path="/home/labath/test/main.c",
+            presentationHint="deemphasize",
+        ),
+        instructionPointerReference="0x40015F",
+    ),
 ]
 
 
-class TestDAP_coreFile(lldbdap_testcase.DAPTestCaseBase):
-    @skipIfLLVMTargetMissing("X86")
+@skipIfLLVMTargetMissing("X86")
+class TestDAP_coreFile(DAPTestCaseBase):
     def test_core_file(self):
-        current_dir = os.path.dirname(__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_adapter()
-        self.attach(program=exe_file, coreFile=core_file)
-        self.dap_server.request_configurationDone()
+        exe_file = self.getSourcePath("linux-x86_64.out")
+        core_file = self.getSourcePath("linux-x86_64.core")
 
-        expected_frames = EXPECTED_CORE_FRAMES
+        session = self.create_session()
+        process_event = session.attach(AttachArgs(program=exe_file, 
coreFile=core_file))
+        stop_event = session.wait_for_stopped_event(after=process_event)
+        thread_id = self.expect_not_none(stop_event.body.threadId)
 
-        self.assertEqual(self.get_stackFrames(), expected_frames)
+        frames = session.stack_trace(thread_id).body.stackFrames
+        self.assertEqual(frames, EXPECTED_CORE_FRAMES)
 
-        # Resuming should have no effect and keep the process stopped
-        resp = self.dap_server.request_continue()
-        self.assertFalse(resp["success"])
-        self.assertEqual(self.get_stackFrames(), expected_frames)
+        # Resuming a core process should fail. the process stays stopped
+        # with the same backtrace.
+        session.send_request(ContinueArgs(thread_id)).error()
+        frames = session.stack_trace(thread_id).body.stackFrames
+        self.assertEqual(frames, EXPECTED_CORE_FRAMES)
 
-        self.dap_server.request_next(threadId=32259)
-        self.assertEqual(self.get_stackFrames(), expected_frames)
+        # Same for step-over.
+        session.send_request(NextArgs(threadId=thread_id)).error()
+        frames = session.stack_trace(thread_id).body.stackFrames
+        self.assertEqual(frames, EXPECTED_CORE_FRAMES)
 
-    @skipIfLLVMTargetMissing("X86")
     def test_core_file_attach_commands(self):
         """Loading a core through "attachCommands" (e.g. `target create 
--core`)
         should behave identically to using the "coreFile" attach key: the
         session stops with the real crash reason and cannot be resumed."""
-        current_dir = os.path.dirname(__file__)
-        exe_file = os.path.join(current_dir, "linux-x86_64.out")
-        core_file = os.path.join(current_dir, "linux-x86_64.core")
+        exe_file = self.getSourcePath("linux-x86_64.out")
+        core_file = self.getSourcePath("linux-x86_64.core")
 
-        self.create_debug_adapter()
+        session = self.create_session()
         # Bootstrap the core target purely through a custom attach command,
         # mirroring how the "coreFile" key passes the same program.
-        self.attach(
-            program=exe_file,
-            attachCommands=['target create --core "%s" "%s"' % (core_file, 
exe_file)],
-        )
-
         # configurationDone must succeed: a core is a non-live session, so the
         # adapter must not try to resume it (resuming a core fails).
-        resp = self.dap_server.request_configurationDone()
-        self.assertTrue(
-            resp["success"],
-            "configurationDone should succeed for a core loaded via 
attachCommands",
+        process_event = session.attach(
+            AttachArgs(
+                program=exe_file,
+                attachCommands=[f"target create --core '{core_file}' 
'{exe_file}"],
----------------
qiyao wrote:

It is missing the closing `'` after `{exe_file}`.

https://github.com/llvm/llvm-project/pull/217403
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to