Skip to content

Commit c002260

Browse files
committed
add x86 tests that verifies lldb-dap steps correctly through assembly
1 parent 5cb1442 commit c002260

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
3+
include Makefile.rules
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Test lldb-dap stack trace containing x86 assembly
3+
"""
4+
5+
import lldbdap_testcase
6+
from lldbsuite.test.decorators import skipUnlessArch, skipUnlessPlatform
7+
from lldbsuite.test.lldbtest import line_number
8+
9+
10+
class TestDAP_stacktrace_x86(lldbdap_testcase.DAPTestCaseBase):
11+
@skipUnlessArch("x86_64")
12+
@skipUnlessPlatform(["linux"])
13+
def test_stacktrace_x86(self):
14+
"""
15+
Tests that lldb-dap steps through correctly and the source lines are correct in x86 assembly.
16+
"""
17+
program = self.getBuildArtifact("a.out")
18+
self.build_and_launch(
19+
program,
20+
initCommands=[
21+
"settings set target.process.thread.step-in-avoid-nodebug false"
22+
],
23+
)
24+
25+
source = "main.c"
26+
breakpoint_ids = self.set_source_breakpoints(
27+
source,
28+
[line_number(source, "// Break here")],
29+
)
30+
self.continue_to_breakpoints(breakpoint_ids)
31+
self.stepIn()
32+
33+
frame = self.get_stackFrames()[0]
34+
self.assertEqual(
35+
frame["name"],
36+
"no_branch_func",
37+
"verify we are in the no_branch_func function",
38+
)
39+
40+
self.assertEqual(frame["line"], 1, "verify we are at the start of the function")
41+
minimum_assembly_lines = (
42+
line_number(source, "Assembly end")
43+
- line_number(source, "Assembly start")
44+
+ 1
45+
)
46+
47+
for i in range(2, minimum_assembly_lines):
48+
self.stepIn()
49+
frame = self.get_stackFrames()[0]
50+
self.assertEqual(
51+
frame["name"],
52+
"no_branch_func",
53+
"verify we are still in the no_branch_func function",
54+
)
55+
self.assertEqual(
56+
frame["line"],
57+
i,
58+
f"step in should advance a single line in the function to {i}",
59+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
3+
__attribute__((nodebug)) int no_branch_func(void) {
4+
int result = 0;
5+
6+
__asm__ __volatile__("movl $0, %%eax;" // Assembly start
7+
"incl %%eax;"
8+
"incl %%eax;"
9+
"incl %%eax;"
10+
"incl %%eax;"
11+
"incl %%eax;"
12+
"incl %%eax;"
13+
"incl %%eax;"
14+
"incl %%eax;"
15+
"incl %%eax;"
16+
"incl %%eax;"
17+
"movl %%eax, %0;" // Assembly end
18+
: "=r"(result)
19+
:
20+
: "%eax");
21+
22+
return result;
23+
}
24+
25+
int main(void) {
26+
int result = no_branch_func(); // Break here
27+
printf("Result: %d\n", result);
28+
return 0;
29+
}

0 commit comments

Comments
 (0)