Skip to content

Debugger: Make debugger aware of thread status when using threads#3603

Closed
nuive wants to merge 1 commit into
mgba-emu:masterfrom
nuive:debugger-fix
Closed

Debugger: Make debugger aware of thread status when using threads#3603
nuive wants to merge 1 commit into
mgba-emu:masterfrom
nuive:debugger-fix

Conversation

@nuive

@nuive nuive commented Sep 29, 2025

Copy link
Copy Markdown
Contributor

When mGBA used Threading, the debugger ignored this and would run even when the thread status was not RUNNING. This issue has been addressed by allowing the debugger to know thread's current status at every momment.
Mutex handling has also been added (when using threads) to prevent unwanted or unpredictable changes during critical sections.

Between this and #3602 issue #3355 should be fixed.

@endrift endrift left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm really not sure what this fixes. It looks like it's just leaking the thread abstraction into the debugger, but only for one check on one callsite that could be done outside the function. Am I missing something?

Comment thread src/debugger/debugger.c

void mDebuggerUnsetThread(struct mDebugger* debugger) {
if (debugger->threadImpl) {
debugger->threadImpl = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
debugger->threadImpl = 0;
debugger->threadImpl = NULL;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought 0 was the prefered C sintax and NULL for C++?

void mDebuggerAttachModule(struct mDebugger*, struct mDebuggerModule*);
void mDebuggerDetachModule(struct mDebugger*, struct mDebuggerModule*);
void mDebuggerRunTimeout(struct mDebugger* debugger, int32_t timeoutMs);
void mDebuggerRunTimeout(struct mDebugger*, int32_t);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please leave the name timeoutMs in the signature. I remove parameter names that are obvious, but timeoutMs includes the unit, which just int32_t doesn't.

Comment thread src/debugger/debugger.c
debugger->platform->checkBreakpoints(debugger->platform);
bool hasBreakpoints = debugger->platform->hasBreakpoints(debugger->platform);
#ifndef DISABLE_THREADING
if (impl) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Almost all of these checks can be put outside of the switch statement by just doing an unlock before and lock afterwards. The only exceptions are the early exit if the thread is paused, which doesn't really seem like it belongs in this function anyway (are there any other callsites that can't do the check itself?), and the two cases at the end, which you can do an early check for before unlocking. By doing the checks external to the switch statement, you can reduce duplication of code and massively reduce the diff size at the same time.

@nuive

nuive commented Nov 2, 2025

Copy link
Copy Markdown
Contributor Author

I'm really not sure what this fixes. It looks like it's just leaking the thread abstraction into the debugger, but only for one check on one callsite that could be done outside the function. Am I missing something?

I tried it, but if I do that inside _mCoreThreadRun all commands entered in the debugger window never reach debugger. It never pauses, it never shows help...

@endrift

endrift commented Dec 29, 2025

Copy link
Copy Markdown
Member

I believe this PR is obviated by 141a82e. Let me know.

@endrift endrift closed this Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants