Skip to content

Commit

Permalink
Support debug mode as gdbstub for semu
Browse files Browse the repository at this point in the history
Enable the emulator to act as gdbstub. This feature helps
to dignose and debug issue of emulator more simply.
  • Loading branch information
RinHizakura committed Feb 10, 2025
1 parent b2e2de7 commit 51f5bef
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 77 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = cnfa
url = https://github.com/cntools/cnfa
shallow = true
[submodule "mini-gdbstub"]
path = mini-gdbstub
url = https://github.com/RinHizakura/mini-gdbstub
shallow = true
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ OBJS := \

deps := $(OBJS:%.o=.%.o.d)

GDBSTUB_LIB := mini-gdbstub/build/libgdbstub.a
LDFLAGS += $(GDBSTUB_LIB)
mini-gdbstub/Makefile:
git submodule update --init $(dir $@)
$(GDBSTUB_LIB): mini-gdbstub/Makefile
$(MAKE) -C $(dir $<)
$(OBJS): $(GDBSTUB_LIB)

$(BIN): $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)
Expand Down Expand Up @@ -152,6 +160,7 @@ build-image:

clean:
$(Q)$(RM) $(BIN) $(OBJS) $(deps)
$(Q)$(MAKE) -C mini-gdbstub clean

distclean: clean
$(Q)$(RM) riscv-harts.dtsi
Expand Down
8 changes: 8 additions & 0 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,11 @@ bool virtio_snd_init(virtio_snd_state_t *vsnd);

/* memory mapping */
typedef struct {
bool debug;
bool stopped;
uint32_t *ram;
uint32_t *disk;
vm_t vm;
plic_state_t plic;
u8250_state_t uart;
#if SEMU_HAS(VIRTIONET)
Expand All @@ -376,4 +378,10 @@ typedef struct {
#if SEMU_HAS(VIRTIOSND)
virtio_snd_state_t vsnd;
#endif

uint32_t peripheral_update_ctr;

/* The fields used for debug mode */
bool is_interrupted;
int curr_cpuid;
} emu_state_t;
Loading

0 comments on commit 51f5bef

Please sign in to comment.