From f93ae3d0b1d2c92859ffb1838c4b6edbaaa1b828 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Wed, 23 Dec 2009 22:23:21 +0000 Subject: [PATCH] core: No longer crash if "codeline" is missing Debug macros were crashing if the symbols had not been loaded, and they are never loaded when usin a .hex file Signed-off-by: Michel Pollet --- simavr/sim/sim_core.c | 2 +- simavr/sim/sim_core.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/simavr/sim/sim_core.c b/simavr/sim/sim_core.c index 94de8f6..51d8c33 100644 --- a/simavr/sim/sim_core.c +++ b/simavr/sim/sim_core.c @@ -58,7 +58,7 @@ int donttrace = 0; #define STATE(_f, args...) { \ if (avr->trace) {\ - if (avr->codeline[avr->pc>>1]) {\ + if (avr->codeline && avr->codeline[avr->pc>>1]) {\ const char * symn = avr->codeline[avr->pc>>1]->symbol; \ int dont = 0 && dont_trace(symn);\ if (dont!=donttrace) { \ diff --git a/simavr/sim/sim_core.h b/simavr/sim/sim_core.h index 1e9113d..fb818a0 100644 --- a/simavr/sim/sim_core.h +++ b/simavr/sim/sim_core.h @@ -61,7 +61,9 @@ void avr_dump_state(avr_t * avr); for (int i = avr->stack_frame_index; i; i--) {\ int pci = i-1;\ printf("\e[31m*** %04x: %-25s sp %04x\e[0m\n",\ - avr->stack_frame[pci].pc, avr->codeline[avr->stack_frame[pci].pc>>1]->symbol, avr->stack_frame[pci].sp);\ + avr->stack_frame[pci].pc, \ + avr->codeline ? avr->codeline[avr->stack_frame[pci].pc>>1]->symbol : "unknown", \ + avr->stack_frame[pci].sp);\ } #else #define DUMP_STACK() @@ -73,7 +75,7 @@ void avr_dump_state(avr_t * avr); for (int i = OLD_PC_SIZE-1; i > 0; i--) {\ int pci = (avr->old_pci + i) & 0xf;\ printf("\e[31m*** %04x: %-25s RESET -%d; sp %04x\e[0m\n",\ - avr->old[pci].pc, avr->codeline[avr->old[pci].pc>>1]->symbol, OLD_PC_SIZE-i, avr->old[pci].sp);\ + avr->old[pci].pc, avr->codeline ? avr->codeline[avr->old[pci].pc>>1]->symbol : "unknown", OLD_PC_SIZE-i, avr->old[pci].sp);\ }\ printf("Stack Ptr %04x/%04x = %d \n", _avr_sp_get(avr), avr->ramend, avr->ramend - _avr_sp_get(avr));\ DUMP_STACK();\ -- 2.39.5