Commit Graph
66 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5 3f0c2da5a9 Debugger: surface source line info in six more places
Following on from the DWARF line table: the lookup was only reachable from
hle.backtrace, the breakpoint hit object and the ImGui disassembly status bar.
Now also in

- the ImDebugger call stack (new Source column),
- the Win32 call stack (new Source column),
- the Win32 disassembly status bar, matching the ImGui one,
- the ImDisasmView right-click menu, which showed a bare address as its heading
  and now leads with "mesh.zig:163 (08841f98)" when there's a line for it,
- breakpoint log lines - a log-only breakpoint's entire output is those lines,
  and "BKP PC=08841f98 mesh.zig:163" reads a great deal better than an address
  when you're scanning a few thousand of them,
- crash stack traces, via FormatStackTrace, which is what the crash screen and
  crash reporting both use.

That last one is where it earns its keep, and it needed the invalid-jump path to
produce a stack trace at all - it was the one exec exception that didn't. It's
also the one that most deserves it: the address it jumped to tells you nothing,
the callers tell you everything. Execution has already moved to the bad address
by the time it's noticed, so a walk from pc finds no function to start from;
WalkCurrentStack takes an explicit starting pc now, and falling back to ra
recovers the chain. Reproducing the original CrossCraft bug:

  CPU Jump: Invalid jump to ae870000 from PC ae870000(invalid) RA 08841f98
  MIPS call stack:
  rendering.mesh.Mesh(PspVertex).draw at mesh.zig:163 (08841c30+368, ...)
  state.MenuState.draw at MenuState.zig:821 (0883ab90+414, ...)
  engine.Engine.stepFrameInternal at State.zig:40 (08820f74+5164, ...)
  utils.module._module_main_thread at engine.zig:468 (088272c4+2fb8, ...)

Fixed a pre-existing double-report while in there: every case in
Core_ExecException sent its message and then fell through to an unconditional
send of the same message, so each exec exception was logged twice. The message
is built in the switch and sent once at the end now.

pspautotests 314/314, UnitTest 55/55.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-18 13:42:14 +02:00
Henrik RydgårdandClaude Opus 5 75ff0d406c Rename Memory::Lock() to Core_LockAgainstShutdown(), move it to Core
It stopped being about memory when CPU_Shutdown started holding it across the
whole teardown - it's what keeps kernel objects, the symbol map and the memory
map from being freed while another thread reads them. The old name invited the
reading that it locks memory *access*, which it has never done.

Memory::Reinit() now holds it across both halves rather than relying on
Memory::Shutdown()'s own acquire: between Shutdown() and Init() there is no
memory map at all, and a reader could slip into that gap.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 13:11:16 +02:00
Henrik RydgårdandClaude Opus 5 f57a102027 Win32 debugger: take the shutdown lock everywhere core state is read
Seven GUI-thread readers held only g_frameMutex, which guards against the CPU
thread mutating state but not against the core being torn down - and two of
PSP_Shutdown's paths (EmuScreen::sendMessage, ProcessScreenSwitches) run outside
that span entirely. CtrlThreadList::reloadThreads walking kernel objects that
__KernelShutdown had freed was the concrete crash; the symbol map readers
(CDisasm::Show/NotifyMapLoaded, CtrlModuleList, CtrlWatchList) had the same
shape.

Always g_frameMutex first, then Memory::Lock().

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 13:11:16 +02:00
Henrik RydgårdandClaude Opus 5 81511e7a08 Fix deadlock between the Win32 debugger's paint handlers and the CPU thread
Reported hang: the CPU thread held g_frameMutex (NativeFrame) and blocked on
g_shutdownLock inside a queued memory.read, while the GUI thread held
g_shutdownLock (CtrlMemView::onPaint) and blocked on g_frameMutex. Textbook
ABBA.

The CPU thread's order is structural - NativeFrame wraps everything below it in
g_frameMutex, and both Core_ProcessCPUQueue() and runImDebugger() ->
DisassembleRange() lock memory from under there - so the GUI side is the one
that has to match. Swaps the three handlers that had it backwards
(CtrlMemView::onPaint, CtrlDisAsmView::onPaint, CtrlStackTraceView::
loadStackTrace) to take g_frameMutex first. They already took both locks, so
this is ordering only, and g_shutdownLock is recursive so nesting is fine.

