-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[debugserver] Implement MultiMemRead packet #162670
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
felipepiovezan
merged 3 commits into
llvm:main
from
felipepiovezan:felipe/multimem_debugserver_impl
Oct 15, 2025
Merged
Changes from 2 commits
Commits
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 |
98 changes: 98 additions & 0 deletions
98
lldb/test/API/macosx/debugserver-multimemread/TestDebugserverMultiMemRead.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,98 @@ | ||
""" | ||
Tests debugserver support for MultiMemRead. | ||
""" | ||
|
||
import lldb | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
@skipUnlessDarwin | ||
@skipIfOutOfTreeDebugserver | ||
class TestCase(TestBase): | ||
def send_process_packet(self, packet_str): | ||
self.runCmd(f"proc plugin packet send {packet_str}", check=False) | ||
# The output is of the form: | ||
# packet: <packet_str> | ||
# response: <response> | ||
reply = self.res.GetOutput().split("\n") | ||
packet = reply[0].strip() | ||
response = reply[1].strip() | ||
|
||
self.assertTrue(packet.startswith("packet: ")) | ||
self.assertTrue(response.startswith("response: ")) | ||
return response[len("response: ") :] | ||
|
||
def check_invalid_packet(self, packet_str): | ||
reply = self.send_process_packet("packet_str") | ||
self.assertEqual(reply, "E03") | ||
|
||
def test_packets(self): | ||
self.build() | ||
source_file = lldb.SBFileSpec("main.c") | ||
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( | ||
self, "break here", source_file | ||
) | ||
|
||
reply = self.send_process_packet("qSupported") | ||
self.assertIn("MultiMemRead+", reply) | ||
|
||
mem_address_var = thread.frames[0].FindVariable("memory") | ||
self.assertTrue(mem_address_var) | ||
mem_address = mem_address_var.GetValueAsUnsigned() + 42 | ||
|
||
# no ":" | ||
self.check_invalid_packet("MultiMemRead") | ||
# missing ranges | ||
self.check_invalid_packet("MultiMemRead:") | ||
# needs at least one range | ||
self.check_invalid_packet("MultiMemRead:ranges:") | ||
# needs at least one range | ||
self.check_invalid_packet("MultiMemRead:ranges:,") | ||
# a range is a pair of numbers | ||
self.check_invalid_packet("MultiMemRead:ranges:10") | ||
# a range is a pair of numbers | ||
self.check_invalid_packet("MultiMemRead:ranges:10,") | ||
# range list must end with ; | ||
self.check_invalid_packet("MultiMemRead:ranges:10,2") | ||
self.check_invalid_packet("MultiMemRead:ranges:10,2,") | ||
self.check_invalid_packet("MultiMemRead:ranges:10,2,3") | ||
# ranges are pairs of numbers. | ||
self.check_invalid_packet("MultiMemRead:ranges:10,2,3;") | ||
# unrecognized field | ||
self.check_invalid_packet("MultiMemRead:ranges:10,2;blah:;") | ||
# unrecognized field | ||
self.check_invalid_packet("MultiMemRead:blah:;ranges:10,2;") | ||
|
||
# This is a valid way of testing for MultiMemRead support | ||
reply = self.send_process_packet("MultiMemRead:ranges:0,0;") | ||
self.assertEqual(reply, "0;") | ||
# Debugserver is permissive with trailing commas. | ||
reply = self.send_process_packet("MultiMemRead:ranges:10,2,;") | ||
self.assertEqual(reply, "0;") | ||
reply = self.send_process_packet("MultiMemRead:ranges:10,2;") | ||
self.assertEqual(reply, "0;") | ||
Comment on lines
72
to
79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should read from the real address so we know the 0 is not a mistake, or perhaps a better idea, add another read from the real address that has a trailing comma. |
||
reply = self.send_process_packet(f"MultiMemRead:ranges:{mem_address:x},0;") | ||
self.assertEqual(reply, "0;") | ||
reply = self.send_process_packet(f"MultiMemRead:ranges:{mem_address:x},2;") | ||
self.assertEqual(reply, "2;ab") | ||
reply = self.send_process_packet( | ||
f"MultiMemRead:ranges:{mem_address:x},2,{mem_address+2:x},4;" | ||
) | ||
self.assertEqual(reply, "2,4;abcdef") | ||
reply = self.send_process_packet( | ||
f"MultiMemRead:ranges:{mem_address:x},2,{mem_address+2:x},4,{mem_address+6:x},8;" | ||
) | ||
self.assertEqual(reply, "2,4,8;abcdefghijklmn") | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Test zero length in the middle. | ||
reply = self.send_process_packet( | ||
f"MultiMemRead:ranges:{mem_address:x},2,{mem_address+2:x},0,{mem_address+6:x},8;" | ||
) | ||
self.assertEqual(reply, "2,0,8;abghijklmn") | ||
# Test zero length in the end. | ||
reply = self.send_process_packet( | ||
f"MultiMemRead:ranges:{mem_address:x},2,{mem_address+2:x},4,{mem_address+6:x},0;" | ||
) | ||
self.assertEqual(reply, "2,4,0;abcdef") |
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,14 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
int main(int argc, char **argv) { | ||
char *memory = malloc(1024); | ||
memset(memory, '-', 1024); | ||
// Write "interesting" characters at an offset from the memory filled with | ||
// `-`. This way, if we read outside the range in either direction, we should | ||
// find `-`s`. | ||
int offset = 42; | ||
for (int i = offset; i < offset + 14; i++) | ||
memory[i] = 'a' + (i - offset); | ||
return 0; // break here | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.