Skip to content

Commit

Permalink
gdbstub: Make loop enum public
Browse files Browse the repository at this point in the history
Make the current gdb loop enum public under the name `gdb_loop_state`.
This will allow for extending the current stub with further
functionality in the future as new features will require control over
the loop state.

Signed-off-by: Robert Zieba <[email protected]>
  • Loading branch information
GRobertZieba authored and fabiobaltieri committed Apr 3, 2024
1 parent fa4ab81 commit e410e2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
9 changes: 9 additions & 0 deletions include/zephyr/debug/gdbstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ struct gdb_mem_region {
uint8_t alignment;
};

/**
* State of the packet processing loop
*/
enum gdb_loop_state {
GDB_LOOP_RECEIVING,
GDB_LOOP_CONTINUE,
GDB_LOOP_ERROR,
};

/**
* Memory region descriptions used for GDB memory access.
*
Expand Down
23 changes: 9 additions & 14 deletions subsys/debug/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,9 @@ int z_gdb_main_loop(struct gdb_ctx *ctx)
* not have enough space.
*/
static uint8_t buf[GDB_PACKET_SIZE];
enum gdb_loop_state state;

enum loop_state {
RECEIVING,
CONTINUE,
ERROR,
} state;

state = RECEIVING;
state = GDB_LOOP_RECEIVING;

/* Only send exception if this is not the first
* GDB break.
Expand All @@ -616,7 +611,7 @@ int z_gdb_main_loop(struct gdb_ctx *ctx)
#define CHECK_ERROR(condition) \
{ \
if ((condition)) { \
state = ERROR; \
state = GDB_LOOP_ERROR; \
break; \
} \
}
Expand All @@ -633,7 +628,7 @@ int z_gdb_main_loop(struct gdb_ctx *ctx)
CHECK_ERROR(ptr == NULL); \
}

while (state == RECEIVING) {
while (state == GDB_LOOP_RECEIVING) {
uint8_t *ptr;
size_t data_len, pkt_len;
uintptr_t addr;
Expand Down Expand Up @@ -718,7 +713,7 @@ int z_gdb_main_loop(struct gdb_ctx *ctx)
*/
case 'c':
arch_gdb_continue();
state = CONTINUE;
state = GDB_LOOP_CONTINUE;
break;

/*
Expand All @@ -727,7 +722,7 @@ int z_gdb_main_loop(struct gdb_ctx *ctx)
*/
case 's':
arch_gdb_step();
state = CONTINUE;
state = GDB_LOOP_CONTINUE;
break;

/*
Expand Down Expand Up @@ -800,7 +795,7 @@ int z_gdb_main_loop(struct gdb_ctx *ctx)
/* breakpoint/watchpoint not supported */
gdb_send_packet(NULL, 0);
} else if (ret == -1) {
state = ERROR;
state = GDB_LOOP_ERROR;
} else {
gdb_send_packet("OK", 2);
}
Expand All @@ -826,9 +821,9 @@ int z_gdb_main_loop(struct gdb_ctx *ctx)
* If this is an recoverable error, send an error message to
* GDB and continue the debugging session.
*/
if (state == ERROR) {
if (state == GDB_LOOP_ERROR) {
gdb_send_packet(GDB_ERROR_GENERAL, 3);
state = RECEIVING;
state = GDB_LOOP_RECEIVING;
}
}

Expand Down

0 comments on commit e410e2b

Please sign in to comment.