Skip to content

Commit 7879ae3

Browse files
committed
Using '__attribute__((nodebug))' instead of a libc call to help verify stack frames without sources return disassembly.
1 parent c68deee commit 7879ae3

File tree

4 files changed

+56
-87
lines changed

4 files changed

+56
-87
lines changed

lldb/test/API/tools/lldb-dap/source/TestDAP_source.py

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212

1313
class TestDAP_source(lldbdap_testcase.DAPTestCaseBase):
1414
@skipIfWindows
15-
def test_stackTrace(self):
15+
def test_source(self):
1616
"""
1717
Tests the 'source' packet.
1818
"""
1919
program = self.getBuildArtifact("a.out")
2020
self.build_and_launch(program)
21-
source = "main.c"
22-
self.source_path = os.path.join(os.getcwd(), source)
23-
self.qsort_call = line_number(source, "qsort call")
21+
source = self.getSourcePath("main.c")
22+
breakpoint_line = line_number(source, "breakpoint")
2423

25-
lines = [self.qsort_call]
24+
lines = [breakpoint_line]
2625
breakpoint_ids = self.set_source_breakpoints(source, lines)
2726
self.assertEqual(
2827
len(breakpoint_ids), len(lines), "expect correct number of breakpoints"
@@ -35,38 +34,59 @@ def test_stackTrace(self):
3534

3635
(stackFrames, totalFrames) = self.get_stackFrames_and_totalFramesCount()
3736
frameCount = len(stackFrames)
38-
self.assertGreaterEqual(
39-
frameCount, 3, "verify we get frames from system librarys (libc qsort)"
40-
)
37+
self.assertGreaterEqual(frameCount, 3, "verify we got up to main at least")
4138
self.assertEqual(
4239
totalFrames,
4340
frameCount,
4441
"verify total frames returns a speculative page size",
4542
)
46-
expectedFrames = [
43+
wantFrames = [
44+
{
45+
"name": "handler",
46+
"line": 8,
47+
"source": {
48+
"name": "main.c",
49+
"path": source,
50+
"containsSourceReference": False,
51+
},
52+
},
4753
{
48-
"name": "comp",
49-
"line": 14,
50-
"sourceName": "main.c",
51-
"containsSourceReference": False,
54+
"name": "add",
55+
"source": {
56+
"name": "add",
57+
"path": program + "`add",
58+
"containsSourceReference": True,
59+
},
5260
},
53-
{"name": "qsort", "sourceName": "qsort", "containsSourceReference": True},
5461
{
5562
"name": "main",
56-
"line": 25,
57-
"sourceName": "main.c",
58-
"containsSourceReference": False,
63+
"line": 12,
64+
"source": {
65+
"name": "main.c",
66+
"path": source,
67+
"containsSourceReference": False,
68+
},
5969
},
6070
]
61-
for idx, expected in enumerate(expectedFrames):
62-
frame = stackFrames[idx]
63-
frame_name = self.get_dict_value(frame, ["name"])
64-
self.assertRegex(frame_name, expected["name"])
65-
source_name = self.get_dict_value(frame, ["source", "name"])
66-
self.assertRegex(source_name, expected["sourceName"])
67-
if expected["containsSourceReference"]:
71+
for idx, want in enumerate(wantFrames):
72+
got = stackFrames[idx]
73+
name = self.get_dict_value(got, ["name"])
74+
self.assertEqual(name, want["name"])
75+
76+
if "line" in want:
77+
line = self.get_dict_value(got, ["line"])
78+
self.assertEqual(line, want["line"])
79+
80+
wantSource = want["source"]
81+
source_name = self.get_dict_value(got, ["source", "name"])
82+
self.assertEqual(source_name, wantSource["name"])
83+
84+
source_path = self.get_dict_value(got, ["source", "path"])
85+
self.assertEqual(source_path, wantSource["path"])
86+
87+
if wantSource["containsSourceReference"]:
6888
sourceReference = self.get_dict_value(
69-
frame, ["source", "sourceReference"]
89+
got, ["source", "sourceReference"]
7090
)
7191
response = self.dap_server.request_source(
7292
sourceReference=sourceReference
@@ -75,12 +95,12 @@ def test_stackTrace(self):
7595
self.assertGreater(
7696
len(self.get_dict_value(response, ["body", "content"])),
7797
0,
78-
"verify content returned",
98+
"verify content returned disassembly",
7999
)
80100
self.assertEqual(
81101
self.get_dict_value(response, ["body", "mimeType"]),
82102
"text/x-lldb.disassembly",
83103
"verify mime type returned",
84104
)
85105
else:
86-
self.assertNotIn("sourceReference", frame["source"])
106+
self.assertNotIn("sourceReference", got["source"])
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
#include <stdio.h>
2-
#include <stdlib.h>
3-
#include <unistd.h>
42

5-
int comp(const void *first, const void *second) {
6-
const int a = *((const int *)first);
7-
const int b = *((const int *)second);
8-
if (a == b) // qsort call
9-
return 0;
10-
if (a > b)
11-
return 1;
12-
return -1;
3+
__attribute__((nodebug)) static void add(int i, int j, void handler(int)) {
4+
handler(i + j);
135
}
146

15-
int main(int argc, char const *argv[]) {
16-
int numbers[] = {4, 5, 2, 3, 1, 0, 9, 8, 6, 7};
17-
qsort(numbers, sizeof(numbers) / sizeof(int), sizeof(int), comp);
7+
static void handler(int result) {
8+
printf("result %d\n", result); // breakpoint
9+
}
1810

11+
int main(int argc, char const *argv[]) {
12+
add(2, 3, handler);
1913
return 0;
2014
}

lldb/test/API/tools/lldb-dap/stackTrace/TestDAP_stackTrace.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ def test_stackTrace(self):
6969
self.recurse_end = line_number(source, "recurse end")
7070
self.recurse_call = line_number(source, "recurse call")
7171
self.recurse_invocation = line_number(source, "recurse invocation")
72-
self.qsort_call = line_number(source, "qsort call")
7372

74-
lines = [self.recurse_end, self.qsort_call]
73+
lines = [self.recurse_end]
7574

7675
# Set breakpoint at a point of deepest recuusion
7776
breakpoint_ids = self.set_source_breakpoints(source, lines)
@@ -196,43 +195,14 @@ def test_stackTrace(self):
196195
)
197196
self.verify_stackFrames(startFrame, stackFrames)
198197

199-
# Verify we do not recive frames when startFrame is out of range
198+
# Verify we get not frames when startFrame is too high
200199
startFrame = 1000
201200
levels = 1
202201
stackFrames = self.get_stackFrames(startFrame=startFrame, levels=levels)
203202
self.assertEqual(
204203
0, len(stackFrames), "verify zero frames with startFrame out of bounds"
205204
)
206205

207-
# Verify a stack frame from an external library (libc`qsort) to ensure
208-
# frames without source code return a valid source reference.
209-
self.continue_to_breakpoints(breakpoint_ids)
210-
(stackFrames, totalFrames) = self.get_stackFrames_and_totalFramesCount()
211-
frameCount = len(stackFrames)
212-
self.assertGreaterEqual(
213-
frameCount, 3, "verify we get frames from system librarys (libc qsort)"
214-
)
215-
self.assertEqual(
216-
totalFrames,
217-
frameCount,
218-
"verify total frames returns a speculative page size",
219-
)
220-
221-
frame = stackFrames.pop(0)
222-
frame_name = self.get_dict_value(frame, ["name"])
223-
self.assertRegex(frame_name, 'comp')
224-
self.assertEqual(self.get_dict_value(frame, ['line']), 14)
225-
self.assertNotIn('sourceReference', frame['source'])
226-
227-
# libc`qsort may not be the first frame below comp, search upwards
228-
found_qsort = False
229-
for frame in stackFrames:
230-
if 'qsort' not in frame['name']:
231-
continue
232-
found_qsort = True
233-
self.assertIn("sourceReference", frame["source"])
234-
self.assertTrue(found_qsort, 'verify we found the qsort frame')
235-
236206
@skipIfWindows
237207
def test_functionNameWithArgs(self):
238208
"""
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <stdio.h>
2-
#include <stdlib.h>
32
#include <unistd.h>
43

54
int recurse(int x) {
@@ -8,21 +7,7 @@ int recurse(int x) {
87
return recurse(x - 1) + x; // recurse call
98
}
109

11-
int comp(const void *first, const void *second) {
12-
const int a = *((const int *)first);
13-
const int b = *((const int *)second);
14-
if (a == b) // qsort call
15-
return 0;
16-
if (a > b)
17-
return 1;
18-
return -1;
19-
}
20-
2110
int main(int argc, char const *argv[]) {
2211
recurse(40); // recurse invocation
23-
24-
int numbers[] = {4, 5, 2, 3, 1, 0, 9, 8, 6, 7};
25-
qsort(numbers, sizeof(numbers) / sizeof(int), sizeof(int), comp);
26-
2712
return 0;
2813
}

0 commit comments

Comments
 (0)