# HG changeset patch # User Michael Pavone # Date 1393800103 28800 # Node ID 624dd5106060f1220108066ed6e4244c77cf5895 # Parent 9324f721efa62ff06adfd270878e1f2c28842c7a Add backtrace (bt) command to 68K debugger diff -r 9324f721efa6 -r 624dd5106060 debug.c --- a/debug.c Sat Mar 01 17:11:06 2014 -0800 +++ b/debug.c Sun Mar 02 14:41:43 2014 -0800 @@ -531,19 +531,49 @@ debugging = 0; break; case 'b': - param = find_param(input_buf); - if (!param) { - fputs("b command requires a parameter\n", stderr); - break; + if (input_buf[1] == 't') { + uint32_t stack = context->aregs[7]; + if (stack >= 0xE00000) { + stack &= 0xFFFF; + uint8_t non_adr_count = 0; + do { + uint32_t bt_address = ram[stack/2] << 16 | ram[stack/2+1]; + bt_address = get_instruction_start(context->native_code_map, bt_address - 2); + if (bt_address) { + stack += 4; + non_adr_count = 0; + uint16_t *bt_pc = NULL; + if (bt_address < 0x400000) { + bt_pc = cart + bt_address/2; + } else if(bt_address > 0xE00000) { + bt_pc = ram + (bt_address & 0xFFFF)/2; + } + m68k_decode(bt_pc, &inst, bt_address); + m68k_disasm(&inst, input_buf); + printf("%X: %s\n", bt_address, input_buf); + } else { + //non-return address value on stack can be word wide + stack += 2; + non_adr_count++; + } + stack &= 0xFFFF; + } while (stack && non_adr_count < 6); + } + } else { + param = find_param(input_buf); + if (!param) { + fputs("b command requires a parameter\n", stderr); + break; + } + value = strtol(param, NULL, 16); + insert_breakpoint(context, value, (uint8_t *)debugger); + new_bp = malloc(sizeof(bp_def)); + new_bp->next = breakpoints; + new_bp->address = value; + new_bp->index = bp_index++; + breakpoints = new_bp; + printf("68K Breakpoint %d set at %X\n", new_bp->index, value); } - value = strtol(param, NULL, 16); - insert_breakpoint(context, value, (uint8_t *)debugger); - new_bp = malloc(sizeof(bp_def)); - new_bp->next = breakpoints; - new_bp->address = value; - new_bp->index = bp_index++; - breakpoints = new_bp; - printf("68K Breakpoint %d set at %X\n", new_bp->index, value); break; case 'a': param = find_param(input_buf); diff -r 9324f721efa6 -r 624dd5106060 m68k_to_x86.h --- a/m68k_to_x86.h Sat Mar 01 17:11:06 2014 -0800 +++ b/m68k_to_x86.h Sun Mar 02 14:41:43 2014 -0800 @@ -73,6 +73,7 @@ void insert_breakpoint(m68k_context * context, uint32_t address, uint8_t * bp_handler); void remove_breakpoint(m68k_context * context, uint32_t address); m68k_context * m68k_handle_code_write(uint32_t address, m68k_context * context); +uint32_t get_instruction_start(native_map_slot * native_code_map, uint32_t address); #endif //M68K_TO_X86_H_