Skip to content
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

Debugger: Implement base code tracing logic. and feature to auto-step through code. #10771

Merged
merged 1 commit into from Nov 4, 2022

Conversation

TryTwo
Copy link
Contributor

@TryTwo TryTwo commented Jun 21, 2022

Adds CodeTrace file and two "simple" uses for it: Auto-stepping through code to track a value from the PC, and register widget auto-stepping until a target register appears.

When right-clicking PC in codeview, new options appear. Operates on target (left-most) register in instruction. Tracks the target value, not just the register, so tracking can hop to another register or memory if the value is shuffled there. May track multiple registers at once if the value is duplicated.

AutoStep2

  • Run until target value is hit: Simply autostep until target appears again.
  • Added run until hit for the register widget as well. Runs the code until the selected register appears.
  • Run until target value is used: Silently tracks target register's value through load/store/moves until it is used (pointer, comparison, math, etc).
  • Run until target value is updated: Same as above, but only stops when the value is modified.

It can timeout if it takes too long, but will give you the option to keep going. When you get a hit, you can keep all the registers/memory that contains the value loaded, and continue tracking. The pop-up window will trap focus so the option to continue running isn't invalidated by performing actions outside the pop-up, which is a little annoying..

Mainly designed for a target value being shuffled through temp memory and registers for thousands of lines of code before being used. I've spent hours manually tracking values through code and memory load/stores, but this does it in a few clicks.

Part of my incremental effort to work up to my old code trace PR #8838. I thought this would be a smaller step, but it turned out to require more effort and code than I originally intended. If the codetrace.cpp is more verbose than expected, it's to prepare for the ability to record and search what happened in a codetrace widget, if I get that finished. I also left out backtracing logic, because it can't be used in auto-stepping, but I could re-include it just so the codetrace file is more complete.

Not sure if codetrace.cpp is in the correct folder.
Limited support for PS and various specialized instructions.
The tiny function IsInstructionLoadStore shows up in the codeview widget as well, not sure if I should point them all to one place.

Copy link
Contributor

@sepalani sepalani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very brief review regarding the code. I still have to take a look at the auto-stepping logic and give this PR a try.

Source/Core/DolphinQt/Debugger/RegisterWidget.h Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/RegisterWidget.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
@TryTwo
Copy link
Contributor Author

TryTwo commented Jun 22, 2022

If I should be worried about unintentional logic changes, or if someone wants to test various versions, I can re-push with the update split into a second commit.

@TryTwo
Copy link
Contributor Author

TryTwo commented Jul 3, 2022

Rebase. I changed the register autostep context menu a little. Before you had to click on the column that lists registers, but now you have to click on the data columns. I think it's more inline with how the menu system is setup. It's a little annoying to get the actual register (r12 for example).

If there's some way I can rewrite the logic to be more clear, let me know. Not sure if I should setup some kind of switch for it.

@sepalani
Copy link
Contributor

sepalani commented Sep 3, 2022

@TryTwo
When you have the time, do you mind to rebase this PR please?

Source/Core/DolphinQt/Debugger/RegisterWidget.h Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/RegisterWidget.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/DolphinLib.props Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
@TryTwo
Copy link
Contributor Author

TryTwo commented Sep 5, 2022

Thanks for taking the time to review! I think I cleaned up the AutoStep returns quite a bit.

Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@sepalani sepalani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems to work as intended. This feature ignores instruction and memory breakpoints which is a bug/feature? similar to the Step Out function. You might want to rename both menu to Run until (and ignore breakpoints) to make this intent explicit.

Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.h Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/RegisterWidget.cpp Outdated Show resolved Hide resolved
@TryTwo
Copy link
Contributor Author

TryTwo commented Sep 27, 2022

Thanks for all the work on reviewing this!

About breakpoints. It's a bit mixed. Would someone want to know the location of the value they are tracking when at an arbitrary code line with a BP? Secondly, would running into breakpoints that aren't relevant be annoying? You might have to juggle breakpoints if they are triggered.

@TryTwo TryTwo force-pushed the PR_AutoStep branch 3 times, most recently from ab045a2 to 5dfdbee Compare September 28, 2022 00:39
@TryTwo
Copy link
Contributor Author

TryTwo commented Sep 28, 2022

I added the register in question to the menu item. It had an added bonus of letting me filter out code lines that won't work with the autostep ("mtctr r3" for example has no comma in it, so would produce an empty QString, which would disable the menu as there's no target to list).

@sepalani
Copy link
Contributor

About breakpoints. It's a bit mixed. Would someone want to know the location of the value they are tracking when at an arbitrary code line with a BP? Secondly, would running into breakpoints that aren't relevant be annoying? You might have to juggle breakpoints if they are triggered.

While I don't have a stance whether which behaviour should be preferred (that's why I referred to it as a bug/feature?), I do think it's important to make its behaviour clear for the user as it's currently not obvious. That's why it should be written somewhere that (instruction/memory) breakpoints are ignored.

A user might be looking for several states update at the same time using memory BPs. Using this new feature Run until might throw the user off guard if they expected this feature to be stopped by a (M)BP.

@TryTwo
Copy link
Contributor Author

TryTwo commented Sep 29, 2022

If I wanted to check breakpoints, do you think building a list of addresses that are active (M)BPs and then checking against that list would be good?

@sepalani
Copy link
Contributor

I'd rather have this kind of feature added in a follow-up PR, that's why I was suggesting to just change the text.

Ideally, we'd need proper functions to be exposed to know if Step/StepIn/StepOut function succeeded and if a (M)BP was hit. Then, we'd need a function exposed from PowerPC to run the code until some conditions happen. That way we could have both, one ignoring BP and one which doesn't. Something similar to what some debuggers did, like VS with Run To Cursor / Force Run To Cursor.

@TryTwo
Copy link
Contributor Author

TryTwo commented Sep 30, 2022

Rebased. Added the "Run until (ignoring breakpoints)" to code and register widget.

Copy link
Contributor

@sepalani sepalani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside these, LGTM.

Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
trace.AutoStepping(true);
emit Host::GetInstance()->UpdateDisasmDialog();

// Could add timed out popup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of AutoStepping isn't checked and we don't have any way to know if it succeeded or not. Can't the method in CodeViewWidget be refactored and used here? Maybe in a member function of the CodeTrace class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tacked the register autostep on as a quick way to navigate to a register in CodeView. I can check for an error message, but I don't think it's necessary for succeeding.

Not sure what I would put in a CodeTrace member function to share the logic. I don't think I can do any Qt stuff in CodeTrace, since it's not a widget. Open to suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point regarding Qt stuff, I can't think of anything pretty either. What you've currently implemented instead sounds mostly fine.

Copy link
Contributor

@sepalani sepalani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpicks regarding the code.

Source/Core/DolphinQt/Debugger/RegisterWidget.cpp Outdated Show resolved Hide resolved
Source/Core/Common/Debug/CodeTrace.cpp Outdated Show resolved Hide resolved
…egister breakpoints. Add CodeViewWidget autostepping to track a value.Debugger
Copy link
Contributor

@sepalani sepalani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and LGTM.

trace.AutoStepping(true);
emit Host::GetInstance()->UpdateDisasmDialog();

// Could add timed out popup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point regarding Qt stuff, I can't think of anything pretty either. What you've currently implemented instead sounds mostly fine.

@AdmiralCurtiss AdmiralCurtiss merged commit 431301a into dolphin-emu:master Nov 4, 2022
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants