XSPdb is a specialized Python pdb-based debugging tool for RISC-V IP cores, customized for Xiangshan's difftest interface. It provides GDB-like interactive debugging capabilities, integrating: Terminal command-line interface, RTL-level waveform toggling, Automated script replay, System snapshot save/restore, Register initialization configuration, Instruction set disassembly, etc. Advanced debugging features: conditional breakpoints, real-time watchpoints, register/memory visualization, Hardware signal-level debugging interface synchronized with software execution states. It is a Hardware/software co-verification solution for RISC-V IPs.
Clone repository and install dependencies:
git clone https://github.com/OpenXiangShan/XSPdb.git # Clone repository
pip install -r XSPdb/requirements.txt # Install dependencies
pip install . # Optional installation
If source integration is not required, use alternative pip installation:
pip3 install XSPdb@git+https://github.com/OpenXiangShan/XSPdb@master
After cloning, run test suite:
cd XSPdb
make test
This command executes:
- Downloads Xiangshan Python binaries
- Fetches test binaries
- Launches interactive debug via example/test.py
Example output and interaction:
LD_PRELOAD=XSPython/xspcomm/libxspcomm.so.0.0.1 PYTHONPATH=. python3 example/test.py
Using simulated 32768B flash
[Info] reset complete
> XSPdb/example/test.py(13)test_sim_top()
-> while True:
(XiangShan) # Enter interactive mode (use Tab for command list)
(XiangShan)xui # Enter TUI mode
(XiangShan)xload ready-to-run/microbench.bin # Load binary (Tab-compatible)
(XiangShan)xistep # Step to next instruction commit
(XiangShan)xstep 10000 # Execute 10000 cycles
Note: XSPdb prioritizes spike-dasm
for disassembly, falling back to capstone
(limited instruction support).
Prerequisite: Build Xiangshan Python simulator (build guide).
Alternative: Download prebuilt binaries:
cd XSPdb
wget https://github.com/OpenXiangShan/XSPdb/releases/download/v0.1.0-test/XSPython.tar.gz
wget https://github.com/OpenXiangShan/XSPdb/releases/download/v0.1.0-test/ready-to-run.tar.gz
tar xf XSPython.tar.gz
tar xf ready-to-run.tar.gz
Launch test:
LD_PRELOAD=XSPython/xspcomm/libxspcomm.so.0.0.1 PYTHONPATH=. python3 example/test.py
Node: The reason for using LD_PRELOAD
to load xspcomm
in advance is to prevent version conflicts between the system xspcomm
library and the local xspcomm
packaged in XSPython.
xload
Load a binary file into memoryxflash
Load a binary file into Flashxreset_flash
Reset Flashxexport_bin
Export Flash + memory data to a filexexport_flash
Export Flash data to a filexexport_ram
Export memory data to a filexload_script
Load an XSPdb scriptxmem_write
Write memory dataxbytes_to_bin
Convert bytes data to a binary filexnop_insert
Insert NOP instructions in a specified address rangexclear_dasm_cache
Clear disassembly cachexprint
Print the value and width of an internal signalxset
Set the value of an internal signalxstep
Step through the circuitxistep
Step through instructionsxwatch_commit_pc
Watch commit PCxunwatch_commit_pc
Unwatch commit PCxwatch
Add a watch variablexunwatch
Remove a watch variablexpc
Print the current Commit PCsxexpdiffstate
Set a variable to difftest_statxexportself
Set a variable to XSPdb selfxreset
Reset DUTxlist_xclock_cb
List all xclock callbacksxui
Enter the Text UI interfacexdasm
Disassemble memory dataxdasmflash
Disassemble Flash dataxdasmbytes
Disassemble binary dataxdasmnumber
Disassemble a numberxbytes2number
Convert bytes to an integerxnumber2bytes
Convert an integer to bytesxparse_instr_file
Parse uint64 stringsxload_instr_file
Load uint64 strings into memoryxparse_reg_file
Parse a register filexload_reg_file
Load a register filexset_iregs
Set Flash internal registers (Integer)xset_mpc
Set the jump address (by mpc) after Flash initialization, default is 0x80000000xget_mpc
Get the jump address after Flash initialization, default is 0x80000000xset_fregs
Set Flash floating-point registers (general)xset_ireg
Set a single Flash internal register (Integer)xset_freg
Set a Flash floating-point registerxlist_flash_iregs
List Flash internal registersxlist_flash_fregs
List Flash floating-point registersxlist_freg_map
List floating-point register mappings
You can use xcmds
to list all commands, their descriptions, and the modules they belong to (use xapis
to list all APIs, their descriptions, and their modules).