-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: Overhaul symbol table parsing (add .mdebug and .sndata support) and add inspector GUI for complex data types #10224
Conversation
I don't know if anybody else agrees, but is there any reason this couldn't be in the debugger? I feel like they are kind of doing similar jobs since we have function symbols in there, and it would be nice to be able to right click on a variable and do "Go to in memory view" etc, all these features just feel like they would be at home as part of the debugger, rather than a separate screen. Great features though! Edit: just to clarify what I was thinking, if it was have it as a tab or something, so it doesn't add extra clutter to the debugger, not all of it on one screen, that might be a bit much! |
There isn't any particular reason, especially now memory consumption is down a lot. That said, I wanted to focus on getting the functionality working first, then worry about integrating it with the existing debugger window. If anyone has more specific design ideas, certainly feel free to suggest them. One constraint I have is that I think the watch window should at least be accessible alongside the rest of the debugger, so people can observe how values change as they step through code, just like with a regular GUI debugger. I think having it as a tab at the bottom would make sense, maybe with the option to pop it out as its own window. Perhaps Qt Dock Widgets or KDDockWidgets would make sense here? |
Yeah no worries. I believe Fobes was thinking about changing the debugger so it was separate (docked?) windows, because the debugger is a bit cramped, so it would be nice to split it out, but I want expecting you to go that far with scope lol |
Got the stack tab working, with some caveats. The biggest issue is that for some functions the live ranges seem to be invalid. It should be possible to display the values of parameters as well as locals, although the registers stored in the symbol table seem to be the registers used in the body of the function, not the prologue, so maybe there's something to be done there to make that more user friendly if you just break on the first instruction of a function. |
Some further thoughts about integrating this with the debugger window: One challenge I see is how we're going to approach the multiple sources of truth that are the two different symbol tables. I see two different approaches to deal with this:
The latter would probably be cleaner, although also more invasive. |
I agree the latter sounds like a better option, try to keep the symbols unique, we don't really want multiple sources of truth if we can help it, but this is going to be true if it's integrated with the debugger or not. |
Little update: I'm still working on this. Building the new data structures and porting my existing code to use them is taking some time. I'll copy it all into this PR when it's all relatively stable. |
This is finally ready for review and testing. Take as long as you want, I'm aware it's ballooned in scope quite a lot. |
Couple things I've found while giving it a more thorough test:
Just wanted to give a heads up on these. Edit: All mentioned issues are now resolved, great work! |
The earlier issue I was having with Fatal Frame 1 is resolved. |
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.
All issues I ran into are resolved. LGTM, haven't found any new issues. 👍
Great work on this
I have actually found another issue, a recent regression with Edit: These issues have been fixed. |
That should be all the issues found so far sorted. I want all the people who regularly work on the debugger to have a look through the symbol guardian/symbol database stuff to make sure it's to their satisfaction. As for the Okami thing, it looks like the game's symbol table is obfuscated so there's nothing to be done. |
Aand of course there were more bugs, which are now fixed. I'll continue playing about with it to see I can find any more. |
I've been thinking, and I've come to the conclusion that the current design for the SymbolGuardian class is unnecessarily complicated. Specifically how the worker thread that loads the symbol table(s) takes a lock on the symbol database for that entire duration, which leads to there being TryRead/BlockingRead/TryReadWrite/BlockingReadWrite functions, which are probably not all required. A better design would be to build the symbol table in a separate SymbolDatabase object and then merge them at the end. I think I strayed away from this originally because I thought it would cause problems with conflicting symbol handles, but I've come up with a solution to that: Make the ccc::SymbolList<>::m_next_handle member variables So far all the changes made since I said the PR was ready for review were fairly minor, although if this PR is going to take a long time to review anyway I think I may as well make the improvements immediately. I haven't thought through how exactly all the aspects of this will work, I just want to get this down for now. |
Is it possible to squash the commits down into a smaller number? For example, one to add the new demangler, another to swap over to it, etc. It's quite difficult to review 252 commits over hundreds of files, and it's also not rebase-mergeable (which is our preferred technique). |
I'll look into that, although I'll have to learn more about rebasing first. I didn't previously spend too much time on that since the other contributors said it would be squashed anyway. |
For smaller PRs, yeah, we can just squash them on merge. But with 50k lines added, I'd prefer to split it up, to make bisecting issues easier. |
Hello @chaoticgd really nice feature! |
I'd like to try fixing the history myself first, I plan to resume work on it soon. |
Now that I see you are active again here... One thing important to highlight when fixing the git history (I suppose you are aware). Plenty of times when merging from master we need to solve conflicts and we apply these changes on the "merge commits", so it is quite risky to lose these changes when running rebases. Cheers |
3bc5415
to
e0200a7
Compare
This library doesn't support the demangling scheme used by GCC 2.x compilers and hence doesn't work in lots of cases.
This is the symbol table parser that I'm replacing the existing ELF symbol table parser with. It supports STABS symbols in .mdebug sections as well as ELF symbols and SNDLL symbols. It includes its own symbol database, and an AST which facilitates debugging tools that let the user inspect complex data structures with full type information. More information is provided in the included readme.
This new class uses the CCC library I added in the last commit and parses the symbol tables on a worker thread.
This code is taken from GCC 13.2.0 with a number of modifications applied. See the included readme for more information.
This adds three new tabs in the debugger: The Globals tab, the Locals tab and the Parameters tab. In addition, it rewrites the Functions tab. All four of these tabs use the new symbol tree widgets and the associated model. This allows the user the inspect complex data structures in memory with full type information. Lastly, new dialogs have been added for creating symbols.
I've recreated the git commit history here. These commits have all been ran through the CI checks. If these new commits are satisfactory I can force push them over the data_inspector branch. The old history will still be available on this branch. There is a diff between the two. The old SymbolMap class is still included in the non-rebased branch due to an error on my part. Other than that, there are some tiny changes I decided to make while reading through the diffs. |
Yeah, that new branch looks fine. Feel free to force push this branch. Once that's done I'll ask some people to test and we can get this merged. |
e0200a7
to
7812cc1
Compare
Okay, I've pushed it. |
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.
Was able to read and write to ene_wrk and plyr_wrk structs in Fatal frame 1
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.
Verified in GR2004;
A great improvement
Amazing! Well done! |
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.
Tested homebrew, it shows all of my globals (and reminded me of how poorly I made that thing years ago 😅)
Tested some games. I don't have any that have the mdebug or sndata support but I did not find any regressions.
No compiler warnings.
Good work.
Oh, I checked the diff of a single commit and didn't see anything that touched that code, oops. |
Description of Changes
I have imported symbol table parsing, symbol database and C++ AST code from CCC, entirely replacing the existing symbol map class, and implemented a GUI to inspect data structures in memory using this information.
The original commit history is on the data_inspector_backup branch.
New screenshot:
Old screenshot:
Some highlights:
I haven't implemented that so far. See #11901.Do comment on whether it would be better for me to put this in pcsx2/DebugTools/ccc/ like I have now with the PCSX2 license headers, or in 3rdparty/ccc/ with my own license headers. The original library is MIT so the latter might make it easier for me to copy changes back and forth? It probably doesn't matter too much, so whatever is convenient is probably fine.I've moved it.Progress:
Possible future extensions:
Rationale behind Changes
Many games shipped with debug symbols in this format, so this would be an extremely useful addition for the modding communities of said games.
Suggested Testing Steps
Some games with .mdebug symbols (data types, functions, globals):
A game with SNDLL symbols (functions, globals):