Also drops the Memory::MemoryInitedLock from the WebSocket LockMemory(), which
is what made the CPU thread want that lock in the first place. It was guarding
against another thread tearing down the memory system, but that doesn't happen:
Memory::Shutdown() is only reached via CPU_Shutdown() <- PSP_Shutdown(), whose
callers all run on the CPU thread, and Memory::Reinit() runs from
Memory::DoState() on savestate load, likewise. WebSocket.cpp additionally holds
lifecycleLock across the whole handler and takes it on STOPPING.

Note this second part isn't sufficient on its own - ImMemView's copy-disassembly
path also locks memory from inside the frame span - which is why the ordering
fix is the real one.

Not removing Memory::Lock() from the Win32 paint handlers: teardown isn't fully
inside the g_frameMutex span yet. EmuScreen::render()'s PSP_Shutdown() is, but
the ones in EmuScreen::sendMessage() (game reset, loading a new game) run from
g_screenManager->sendMessage(), above where NativeFrame takes the guard. Closing
that is the prerequisite, and is left for later.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 00:29:44 +02:00
Henrik RydgårdandClaude Opus 5 35a91b757a Move the temporary breakpoint out of the user's breakpoint list
step-over, step-out and run-until plant a one-shot breakpoint at the address
they want execution to return to. Keeping it in breakPoints_ alongside the
user's own meant the two kept colliding:

- Adding a log-only user breakpoint at the same address hijacked the temporary
  one. AddBreakPoint() didn't match across temp-ness so both existed, and then
  ChangeBreakPoint() looked up "the first enabled breakpoint at this address" -
  a log-only breakpoint isn't enabled, so the temporary one won and had its
  action overwritten to log-only. It lost PAUSE and the step never came back.
- RemoveBreakPoint() erased up to two entries per address to catch an
  overlapping temporary one, so deleting either deleted both - including the
  interpreter's cleanup path in CheckExecBreakpoints() taking the user's
  breakpoint with it.
- ExecBreakPoint() handled one breakpoint per address, so with both at the same
  address only one of them did anything: the step completed but the user's log
  line never printed.
- Nothing dropped it when something *else* stopped us first, so an interrupted
  step left a breakpoint armed at an address nobody was waiting for anymore,
  which later fired as a phantom stop.

It's a single TempBreakPoint member now, invisible to the breakpoint lists and
untouched by user edits. One is enough: step over/out and cross-thread step into
all require the CPU to already be stepping and resume it immediately, so only
one can be in flight, and run-until now replaces rather than stacking (two
pending run-untils had no coherent meaning, and the loser stayed armed).

Behavior follows what other debuggers do. Both breakpoints at an address are
evaluated independently and their actions combine, so a log-only breakpoint
logs without stopping and still lets the step finish. Core_Break() drops the
temporary breakpoint on any stop, whatever the reason - the same way gdb deletes
its step-resume breakpoint and lldb discards the thread plan.

Two things to be careful of, both covered by the new TempBreakpoints test:
HasBreakPoints() has to account for it, or the interpreter's checked run loop
and the JIT skip breakpoint checking entirely and a step with no user
breakpoints set never returns; and IsAddressBreakPoint() (user-facing, for the
lists and disassembly markers) is now separate from NeedsBreakCheckAt() (what
the JIT frontends and interpreter ask), since only the latter should see it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 00:29:26 +02:00
Henrik Rydgård c457dbbd2f Debugger breakpoints: Rename "Result" to "Action" 2026-08-16 16:59:54 +02:00
Henrik RydgårdandClaude Sonnet 5 f72709feb0 Legacy Win32 debugger: fix the painting problem with a frame-scoped mutex
Debugger windows (register list, disassembly view, memory view, breakpoint/
thread/module/stack lists, watch list) read CPU-thread-owned state directly
from the GUI thread's WM_PAINT/list-fill handlers, racing against the CPU
thread. Routing every read through Core_RunOnCPUThread would be too slow for
something invoked continuously on paint/list-refresh.

Add g_frameMutex (Core.h/Core.cpp), held by NativeFrame() only across the
span where it actually touches that state (running the CPU, processing
breakpoints, running the ImGui debugger) - not across input handling or the
present/frame-pacing waits. Debugger windows now hold the same mutex while
reading, giving synchronized reads without the round-trip cost of queuing
to the CPU thread.

