1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
"""
Test lldb-dap stack trace when some of the source paths are missing
"""
from lldbsuite.test.lldbtest import line_number
import lldbdap_testcase
from contextlib import contextmanager
import os
OTHER_C_SOURCE_CODE = """
int no_source_func(int n) {
return n + 1; // Break here
}
"""
@contextmanager
def delete_file_on_exit(path):
try:
yield path
finally:
if os.path.exists(path):
os.remove(path)
class TestDAP_stackTraceMissingSourcePath(lldbdap_testcase.DAPTestCaseBase):
def build_and_run_until_breakpoint(self):
"""
Build the program and run until the breakpoint is hit, and return the stack frames.
"""
other_source_file = "other.c"
with delete_file_on_exit(other_source_file):
with open(other_source_file, "w") as f:
f.write(OTHER_C_SOURCE_CODE)
breakpoint_line = line_number(other_source_file, "// Break here")
program = self.getBuildArtifact("a.out")
self.build_and_launch(program, commandEscapePrefix="")
breakpoint_ids = self.set_source_breakpoints(
other_source_file, [breakpoint_line]
)
self.assertEqual(
len(breakpoint_ids), 1, "expect correct number of breakpoints"
)
self.continue_to_breakpoints(breakpoint_ids)
frames = self.get_stackFrames()
self.assertLessEqual(2, len(frames), "expect at least 2 frames")
self.assertIn(
"path",
frames[0]["source"],
"Expect source path to always be in frame (other.c)",
)
self.assertIn(
"path",
frames[1]["source"],
"Expect source path in always be in frame (main.c)",
)
return frames
def verify_frames_source(
self, frames, main_frame_assembly: bool, other_frame_assembly: bool
):
self.assertLessEqual(2, len(frames), "expect at least 2 frames")
source_0 = frames[0].get("source")
source_1 = frames[1].get("source")
self.assertIsNotNone(source_0, "Expects a source object in frame 0")
self.assertIsNotNone(source_1, "Expects a source object in frame 1")
# it does not always have a path.
source_0_path: str = source_0.get("path", "")
source_1_path: str = source_1.get("path", "")
if other_frame_assembly:
self.assertFalse(
source_0_path.endswith("other.c"),
"Expect original source path to not be in unavailable source frame (other.c)",
)
self.assertIn(
"sourceReference",
source_0,
"Expect sourceReference to be in unavailable source frame (other.c)",
)
else:
self.assertTrue(
source_0_path.endswith("other.c"),
"Expect original source path to be in normal source frame (other.c)",
)
self.assertNotIn(
"sourceReference",
source_0,
"Expect sourceReference to not be in normal source frame (other.c)",
)
if main_frame_assembly:
self.assertFalse(
source_1_path.endswith("main.c"),
"Expect original source path to not be in unavailable source frame (main.c)",
)
self.assertIn(
"sourceReference",
source_1,
"Expect sourceReference to be in unavailable source frame (main.c)",
)
else:
self.assertTrue(
source_1_path.endswith("main.c"),
"Expect original source path to be in normal source frame (main.c)",
)
self.assertNotIn(
"sourceReference",
source_1,
"Expect sourceReference to not be in normal source code frame (main.c)",
)
def test_stopDisassemblyDisplay(self):
"""
Test that with with all stop-disassembly-display values you get correct assembly / no assembly source code.
"""
self.build_and_run_until_breakpoint()
frames = self.get_stackFrames()
self.assertLessEqual(2, len(frames), "expect at least 2 frames")
self.assertIn(
"path",
frames[0]["source"],
"Expect source path to always be in frame (other.c)",
)
self.assertIn(
"path",
frames[1]["source"],
"Expect source path in always be in frame (main.c)",
)
self.dap_server.request_evaluate(
"settings set stop-disassembly-display never", context="repl"
)
frames = self.get_stackFrames()
self.verify_frames_source(
frames, main_frame_assembly=False, other_frame_assembly=False
)
self.dap_server.request_evaluate(
"settings set stop-disassembly-display always", context="repl"
)
frames = self.get_stackFrames()
self.verify_frames_source(
frames, main_frame_assembly=True, other_frame_assembly=True
)
self.dap_server.request_evaluate(
"settings set stop-disassembly-display no-source", context="repl"
)
frames = self.get_stackFrames()
self.verify_frames_source(
frames, main_frame_assembly=False, other_frame_assembly=True
)
self.dap_server.request_evaluate(
"settings set stop-disassembly-display no-debuginfo", context="repl"
)
frames = self.get_stackFrames()
self.verify_frames_source(
frames, main_frame_assembly=False, other_frame_assembly=False
)
|