Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDB stub #1583

Merged
merged 28 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2f67161
gdbstub beginnings
PoroCYon Dec 5, 2022
4a9456c
gdbstub: finish gdb impl things, next up is integration with melonDS
PoroCYon Dec 5, 2022
300bc37
holy fuck the gdbstub works
PoroCYon Dec 6, 2022
7059dee
gdb breakpoints work, but there's a mysterious crash on continue
PoroCYon Dec 8, 2022
358dfb1
fix memory corruption that sometimes happened, and make resetting the…
PoroCYon Dec 8, 2022
448848d
remove some gdb debug printing
PoroCYon Dec 8, 2022
857f574
fix things in gdbstub
PoroCYon Dec 13, 2022
f35a807
separate option for enabling gdbstub
PoroCYon Dec 13, 2022
160ee42
add mode-dependent CPU registers
PoroCYon Jul 8, 2023
e17cda7
C++ize the GDBstub code
PoroCYon Jul 9, 2023
e2b9e9a
add gdbstub config in emu settings dialog
PoroCYon Jul 9, 2023
c41bad1
make sure gdb is disabled when jit is enabled
PoroCYon Jul 9, 2023
071e588
Remove unnecessary compiler flags, mark ARMJIT assembly code as no-ex…
PoroCYon Jul 9, 2023
24cc71d
add option to wait for debugger attach on startup
PoroCYon Jul 9, 2023
0eebcdf
only insert GNU stack notes on linux
PoroCYon Jul 9, 2023
c71d47b
disable gdbstub enable checkbox when jit is enabled
PoroCYon Jul 9, 2023
c489593
fix non-linux incompatibilities
PoroCYon Jul 9, 2023
3ddb384
enable gdbstub by default
PoroCYon Jul 9, 2023
242c035
fix issues with gdbstub settings disable stuff
PoroCYon Jul 9, 2023
0503b19
format stuff
PoroCYon Jul 15, 2023
a94d924
update gdb test code
PoroCYon Jul 16, 2023
60cd6c1
Fix segfault when calling StubCallbacks->GetCPU()
PoroCYon Jul 18, 2023
34218ef
fix packet size not being sent correctly
PoroCYon Jul 20, 2023
30bb773
fix select(2) calls (i should read docs more properly)
PoroCYon Jul 24, 2023
223043c
fix GDB command sequencing/parsing issue (hopefully)
PoroCYon Aug 20, 2023
73d2c5f
[GDB] implement no-ack mode
PoroCYon Aug 21, 2023
fae3642
fix sending ack on handshake
PoroCYon Aug 21, 2023
7305cb3
get lldb to work
PoroCYon Aug 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gdbstub beginnings
  • Loading branch information
PoroCYon committed Jul 16, 2023
commit 2f671617753edd1a151ae2489f99d402005b316a
2 changes: 2 additions & 0 deletions src/debug/gdb_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
obj/
test-gdb
25 changes: 25 additions & 0 deletions src/debug/gdb_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

default: all

all: test-gdb

CFLAGS += -Werror=implicit-function-declaration -Werror=int-conversion \
-Werror=return-type -Werror=uninitialized \
-I../ -Og -g -Wall \
-Wno-switch -Wno-pointer-sign

obj/:
@mkdir -vp "$@"

test-gdb: obj/gdbproto.o obj/gdbstub.o obj/gdbcmds.o obj/main.o
$(CC) $(CFLAGS) $(LDFLAGS) -o "$@" $^

obj/gdb%.o: ../gdb%.c obj/
$(CC) $(CFLAGS) -c -o "$@" "$<"

obj/main.o: main.c obj/
$(CC) $(CFLAGS) -c -o "$@" "$<"

clean:
@$(RM) -rv obj/ test-gdb

94 changes: 94 additions & 0 deletions src/debug/gdb_test/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

#include <stdio.h>
#include <time.h>

#include "gdbstub.h"

static uint32_t my_read_reg(int reg) {
printf("[==>] read reg %d\n", reg);

if (reg == 16) return 0x000000df; // cpsr: irq,fiq disabled, arm, sys mode
else return 0x69420;
}
static void my_write_reg(int reg, uint32_t value) {
printf("[==>] write reg %d: 0x%08x\n", reg, value);
}
static uint32_t my_read_mem(uint32_t addr, uint32_t len) {
printf("[==>] read mem 0x%08x (size %u)\n", addr, len);

static const uint32_t words[] = {
0xeafffffe,
0xe0211002,
0xe12fff1e,
0
};

// $: b $ (arm)
return words[(addr>>2)&3] & ((1uLL<<len)-1);
}
static void my_write_mem(uint32_t addr, uint32_t len, uint32_t value) {
printf("[==>] write addr 0x%08x (size %u): 0x%08x\n", addr, len, value);
}

void my_add_bkpt(uint32_t addr, uint32_t len) {
printf("[==>] add bkpt at 0x%08x, len %u\n", addr, len);
}
void my_del_bkpt(uint32_t addr, uint32_t len) {
printf("[==>] del bkpt at 0x%08x, len %u\n", addr, len);
}
void my_del_watchpt(uint32_t addr, uint32_t len) {
printf("[==>] add watchpt at 0x%08x, len %u\n", addr, len);
}
void my_add_watchpt(uint32_t addr, uint32_t len) {
printf("[==>] del watchpt at 0x%08x, len %u\n", addr, len);
}

enum gdbtgt_status my_target_get_status(void) {
return gdbt_break_req;
}

const static struct gdbstub_callbacks cb = {
.cpu = 9,

.target_get_status = my_target_get_status,

.read_reg = my_read_reg,
.write_reg = my_write_reg,
.read_mem = my_read_mem,
.write_mem = my_write_mem,
.add_bkpt = my_add_bkpt,
.del_bkpt = my_del_bkpt,
.add_watchpt = my_add_watchpt,
.del_watchpt = my_del_watchpt
};

int main(int argc, char** argv) {
struct gdbstub* stub;

stub = gdbstub_new(&cb, 3333);
if (!stub) return 1;

while (true) {
enum gdbstub_state s = gdbstub_poll(stub);

if (s == gdbstat_none || s == gdbstat_noconn) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 1000*1000; // 1 ms
nanosleep(&ts, NULL);
continue;
}

switch (s) {
case gdbstat_break: printf("[==>] break execution\n"); break;
case gdbstat_continue: printf("[==>] continue execution\n"); break;
case gdbstat_disconnect: printf("[==>] disconnect\n"); break;
}

if (s == gdbstat_disconnect) break;
}

gdbstub_close(stub);
return 0;
}

Loading