-
-
Notifications
You must be signed in to change notification settings - Fork 24
Multiple bps #175
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
Open
io-no
wants to merge
13
commits into
single-thread-control-flow
Choose a base branch
from
multiple-bps
base: single-thread-control-flow
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Multiple bps #175
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f017092
doc: docstring was not correct
io-no ad0da82
feat: introduced BreakpointList
io-no 09b2999
feat: first, working implementation of multiple bps at the same address
io-no 432f461
fix: now disable works correctly when multiple bps are installed
io-no 442fb0a
test: added test for multiple sw bps
io-no 1653018
fix: now the entry point hw bp is correctly disabled
io-no 67a326f
refactor: install instead of register for bp
io-no 783231e
fix: now hw and sw bp at the same location should be better managed
io-no 7e33d28
refactor: code rationalization
io-no 8898cff
test: added test on cohesistent multiple bps both hw and sw
io-no d746923
refactor: unused imports
io-no 2cc3079
feat: thread scoped breakpoints list
io-no ea6004e
test: added test on thread-scoped breakpoints list
io-no 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
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,87 @@ | ||
| # | ||
| # This file is part of libdebug Python library (https://github.com/libdebug/libdebug). | ||
| # Copyright (c) 2024 Gabriele Digregorio. All rights reserved. | ||
| # Licensed under the MIT license. See LICENSE file in the project root for details. | ||
| # | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from libdebug.data.breakpoint import Breakpoint | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable | ||
|
|
||
| from libdebug.state.thread_context import ThreadContext | ||
|
|
||
|
|
||
| class BreakpointList(list): | ||
| """A list of breakpoints installed at the same address in the target process. | ||
|
|
||
| Attributes: | ||
| address (int): The address of the breakpoints installed in the target process. | ||
| symbol (str): The symbol, if available, of the breakpoints installed in the target process. | ||
| hit_count (int): The sum of the hit counts of all the breakpoints inside the BreakpointList. | ||
| callback list[Callable[[ThreadContext, Breakpoint], None]]: The list of callbacks defined by the user to execute when the breakpoints are hit. | ||
| enabled (bool): Whether at least one of the breakpoints is enabled or not. | ||
| """ | ||
|
|
||
| address: int = 0 | ||
| symbol: str = "" | ||
|
|
||
| def __init__(self: BreakpointList, breakpoints: list[Breakpoint], address: int, symbol: str) -> None: | ||
| """Initializes the BreakpointList.""" | ||
| self.address = address | ||
| self.symbol = symbol | ||
| super().__init__(breakpoints) | ||
|
|
||
| @property | ||
| def hit_count(self: BreakpointList) -> int: | ||
| """Returns the sum of the hit counts of all the breakpoints inside the BreakpointList.""" | ||
| return sum(bp.hit_count for bp in self) | ||
|
|
||
| @property | ||
| def callback(self: BreakpointList) -> list[Callable[[ThreadContext, Breakpoint], None]]: | ||
| """Returns the list of callbacks defined by the user to execute when the breakpoints are hit.""" | ||
| return [bp.callback for bp in self] | ||
|
|
||
| @property | ||
| def enabled(self: BreakpointList) -> bool: | ||
|
Member
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. Do we want to set enabled on the list to enable all or disable all breakpoints at that address? If not, I would rename this property to avoid confusion (because of the symmetry with the property of the breakpoint object itself). |
||
| """Returns whether at least one of the breakpoints is enabled or not.""" | ||
| return any(bp.enabled for bp in self) | ||
|
|
||
| def filter(self: BreakpointList, **kwargs: dict[str, object]) -> BreakpointList: | ||
| """Filters the breakpoints according to the specified Breakpoint attributes. | ||
|
|
||
| Args: | ||
| **kwargs: The arguments to filter the breakpoints. It can be any Breakpoint attribute. | ||
|
|
||
| Returns: | ||
| BreakpointList[Breakpoint]: The list of breakpoints installed in the specified thread and/or with the specified condition. | ||
| """ | ||
| if not kwargs: | ||
| return self | ||
|
|
||
| filtered_breakpoints = self | ||
| for key, value in kwargs.items(): | ||
| if key not in Breakpoint.__annotations__: | ||
| raise ValueError(f"Invalid attribute: {key} is not a valid Breakpoint attribute") | ||
| if key == "thread_id": | ||
| filtered_breakpoints = [bp for bp in filtered_breakpoints if bp.thread_id in (value, -1)] | ||
| else: | ||
| filtered_breakpoints = [bp for bp in filtered_breakpoints if getattr(bp, key) == value] | ||
|
|
||
| return BreakpointList(filtered_breakpoints, self.address, self.symbol) | ||
|
|
||
| def __hash__(self) -> int: | ||
| """Return the hash of the symbol list.""" | ||
| return hash(id(self)) | ||
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| """Check if the symbol list is equal to another object.""" | ||
| return super().__eq__(other) | ||
|
|
||
| def __repr__(self: BreakpointList) -> str: | ||
| """Returns the string representation of the BreakpointList without the default factory.""" | ||
| return f"BreakpointList({super().__repr__()})" | ||
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
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.
This would multiply the hit count for the number of superimposed breakpoints... Is this really what we want?