CtrlRegisterList::onPaint() goes back to always reading live values (now
safe under the lock) and grays them out by color alone while the core is
running, rather than the earlier snapshot-caching approach.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hqm11k99viLfbJm2MkH4BH
2026-08-08 17:22:12 +02:00
Henrik RydgårdandClaude Sonnet 5 25c3c90c94 Legacy Win32 debugger: route mutations through the CPU thread
The Win32 debugger dialogs mutate CPU-thread-owned state (breakpoints,
symbol map, registers, memory, kernel threads) directly from the GUI
thread with no synchronization, same problem the WebSocket debugger had.
Route all of these through Core_RunOnCPUThread instead, following the
same pattern used there.

Also drops two forced-pause (Core_Break/Core_WaitInactive/Core_Resume)
dances in CtrlMemView::onChar and DumpMemoryWindow's dump handler, now
unnecessary since Core_RunOnCPUThread works whether the CPU is running
or already stepping.

Modal dialogs (MessageBox, InputBox_GetString, BreakpointWindow::exec,
etc.) are kept outside any queued callback so they never block the CPU
thread on user input. Pure reads/painting (disassembly formatting,
search, list reloads, onPaint) are intentionally left as-is for now.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hqm11k99viLfbJm2MkH4BH
2026-08-08 17:22:12 +02:00
Henrik Rydgård 5f7a937466 Rename ValidSize to ClampValidSizeAt 2025-12-30 20:31:07 +01:00
Henrik Rydgård 644f5e4e6c Expose PSPModule (so the debugger can access it later) 2025-03-31 09:56:08 +02:00
Henrik Rydgård 20a17a0e8d Reorganize DebugInterface etc a bit.
KernelThreadDebugInterface no longer has a useless copy of a MIPSDebugInterface.
2024-12-12 18:54:46 +01:00
Henrik Rydgård 21997784bf Extract FormatStateRow() from the Win32 GE debugger to GPU/Debugger/Registers 2024-12-05 10:07:29 +01:00
Henrik Rydgård 3cba1135d5 Add basic breakpoint editing window. Need UI refinement 2024-11-25 00:23:28 +01:00
Henrik Rydgård 7992ff4627 Make CBreakpoints an object 2024-11-25 00:22:53 +01:00
Henrik Rydgård 88a2994a4d Make some more ImGui debugger windows (modules, threads, callstack)
Funcionality is a bit limited though (no context menus yet)
2024-11-07 13:29:27 +01:00
Henrik Rydgård 15c0bb1bd0 Fix crash in debugger after unloading the game. 2023-12-13 22:00:55 +01:00
Unknown W. Brackets 9cebfc31b3 Debugger: Avoid unaligned reads in expressions.
Potentially, a watch or break condition could crash if it was unaligned
between mirrors.  This might happen if it's not the condition you wanted,
especially.  Play it safe.
2023-04-12 01:14:30 -07:00
Unknown W. Brackets 5629b01dc9 Debugger: Accept format for watches. 2023-04-09 16:39:25 -07:00
Unknown W. Brackets 99bdb4f18a Debugger: Periodically refresh watches to be safe. 2023-04-09 00:52:03 -07:00
Unknown W. Brackets c0fc2e65e0 Debugger: Highlight changed watches. 2023-04-09 00:47:36 -07:00
Unknown W. Brackets 85a071568c Debugger: Allow adding/removing watches. 2023-04-09 00:35:37 -07:00
Unknown W. Brackets 879e91dbf6 Debugger: Add empty watch tab for debugger.
Currently, there's nothing shown here.
2023-04-09 00:01:42 -07:00
Unknown W. Brackets f708ab2965 Debugger: Add delete breakpoint to context menu. 2023-04-08 23:29:59 -07:00
Unknown W. Brackets cbc1ed4bfe Debugger: Lock memory during stack walk.
In case of shutdown during it.
2023-02-22 21:14:33 -08:00
Unknown W. Brackets bfc659ab5f Debugger: Correct check of pending list item.
Since updating is async now, setting the check state should be too.
2022-12-31 09:58:24 -08:00
Unknown W. Brackets e7e5d031b2 Debugger: Fix crash on ill-timed breakpoint update. 2021-12-12 10:49:38 -08:00
Henrik Rydgård c004e9ca9d Windows debugger: Load the dialogs on demand.
I think this is especially good for the Ge dialog since we now can avoid
initializing that extra GL context unless you open the dialog.
2021-11-13 22:10:37 +01:00
Unknown W. Brackets 39d3b4d933 Debugger: Centralize context menu handling.
This deduplicates a bit, but more importantly keeps all the IDs together.
2021-10-07 19:48:13 -07:00
Unknown W. Brackets 58238abef5 Debugger: Fix submenu offsets from removing unused.
The wrong menus were showing in several places, especially the GE
debugger.
2021-10-07 07:04:33 -07:00
Henrik Rydgård ff8148dd92 Move native/util, native/data and native/i18 to Common/Data.
Also move colorutil.cpp/h

