Skip to content

Commit 9fba5e5

Browse files
da-viperDhruvSrivastavaX
authored andcommitted
[lldb-dap][test] Fix DAP disassemble test (llvm#142129)
compare the instructions before and after setting breakpoint to make sure they are the same.
1 parent 84be8b5 commit 9fba5e5

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

lldb/test/API/tools/lldb-dap/disassemble/TestDAP_disassemble.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
Test lldb-dap disassemble request
33
"""
44

5-
6-
import dap_server
7-
from lldbsuite.test.decorators import *
8-
from lldbsuite.test.lldbtest import *
9-
from lldbsuite.test import lldbutil
5+
from lldbsuite.test.decorators import skipIfWindows
6+
from lldbsuite.test.lldbtest import line_number
107
import lldbdap_testcase
11-
import os
128

139

1410
class TestDAP_disassemble(lldbdap_testcase.DAPTestCaseBase):
@@ -20,18 +16,35 @@ def test_disassemble(self):
2016
program = self.getBuildArtifact("a.out")
2117
self.build_and_launch(program)
2218
source = "main.c"
23-
self.set_source_breakpoints(source, [line_number(source, "// breakpoint 1")])
19+
bp_line_no = line_number(source, "// breakpoint 1")
20+
self.set_source_breakpoints(source, [bp_line_no])
2421
self.continue_to_next_stop()
2522

26-
_, pc_assembly = self.disassemble(frameIndex=0)
27-
self.assertIn("location", pc_assembly, "Source location missing.")
28-
self.assertIn("instruction", pc_assembly, "Assembly instruction missing.")
23+
insts_with_bp, pc_with_bp_assembly = self.disassemble(frameIndex=0)
24+
self.assertIn("location", pc_with_bp_assembly, "Source location missing.")
25+
self.assertEqual(
26+
pc_with_bp_assembly["line"], bp_line_no, "Expects the same line number"
27+
)
28+
no_bp = self.set_source_breakpoints(source, [])
29+
self.assertEqual(len(no_bp), 0, "Expects no breakpoints.")
30+
self.assertIn(
31+
"instruction", pc_with_bp_assembly, "Assembly instruction missing."
32+
)
33+
34+
insts_no_bp, pc_no_bp_assembly = self.disassemble(frameIndex=0)
35+
self.assertIn("location", pc_no_bp_assembly, "Source location missing.")
36+
self.assertEqual(
37+
pc_with_bp_assembly["line"], bp_line_no, "Expects the same line number"
38+
)
39+
# the disassembly instructions should be the same with breakpoint and no breakpoint;
40+
self.assertDictEqual(
41+
insts_with_bp,
42+
insts_no_bp,
43+
"Expects instructions are the same after removing breakpoints.",
44+
)
45+
self.assertIn("instruction", pc_no_bp_assembly, "Assembly instruction missing.")
2946

30-
# The calling frame (qsort) is coming from a system library, as a result
31-
# we should not have a source location.
32-
_, qsort_assembly = self.disassemble(frameIndex=1)
33-
self.assertNotIn("location", qsort_assembly, "Source location not expected.")
34-
self.assertIn("instruction", pc_assembly, "Assembly instruction missing.")
47+
self.continue_to_exit()
3548

3649
@skipIfWindows
3750
def test_disassemble_backwards(self):
@@ -74,3 +87,7 @@ def test_disassemble_backwards(self):
7487
backwards_instructions,
7588
f"requested instruction should be preceeded by {backwards_instructions} instructions. Actual index: {frame_instruction_index}",
7689
)
90+
91+
# clear breakpoints
92+
self.set_source_breakpoints(source, [])
93+
self.continue_to_exit()

lldb/test/API/tools/lldb-dap/disassemble/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ int compare_ints(const void *a, const void *b) {
66
int arg1 = *(const int *)a;
77
int arg2 = *(const int *)b;
88

9-
// breakpoint 1
10-
11-
if (arg1 < arg2)
9+
if (arg1 < arg2) // breakpoint 1
1210
return -1;
1311
if (arg1 > arg2)
1412
return 1;

0 commit comments

Comments
 (0)