diff options
| author | Duncan Ogilvie <mr.exodia.tpodt@gmail.com> | 2026-04-27 03:39:34 +0200 |
|---|---|---|
| committer | crueter <crueter@eden-emu.dev> | 2026-04-27 03:39:34 +0200 |
| commit | 1590e7c061898d23f3f8647b41d86b36aa148ad3 (patch) | |
| tree | be932c972c7bd9f4e4b77e94b4cabb362342b78e /src | |
| parent | c95f8df8a5d83aadba6645cb5332442ac0dc78e8 (diff) | |
[core] GDB improvements (#3848)
The commands to reproduce the issues are in the commit messages. I tested on Super Mario Odyssey using [nx2elf](https://github.com/shuffle2/nx2elf) converted binaries and gdb-multiarch:
```
(gdb) monitor info
Process: 0x51 (Application)
Program Id: 0x0100000000010000
Layout:
Alias: 0x1103400000 - 0x21033fffff
Heap: 0x2103400000 - 0x23033fffff
Aslr: 0x0008000000 - 0x7fffffffff
Stack: 0x1083400000 - 0x11033fffff
Modules:
0x0080b3d000 - 0x0080b40fff nnrtld
0x0080b41000 - 0x0081ff1fff RedStar.nss
0x0081ff2000 - 0x008270efff multimedia
0x008270f000 - 0x00833e2fff nnSdk
(gdb) monitor mappings
Mappings:
0x0000000000 - 0x0080b3cfff Free ----- [0, 0]
0x0080b3d000 - 0x0080b3efff r-x Code ----- [0, 0]
0x0080b3f000 - 0x0080b3ffff r-- Code ----- [0, 0]
0x0080b40000 - 0x0080b40fff rw- CodeData ----- [0, 0]
0x0080b41000 - 0x008156bfff r-x Code ----- [0, 0]
0x008156c000 - 0x0081cdafff r-- Code ----- [0, 0]
0x0081cdb000 - 0x0081ff1fff rw- CodeData ----- [0, 0]
0x0081ff2000 - 0x0082365fff r-x Code ----- [0, 0]
0x0082366000 - 0x00825c0fff r-- Code ----- [0, 0]
0x00825c1000 - 0x008270efff rw- CodeData ----- [0, 0]
0x008270f000 - 0x0082c3cfff r-x Code ----- [0, 0]
0x0082c3d000 - 0x00832bffff r-- Code ----- [0, 0]
0x00832c0000 - 0x00833e2fff rw- CodeData ----- [0, 0]
0x00833e3000 - 0x0083403fff Free ----- [0, 0]
0x0083404000 - 0x0083404fff rw- ThreadLocal ----- [0, 0]
0x0083405000 - 0x1083403fff Free ----- [0, 0]
0x1083404000 - 0x1083503fff rw- Stack ----- [0, 0]
0x1083504000 - 0x7fffffffff Free ----- [0, 0]
(gdb) set sysroot
(gdb) set solib-search-path /Users/duncan/Downloads/smo-program
Reading symbols from /Users/duncan/Downloads/smo-program/rtld.elf...
(No debugging symbols found in /Users/duncan/Downloads/smo-program/rtld.elf)
Reading symbols from /Users/duncan/Downloads/smo-program/main.elf...
(No debugging symbols found in /Users/duncan/Downloads/smo-program/main.elf)
Reading symbols from /Users/duncan/Downloads/smo-program/subsdk0.elf...
(No debugging symbols found in /Users/duncan/Downloads/smo-program/subsdk0.elf)
Reading symbols from /Users/duncan/Downloads/smo-program/sdk.elf...
(No debugging symbols found in /Users/duncan/Downloads/smo-program/sdk.elf)
(gdb) info shared
From To Syms Read Shared Object Library
0x0000000080b3d000 0x0000000080b41000 Yes (*) /Users/duncan/Downloads/smo-program/rtld.elf
0x0000000080b41000 0x0000000081ff2000 Yes (*) /Users/duncan/Downloads/smo-program/main.elf
0x0000000081ff2000 0x000000008270f000 Yes (*) /Users/duncan/Downloads/smo-program/subsdk0.elf
0x000000008270f000 0x00000000833e3000 Yes (*) /Users/duncan/Downloads/smo-program/sdk.elf
(*): Shared library is missing debugging information.
(gdb) info functions nnMain
All functions matching regular expression "nnMain":
Non-debugging symbols:
0x0000000081024250 nnMain
0x0000000082c2de40 nnMain@plt
(gdb) b *nnMain
Breakpoint 1 at 0x81024250
(gdb) c
Continuing.
Breakpoint 1, 0x0000000081024250 in nnMain () from /Users/duncan/Downloads/smo-program/main.elf
(gdb) x/10i $pc
=> 0x81024250 <nnMain>: stp x22, x21, [sp, #-48]!
0x81024254 <nnMain+4>: stp x20, x19, [sp, #16]
0x81024258 <nnMain+8>: stp x29, x30, [sp, #32]
0x8102425c <nnMain+12>: add x29, sp, #0x20
0x81024260 <nnMain+16>: bl 0x81569aa0
0x81024264 <nnMain+20>: mov w19, w0
0x81024268 <nnMain+24>: bl 0x81569ab0
0x8102426c <nnMain+28>: mov x20, x0
0x81024270 <nnMain+32>: mov w0, w19
0x81024274 <nnMain+36>: mov x1, x20
```
Symlinked like this:
```
ls -l /Users/duncan/Downloads/smo-program
total 687472
-rw-r--r--@ 1 duncan staff 20385356 Apr 9 18:12 main.elf
lrwxr-xr-x@ 1 duncan staff 11 Apr 9 15:26 multimedia -> subsdk0.elf
lrwxr-xr-x@ 1 duncan staff 8 Apr 9 15:28 nnrtld -> rtld.elf
lrwxr-xr-x@ 1 duncan staff 7 Apr 9 15:26 nnSdk -> sdk.elf
lrwxr-xr-x@ 1 duncan staff 8 Apr 9 15:26 RedStar.nss -> main.elf
-rw-r--r--@ 1 duncan staff 12440 Apr 9 18:12 rtld.elf
-rw-r--r--@ 1 duncan staff 12662960 Apr 9 18:12 sdk.elf
-rw-r--r--@ 1 duncan staff 6294336 Apr 9 18:12 subsdk0.elf
```
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3848
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/debugger/gdbstub_arch.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/physical_core.cpp | 28 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/core/debugger/gdbstub_arch.cpp b/src/core/debugger/gdbstub_arch.cpp index fec75c3432..5c5f3e8704 100644 --- a/src/core/debugger/gdbstub_arch.cpp +++ b/src/core/debugger/gdbstub_arch.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project @@ -283,7 +283,7 @@ std::string_view GDBStubA32::GetTargetXML() const { <reg name="r11" bitsize="32" type="uint32"/> <reg name="r12" bitsize="32" type="uint32"/> <reg name="sp" bitsize="32" type="data_ptr"/> - <reg name="lr" bitsize="32" type="code_ptr"/> + <reg name="lr" bitsize="32"/> <reg name="pc" bitsize="32" type="code_ptr"/> <!-- The CPSR is register 25, rather than register 16, because the FPA registers historically were placed between the PC diff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cpp index e4aff43d82..f394122764 100644 --- a/src/core/hle/kernel/physical_core.cpp +++ b/src/core/hle/kernel/physical_core.cpp @@ -50,6 +50,14 @@ void PhysicalCore::RunThread(Kernel::KThread* thread) { }; const auto ExitContext = [&]() { + // Save the JIT context back to the thread so the debugger can + // read the current register state. Debug halt paths (step, + // breakpoint, watchpoint) return from RunThread without going + // through the scheduler's Unload/SaveContext. + if (system.DebuggerEnabled()) { + interface->GetContext(thread->GetContext()); + } + // Unlock the thread. interface->UnlockThread(thread); @@ -97,11 +105,16 @@ void PhysicalCore::RunThread(Kernel::KThread* thread) { } // Determine why we stopped. - const bool supervisor_call = True(hr & Core::HaltReason::SupervisorCall); - const bool prefetch_abort = True(hr & Core::HaltReason::PrefetchAbort); - const bool breakpoint = True(hr & Core::HaltReason::InstructionBreakpoint); - const bool data_abort = True(hr & Core::HaltReason::DataAbort); - const bool interrupt = True(hr & Core::HaltReason::BreakLoop); + // If a step completed successfully, skip other halt reason handlers — + // the step takes priority (e.g. step may also set InstructionBreakpoint + // if the next instruction happens to be a breakpoint). + const bool step_completed = True(hr & Core::HaltReason::StepThread) + && thread->GetStepState() == StepState::StepPerformed; + const bool supervisor_call = !step_completed && True(hr & Core::HaltReason::SupervisorCall); + const bool prefetch_abort = !step_completed && True(hr & Core::HaltReason::PrefetchAbort); + const bool breakpoint = !step_completed && True(hr & Core::HaltReason::InstructionBreakpoint); + const bool data_abort = !step_completed && True(hr & Core::HaltReason::DataAbort); + const bool interrupt = !step_completed && True(hr & Core::HaltReason::BreakLoop); // Since scheduling may occur here, we cannot use any cached // state after returning from calls we make. @@ -111,6 +124,11 @@ void PhysicalCore::RunThread(Kernel::KThread* thread) { if (breakpoint || prefetch_abort) { if (breakpoint) { interface->RewindBreakpointInstruction(); + // RewindBreakpointInstruction sets the JIT state to the + // saved breakpoint context. Update the thread context to + // match, since ExitContext already saved the post-execution + // state. + interface->GetContext(thread->GetContext()); } if (system.DebuggerEnabled()) { system.GetDebugger().NotifyThreadStopped(thread); |
