-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb] Handle an empty SBMemoryRegionInfo from scripted process #115963
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
jasonmolenda
merged 6 commits into
llvm:main
from
jasonmolenda:detect-empty-sbmemoryregioninfo-reponses
Nov 15, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f8f1d70
[lldb] Handle an empty SBMemoryRegionInfo from scripted process
jasonmolenda 0e57707
Remove the clearly unnecessary parts from
jasonmolenda 403fe3d
Update patch to move the check for memory regions to
jasonmolenda aadf21d
Update error message.
jasonmolenda d4125c1
Change the test to be "returned region must contain addr"
jasonmolenda f79aa73
Ismail caught a logic error on my part, used a built-in method
jasonmolenda 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
3 changes: 3 additions & 0 deletions
3
lldb/test/API/functionalities/scripted_process_empty_memory_region/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,3 @@ | ||
| C_SOURCES := main.c | ||
|
|
||
| include Makefile.rules |
33 changes: 33 additions & 0 deletions
33
...ctionalities/scripted_process_empty_memory_region/TestScriptedProcessEmptyMemoryRegion.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,33 @@ | ||
| """ | ||
| Test python scripted process which returns an empty SBMemoryRegionInfo | ||
| """ | ||
|
|
||
| import os, shutil | ||
|
|
||
| import lldb | ||
| from lldbsuite.test.decorators import * | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test import lldbutil | ||
| from lldbsuite.test import lldbtest | ||
|
|
||
|
|
||
| class ScriptedProcessEmptyMemoryRegion(TestBase): | ||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def test_scripted_process_empty_memory_region(self): | ||
| """Test that lldb handles an empty SBMemoryRegionInfo object from | ||
| a scripted process plugin.""" | ||
| self.build() | ||
|
|
||
| target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) | ||
| self.assertTrue(target, VALID_TARGET) | ||
|
|
||
| scripted_process_example_relpath = "dummy_scripted_process.py" | ||
| self.runCmd( | ||
| "command script import " | ||
| + os.path.join(self.getSourceDir(), scripted_process_example_relpath) | ||
| ) | ||
|
|
||
| self.expect("memory region 0", error=True, substrs=["Invalid memory region"]) | ||
|
|
||
| self.expect("expr -- 5", substrs=["5"]) |
110 changes: 110 additions & 0 deletions
110
lldb/test/API/functionalities/scripted_process_empty_memory_region/dummy_scripted_process.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,110 @@ | ||
| import os, struct, signal | ||
|
|
||
| from typing import Any, Dict | ||
|
|
||
| import lldb | ||
| from lldb.plugins.scripted_process import ScriptedProcess | ||
| from lldb.plugins.scripted_process import ScriptedThread | ||
|
|
||
|
|
||
| class DummyScriptedProcess(ScriptedProcess): | ||
| memory = None | ||
|
|
||
| def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData): | ||
| super().__init__(exe_ctx, args) | ||
| self.threads[0] = DummyScriptedThread(self, None) | ||
| self.memory = {} | ||
| addr = 0x500000000 | ||
| debugger = self.target.GetDebugger() | ||
| index = debugger.GetIndexOfTarget(self.target) | ||
| self.memory[addr] = "Hello, target " + str(index) | ||
| self.handled_stop = False | ||
|
|
||
| def read_memory_at_address( | ||
| self, addr: int, size: int, error: lldb.SBError | ||
| ) -> lldb.SBData: | ||
| data = lldb.SBData().CreateDataFromCString( | ||
| self.target.GetByteOrder(), self.target.GetCodeByteSize(), self.memory[addr] | ||
| ) | ||
|
|
||
| return data | ||
|
|
||
| def get_memory_region_containing_address( | ||
| self, addr: int | ||
| ) -> lldb.SBMemoryRegionInfo: | ||
| return lldb.SBMemoryRegionInfo() | ||
|
|
||
| def write_memory_at_address(self, addr, data, error): | ||
| self.memory[addr] = data.GetString(error, 0) | ||
| return len(self.memory[addr]) + 1 | ||
|
|
||
| def get_loaded_images(self): | ||
| return self.loaded_images | ||
|
|
||
| def get_process_id(self) -> int: | ||
| return 42 | ||
|
|
||
| def should_stop(self) -> bool: | ||
| return True | ||
|
|
||
| def is_alive(self) -> bool: | ||
| return True | ||
|
|
||
| def get_scripted_thread_plugin(self): | ||
| return DummyScriptedThread.__module__ + "." + DummyScriptedThread.__name__ | ||
|
|
||
| def my_super_secret_method(self): | ||
| if hasattr(self, "my_super_secret_member"): | ||
| return self.my_super_secret_member | ||
| else: | ||
| return None | ||
|
|
||
|
|
||
| class DummyScriptedThread(ScriptedThread): | ||
| def __init__(self, process, args): | ||
| super().__init__(process, args) | ||
| self.frames.append({"pc": 0x0100001B00}) | ||
|
|
||
| def get_thread_id(self) -> int: | ||
| return 0x19 | ||
|
|
||
| def get_name(self) -> str: | ||
| return DummyScriptedThread.__name__ + ".thread-1" | ||
|
|
||
| def get_state(self) -> int: | ||
| return lldb.eStateStopped | ||
|
|
||
| def get_stop_reason(self) -> Dict[str, Any]: | ||
| return {"type": lldb.eStopReasonTrace, "data": {}} | ||
|
|
||
| def get_register_context(self) -> str: | ||
| return struct.pack( | ||
| "21Q", | ||
| 1, | ||
| 2, | ||
| 3, | ||
| 4, | ||
| 5, | ||
| 6, | ||
| 7, | ||
| 8, | ||
| 9, | ||
| 10, | ||
| 11, | ||
| 12, | ||
| 13, | ||
| 14, | ||
| 15, | ||
| 16, | ||
| 17, | ||
| 18, | ||
| 19, | ||
| 20, | ||
| 21, | ||
| ) | ||
|
|
||
|
|
||
| def __lldb_init_module(debugger, dict): | ||
| debugger.HandleCommand( | ||
| "process launch -C %s.%s" % (__name__, DummyScriptedProcess.__name__) | ||
| ) |
1 change: 1 addition & 0 deletions
1
lldb/test/API/functionalities/scripted_process_empty_memory_region/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 @@ | ||
| int main() {} |
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.
I believe in
range_info.GetRange().GetRangeBase() < load_addrthe sign should be inverted.You could use directly the
Range::{Contains, ContainsEndInclusive}instead ?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.
Ah, you did catch a mistake there, thanks. I was focusing on "lookup of 0, get back range start 0x0 size 0" and this check happens to work correctly for that, but this should be
(range_info.GetRange().GetRangeBase() < load_addr || range_info.GetRange().GetRangeEnd() >= load_addr).ContainsEndInclusiveisn't correct, but theContainsmethod is, good call.