From 8c526abb7d8c2a0bacddf38a0c187738a6c0bf9a Mon Sep 17 00:00:00 2001 From: Sami Liedes Date: Wed, 2 Feb 2011 22:18:04 +0200 Subject: [PATCH] Return zeros when GDB reads just past end of stack. GDB likes to read the topmost value of stack when using the "stepi" (step instruction) command. Unfortunately this does not work when the stack is empty, causing an error message and GDB confusion. Hack the GDB stub code to just return zeros if GDB tries to read two bytes just past the end of stack. NOTE: This may need to be modified to support also longer reads for bigger AVRs where code pointers are longer than two bytes (e.g. ATMega2560). As simavr doesn't support atm2560 yet, I'm implementing it this way now. --- simavr/sim/sim_gdb.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simavr/sim/sim_gdb.c b/simavr/sim/sim_gdb.c index f2d46ff..9bec4b5 100644 --- a/simavr/sim/sim_gdb.c +++ b/simavr/sim/sim_gdb.c @@ -208,6 +208,12 @@ static void gdb_handle_command(avr_gdb_t * g, char * cmd) gdb_send_reply(g, "E01"); break; } + } else if (addr >= 0x800000 && (addr - 0x800000) == avr->ramend+1 && len == 2) { + // Allow GDB to read a value just after end of stack. + // This is necessary to make instruction stepping work when stack is empty + printf("GDB read just past end of stack %08x, %08x; returning zero\n", addr, len); + gdb_send_reply(g, "0000"); + break; } else { printf("read memory error %08x, %08x (ramend %04x)\n", addr, len, avr->ramend+1); gdb_send_reply(g, "E01"); -- 2.39.5