-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb-dap] fix wrong assembly line number x64 #136486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JDevlieghere
merged 3 commits into
llvm:main
from
eronnen:lldb-dap-fix-wrong-assembly-line-x64
Apr 25, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
C_SOURCES := main.c | ||
|
||
include Makefile.rules |
65 changes: 65 additions & 0 deletions
65
lldb/test/API/tools/lldb-dap/stackTrace-x86/TestDAP_source_x86.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
Test lldb-dap stack trace containing x86 assembly | ||
""" | ||
|
||
import lldbdap_testcase | ||
from lldbsuite.test import lldbplatformutil | ||
from lldbsuite.test.decorators import skipUnlessArch, skipUnlessPlatform | ||
from lldbsuite.test.lldbtest import line_number | ||
|
||
|
||
class TestDAP_stacktrace_x86(lldbdap_testcase.DAPTestCaseBase): | ||
@skipUnlessArch("x86_64") | ||
@skipUnlessPlatform(["linux"] + lldbplatformutil.getDarwinOSTriples()) | ||
def test_stacktrace_x86(self): | ||
""" | ||
Tests that lldb-dap steps through correctly and the source lines are correct in x86 assembly. | ||
""" | ||
program = self.getBuildArtifact("a.out") | ||
self.build_and_launch( | ||
program, | ||
initCommands=[ | ||
"settings set target.process.thread.step-in-avoid-nodebug false" | ||
], | ||
) | ||
|
||
source = "main.c" | ||
breakpoint_ids = self.set_source_breakpoints( | ||
source, | ||
[line_number(source, "// Break here")], | ||
) | ||
self.continue_to_breakpoints(breakpoint_ids) | ||
self.stepIn() | ||
|
||
frame = self.get_stackFrames()[0] | ||
self.assertEqual( | ||
frame["name"], | ||
"no_branch_func", | ||
"verify we are in the no_branch_func function", | ||
) | ||
|
||
self.assertEqual(frame["line"], 1, "verify we are at the start of the function") | ||
minimum_assembly_lines = ( | ||
line_number(source, "Assembly end") | ||
- line_number(source, "Assembly start") | ||
+ 1 | ||
) | ||
self.assertLessEqual( | ||
10, | ||
minimum_assembly_lines, | ||
"verify we have a reasonable number of assembly lines", | ||
) | ||
|
||
for i in range(2, minimum_assembly_lines): | ||
self.stepIn() | ||
frame = self.get_stackFrames()[0] | ||
self.assertEqual( | ||
frame["name"], | ||
"no_branch_func", | ||
"verify we are still in the no_branch_func function", | ||
) | ||
self.assertEqual( | ||
frame["line"], | ||
i, | ||
f"step in should advance a single line in the function to {i}", | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
|
||
__attribute__((nodebug)) int no_branch_func(void) { | ||
int result = 0; | ||
|
||
__asm__ __volatile__("movl $0, %%eax;" // Assembly start | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"incl %%eax;" | ||
"movl %%eax, %0;" // Assembly end | ||
: "=r"(result) | ||
: | ||
: "%eax"); | ||
|
||
return result; | ||
} | ||
|
||
int main(void) { | ||
int result = no_branch_func(); // Break here | ||
printf("Result: %d\n", result); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we explicitly step with
granularity='instruction'
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be the same because it's a function without debug symbols so each step should execute one assembly instruction