-
Notifications
You must be signed in to change notification settings - Fork 15k
[lldb-dap] Handle stack frames without a module #136777
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 2 commits into
llvm:main
from
eronnen:lldb-dap-handle-frames-without-module
Apr 25, 2025
Merged
Changes from all commits
Commits
Show all changes
2 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
2 changes: 2 additions & 0 deletions
2
lldb/test/API/tools/lldb-dap/stackTraceMissingModule/Makefile
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,2 @@ | ||
C_SOURCES := main.c | ||
include Makefile.rules |
54 changes: 54 additions & 0 deletions
54
lldb/test/API/tools/lldb-dap/stackTraceMissingModule/TestDAP_stackTraceMissingModule.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,54 @@ | ||
""" | ||
Test lldb-dap stack trace when module is missing | ||
""" | ||
|
||
from lldbsuite.test.decorators import skipUnlessPlatform | ||
from lldbsuite.test.lldbtest import line_number | ||
import lldbdap_testcase | ||
import re | ||
|
||
|
||
class TestDAP_stackTraceMissingModule(lldbdap_testcase.DAPTestCaseBase): | ||
@skipUnlessPlatform(["linux"]) | ||
def test_missingModule(self): | ||
""" | ||
Test that the stack frame without a module still has assembly source. | ||
""" | ||
program = self.getBuildArtifact("a.out") | ||
self.build_and_launch(program, commandEscapePrefix="") | ||
|
||
source = "main.c" | ||
self.set_source_breakpoints( | ||
source, | ||
[line_number(source, "// Break here")], | ||
) | ||
self.continue_to_next_stop() | ||
|
||
# Evaluate expr -- func | ||
expr_result = self.dap_server.request_evaluate( | ||
expression="expr -f pointer -- func", | ||
context="repl", | ||
) | ||
|
||
expr_result_address = re.search( | ||
r"0x[0-9a-fA-F]+", expr_result["body"]["result"] | ||
) | ||
self.assertIsNotNone( | ||
expr_result_address, "Failed to get address of dynamic allocated func" | ||
) | ||
func_address = expr_result_address.group(0) | ||
|
||
self.dap_server.request_evaluate( | ||
expression=f"breakpoint set --address {func_address}", | ||
context="repl", | ||
) | ||
|
||
self.continue_to_next_stop() | ||
|
||
frame_without_module = self.get_stackFrames()[0] | ||
|
||
self.assertIn("line", frame_without_module, "Line number missing.") | ||
self.assertIn("column", frame_without_module, "Column number missing.") | ||
self.assertIn("source", frame_without_module, "Source location missing.") | ||
source = frame_without_module["source"] | ||
self.assertIn("sourceReference", source, "Source reference missing.") |
37 changes: 37 additions & 0 deletions
37
lldb/test/API/tools/lldb-dap/stackTraceMissingModule/main.c
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,37 @@ | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <sys/mman.h> | ||
#include <unistd.h> | ||
|
||
extern uint8_t __start_target_section[]; | ||
extern uint8_t __stop_target_section[]; | ||
|
||
__attribute__((used, section("target_section"))) int target_function(void) { | ||
return 42; | ||
} | ||
|
||
typedef int (*target_function_t)(void); | ||
|
||
int main(void) { | ||
size_t target_function_size = __stop_target_section - __start_target_section; | ||
size_t page_size = sysconf(_SC_PAGESIZE); | ||
size_t page_aligned_size = | ||
(target_function_size + page_size - 1) & ~(page_size - 1); | ||
|
||
void *executable_memory = | ||
mmap(NULL, page_aligned_size, PROT_READ | PROT_WRITE | PROT_EXEC, | ||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
if (executable_memory == MAP_FAILED) { | ||
perror("mmap"); | ||
return 1; | ||
} | ||
|
||
memcpy(executable_memory, __start_target_section, target_function_size); | ||
|
||
target_function_t func = (target_function_t)executable_memory; | ||
int result = func(); // Break here | ||
printf("Result from target function: %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
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.
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 still needs to be 1, this way it will be possible to debug the code in the IDE:
Screencast.From.2025-04-24.08-48-53.webm
The only annoying thing is that each step removes the previous assembly lines, but I couldn't think of a straightforward way to tackle it because the frame changes too in every step