GDB Debugging Support
Hydra features a built-in GDB server that allows you to debug guest (Nintendo Switch) code using standard GDB tools.GDB Server Architecture
The GDB server runs on a separate thread and communicates with GDB clients over TCP/IP.
Supported GDB Features
Register Access
Register Access
Read and write ARM64 registers:Supported registers:
- General purpose (x0-x31)
- Special registers (PC, SP, LR)
- FP/SIMD registers (v0-v31)
- System registers (PSTATE, etc.)
Memory Access
Memory Access
Read guest memory during debugging:
- Read arbitrary memory addresses
- Supports page-granular access
- Respects memory protection
Breakpoints
Breakpoints
Set and manage breakpoints:Breakpoint types:
- Software breakpoints (BRK instruction)
- Hardware breakpoints (CPU backend dependent)
Thread Control
Thread Control
Control thread execution:
- Continue/pause threads
- Switch active thread
- Query thread status
Executable Information
Executable Information
Query loaded executables:
- List loaded modules
- Get memory ranges
- Symbol information
Enabling GDB Debugging
To use GDB debugging with Hydra:Start Hydra
Launch the emulator. The GDB server will start listening on the configured port.You should see a log message indicating the GDB server is ready.
GDB Protocol Support
The GDB server implements standard RSP (Remote Serial Protocol) commands:src/core/debugger/gdb_server.cpp
Target XML
The server provides AArch64 target description:Debugger Framework
Hydra includes a comprehensive debugging framework beyond GDB:Debugger Class
src/core/debugger/debugger.hpp
Thread Management
- Guest Threads
- Thread Status
Track Nintendo Switch threads:
Symbol Tables
The debugger maintains symbol tables for modules and functions:src/core/debugger/debugger.hpp
Module Symbols
Module Symbols
Track loaded executables and libraries:
Function Symbols
Function Symbols
Register individual functions for better debugging:
Debug Assertions
Use debug assertions in your code:src/core/debugger/debugger.hpp
DEBUGGER_ASSERT_DEBUG is only active in debug builds, while DEBUGGER_ASSERT is always active.Stack Traces
The debugger can capture and resolve stack traces:Message Logging
Capture debug messages with stack traces:Logging Configuration
Control debug output verbosity:config.toml
- None
- StdOut
- File
Disables all logging output
- Fastest performance
- No debug information
- Not recommended
CPU Backend Differences
Debug capabilities vary by CPU backend:Apple Hypervisor
Debug Features:
- Native hardware breakpoints
- Fast breakpoint handling
- Debug exception trapping
- No single-step support
Dynarmic
Debug Features:
- Software breakpoints
- Single-step execution
- Instruction-level debugging
- Exception callbacks
Advanced Debugging
Executable Registration
Register executables for symbol resolution:Custom Debug Commands
The GDB server supports custom commands viamonitor:
Best Practices
Use Dynarmic for Development
The Dynarmic CPU backend provides better debugging support with single-step capability.
Enable File Logging
Set
log_output = "file" to capture all debug information without cluttering your terminal.Register Symbols
Register module and function symbols to get meaningful stack traces and breakpoint names.
Common Debug Workflows
Debugging a Crash
Debugging a Crash
- Enable GDB and file logging
- Reproduce the crash
- Check logs for stack trace
- Connect GDB at crash point
- Examine registers and memory
Analyzing Game Behavior
Analyzing Game Behavior
- Set breakpoint at function of interest
- Run until breakpoint hit
- Single-step through code (Dynarmic)
- Inspect registers and memory
- Continue or repeat
Performance Profiling
Performance Profiling
- Enable performance logging
- Run game for representative period
- Analyze logs for hotspots
- Use GDB to understand slow code
- Optimize as needed
Troubleshooting
GDB Won't Connect
GDB Won't Connect
- Check
gdb_enabled = truein config - Verify port is not in use (default 1234)
- Ensure firewall allows connection
- Try
telnet localhost 1234to test
Breakpoints Not Working
Breakpoints Not Working
- Verify address is correct
- Check if code is loaded at that address
- Try hardware breakpoints (Hypervisor)
- Switch to Dynarmic backend for software breakpoints
Missing Symbols
Missing Symbols
- Register executables with debugger
- Load symbol files if available
- Use
info symbolin GDB - Check module table registration