-
Notifications
You must be signed in to change notification settings - Fork 24
Added Conditional Breakpoint Support #941
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
base: dev
Are you sure you want to change the base?
Conversation
…ems, and return type for `get_breakpoint_condition`
…dresses (new fallback to address comparison and VA comparisons)
…consistency issues
… + context menu additions) Co-authored-by: AdamR05 <215697996+AdamR05@users.noreply.github.com>
…on change events Co-authored-by: AdamR05 <215697996+AdamR05@users.noreply.github.com>
…t code Co-authored-by: AdamR05 <215697996+AdamR05@users.noreply.github.com>
|
Hi @3rdit I will review this ASAP and let you know what I think For context, I am working on a different PR that adds hardware breakpoint #53. And in light of the hardware breakpoint, I plan to make another large refactor on the breakpoint handling, e.g., the added breakpoints will be referred to by their index, not their address, etc. This would mean some non-trivial merge conflict in the future. However, I hope to minimize the frictions for you as you are doing these all for free. I will most likely review and merge your PR first, and brace for the merge conflicts on my branch. Hopefully that will be manageable |
core/debuggerstate.h
Outdated
| DebuggerState* m_state; | ||
| std::vector<ModuleNameAndOffset> m_breakpoints; | ||
| std::map<ModuleNameAndOffset, bool> m_enabledState; | ||
| std::map<ModuleNameAndOffset, std::string> m_conditions; |
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 am not a big fan of m_conditions here. I know you are copying the m_enabledState pattern, but that is really just a quick and dirty way to add "enable/disable" breakpoint into the product without a full refactor (a refactor on the breakpoint is already planned, but we wanted to slip that feature into the debugger before the refactor lands).
Ideally we would want something like this
struct Breakpoint {
ModuleNameAndOffset address;
bool enabled = true;
std::string condition;
};
which is apparently better in terms of how to keep things more organized. I will make a decision on whether or not to integrate the refactor with this PR
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 like this idea. I've followed your code patterns to keep it all consistent.
I've refactored the three separate variables into a BreakpointEntry struct (named to avoid a conflict with the enum) stored in a single vector. FindBreakpoint will now return an iterator directly to avoid redundant lookups when modifying or erasing entries. This reduces complexity in the lookups/logic and should make your planned refactor easier to do.
|
@3rdit I have a look at the code today and it looks good to me in general. I also did functionality tests and it works like a charm. I will see how the unit test goes Most likely I will take over this PR and make some changes to it, and then merge it. I will keep you posted. Thanks again for the contribution! |
PR Overview
This PR adds conditional breakpoint support to the debugger, allowing a user to specify expressions that must evaluate to true for the breakpoint to actually trigger. This is implemented at the debugger core level (not adapter level), so it works the same across all adapters.
As discussed with @xusheng6:
The conditions for breakpoints are written using the expression parser (i.e.
$rax == 0) making it the exact same for each debugger. The API now has:SetBreakpointCondition(),GetBreakpointCondition()on DebuggerControllerset_breakpoint_condition(),get_breakpoint_condition()For example:
In the breakpoint widget, there's a new "Condition" column that can be set by right-clicking and pressing "Edit Condition...", this works in the widget and disassembly view.
The condition is also persistent across sessions (saved to the binary view metadata).
Upcoming Changes
Condition validation on the input dialog; the idea being to stop users from entering invalid expressions(this is tricky to add due to the way the expression parser works, not going to do this)It makes sense to have some sort of unit testing for this. I reviewed the unit testing and noticed how breakpoints get tested indebugger_test.py, it would be trivial to add a quick unit test for conditions.This PR will close #93 and maybe close #422 (if the feature above is approved to be added in this PR).