A simple c++ socket.io client for communicating with ysyx-sdb-tui server.
You can install
ysyx-sdb-tuiplugin in the marketplace of VS Code. Or see ysyx-sdb-tui
When you use sdb in NEMU or NPC for debugging, it can highlight the specific line in the disassembly file and source file. It greatly enhances debugging efficiency.
apt install gdb-multiarch: support RISC-V debugging- Install C++
socket.ioclient library: socket.io-client-cpp, see Chapter Installation alternatives for details.
-
copy
sdb-client.ccto${NEMU_HOME}/src/utils. -
Modify the
filelist.mkin${NEMU_HOME}/src/utils. Addsdb-client.cc,-lsioclientto specific conditions.
ifneq ($(CONFIG_ITRACE)$(CONFIG_IQUEUE),)
CXXSRC = src/utils/disasm.cc src/utils/sdb-client.cc
CXXFLAGS += $(shell llvm-config --cxxflags) -fPIE
LIBS += $(shell llvm-config --libs) -lsioclient
endif- Add interface callings to NEMU.
- Add client initialization code to the function
void init_monitor(int argc, char *argv[])insrc/monitor/monitor.c.
/* Initialize the simple debugger. */
init_sdb();
/* Initialize the sdb client, server is vscode plugin */
void open_sdb_client();
void init_sdb_vscode_file(char *img_file_path, int type);
void highlight_line(word_t addr, int type);
if (img_file != NULL)
{
open_sdb_client();
init_sdb_vscode_file(img_file, 0);
init_sdb_vscode_file(img_file, 1);
highlight_line(cpu.pc, 0); // disassembly file, highlight the start pc
}
///////////////////////////////////////////////////////////- Add
highlight_line()to the functionexecuteinsrc/cpu/cpu-exec.c.
static void execute(uint64_t n)
{
Decode s;
for (; n > 0; n--)
{
exec_once(&s, cpu.pc);
// ...
}
/* highlight the specified line in the source file and disassembly file */
void highlight_line(word_t addr, int type);
highlight_line(s.dnpc, 2); // all
}- Add
close_sdb_clientto functioncpu_execinsrc/cpu/cou-exec.c.
case NEMU_QUIT:
Log("NEMU QUIT Only");
///////////////////////////////////////
void close_sdb_client();
close_sdb_client();
///////////////////////////////////////
statistic();
}In abstract-machine/Makfile:
# modify `O2` to `O0`
CFLAGS += O0 -ggdb Then clean all build directory and rebuild:
abstract-machine/builddirectoryabstract-machine/am/builddirectoryabstract-machine/klib/builddirectory
- Open VS Code and install the
ysyx-sdb-tuiplugin in the marketplace.
-
Type
Ctrl+Shift+Pto open the command palette.- Type
ysyx sdb tui Enableand pressEnterto enable the extension. It will open a terminal and focus on it.
- Type
-
Run the NEMU program in sdb mode in the terminal, such as
make ARCH=riscv32-nemu run. -
Type
si 5test the SDB TUI plugin.
- Close the server after debugging.
- Type
ysyx sdb tui Disableand pressEnterto disable the extension. - Or close the VS Code directly.
- Type


