From 9ac39e6a1266ad4d17bfc8966ee1dce81a48f263 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 22 Sep 2025 05:33:48 +0000 Subject: [PATCH] Add conn conn_pop_packet. --- .vscode/launch.json | 51 +++++++++++++++++++++++++++++++++----------- gdbstub/stub.cpp | 6 ++++++ gdbstub/utils/conn.h | 7 +++--- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c418c4a..b661d21 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,29 +5,54 @@ "version": "0.2.0", "configurations": [ { - "name": "(gdb) Launch", + "name": "mini-gdbstub", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/mini-gdbstub/build/emu", - "args": ["./mini-gdbstub/build/emu_test.bin"], + "args": [ + "./mini-gdbstub/build/emu_test.bin" + ], "stopAtEntry": false, "cwd": "${workspaceFolder}/mini-gdbstub", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - }, - { - "description": "Set Disassembly Flavor to Intel", - "text": "-gdb-set disassembly-flavor intel", - "ignoreFailures": true - } + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + }, + { + "name": "gdbstub", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/gdbstub/build/stub", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/gdbstub", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } ] } - ] } \ No newline at end of file diff --git a/gdbstub/stub.cpp b/gdbstub/stub.cpp index 280a029..846a16f 100644 --- a/gdbstub/stub.cpp +++ b/gdbstub/stub.cpp @@ -8,5 +8,11 @@ int main(int argc, char *argv[]) { conn_t conn; if (!conn_init(&conn, "127.0.0.1", 1234)) std::cout << "conn_init error" << std::endl; + while (1) { + conn_recv_packet(&conn); + packet_t *pkt = conn_pop_packet(&conn); + printf("packet = %s\n", pkt->data); + } + return 0; } diff --git a/gdbstub/utils/conn.h b/gdbstub/utils/conn.h index 4017d91..2f12b61 100644 --- a/gdbstub/utils/conn.h +++ b/gdbstub/utils/conn.h @@ -3,16 +3,17 @@ #include #include + #include "packet.h" #define MAX_SEND_PACKET_SIZE (0x1000) #define MAX_DATA_PAYLOAD (MAX_SEND_PACKET_SIZE - (2 + CSUM_SIZE + 2)) typedef struct { - int listen_fd; - int socket_fd; + int listen_fd; + int socket_fd; - pktbuf_t pktbuf; + pktbuf_t pktbuf; } conn_t; bool conn_init(conn_t *conn, char *addr_str, int port);