linking build fix experiment

Delete a bunch of unused CMakeLists.txt files

CMakeLists.txt linking fix

Don't include NativeApp.h from any headers.

Android.mk buildfix

Half of the UWP fix

Buildfix

Minor project file cleanup

Buildfixes

Guess what? More buildfixes!
2020-10-04 07:28:29 +02:00
Henrik Rydgård 6ac9dfe6b5 Windows debugger: Clean out old remains of multi-cpu support 2020-09-24 00:32:52 +02:00
Unknown W. Brackets 9972e5b10a Debugger: Allow logging on CPU breakpoints. 2016-08-04 12:39:29 -07:00
Unknown W. Brackets a9ad0cd471 Debugger: Make breakpoint actions more generic. 2016-08-04 12:02:44 -07:00
Henrik Rydgard b998131581 Move the symbol map to the heap, deallocate it when no game is running. 2015-10-31 23:01:19 +01:00
Unknown W. Brackets 83b8e564cf Avoid an unlikely error in breakpoint listing. 2015-01-19 08:31:56 -08:00
Henrik Rydgard f84ebf6bff sprintf->snprintf, fix some too short buffers 2014-09-14 00:14:11 +02:00
Unknown W. Brackets 9f01c02626 Don't try to read breakpoint info after exit.
Fixes a crash on exit when on a breakpoint.
2014-05-31 10:03:01 -07:00
Kingcom 2b7a601c17 Add checkboxes to GenericListControl, use them in CtrlBreakpointList 2014-02-13 10:24:42 +01:00
Kingcom 880be6d41d Module list in Windows debugger 2014-01-27 00:35:16 +01:00
Henrik Rydgård efd44a6933 Merge branch 'debugger2' of https://github.com/unknownbrackets/ppsspp into unknownbrackets-debugger2
Conflicts:
	Core/Debugger/Breakpoints.cpp
2014-01-26 23:10:37 +01:00
Unknown W. Brackets fe2b62c27d Make the "on change" checkbox for memchecks work.
But, for now, only on sw and similar instructions, the rest don't work
yet and just always break.
2014-01-26 11:57:39 -08:00
Unknown W. Brackets 76afb2a8d5 Avoid returning points from the symbol map.
Now that it uses a lookup, this is even more dangerous.  But, the maps
could be reordered while it's trying to print the pointer and cause that
data to become invalid.

This should be safe from race conditions.
2014-01-25 21:40:23 -08:00
Unknown W. Brackets db77dcd149 Fix some includes on Windows/etc. 2013-12-29 15:59:36 -08:00
Unknown W. Brackets 32f4a7594a Add bounds checks to columns accessors.
Hit a crash in one of these on a rare case, so better to check.
2013-11-27 23:53:18 -08:00
Kingcom 7c585485bb Save labels separately from symbols 2013-11-26 00:23:17 +01:00
Unknown W. Brackets 5b888f0d0a Fix a crash in debug mode with no threads. 2013-10-16 00:56:46 -07:00
Kingcom 49a4f9e73d Fix right click->edit breakpoint 2013-10-04 23:21:44 +02:00
Kingcom f41e5a3867 -use TabControl for bottom tabs
-show/hide bottom tabs with ctrl+x
2013-09-30 10:40:15 +02:00
Kingcom c800b0055d Update CtrlStackTraceView 2013-09-29 11:28:16 +02:00
Kingcom ed9c72e8eb Update CtrlBreakpointList 2013-09-29 11:19:13 +02:00