comparison debug.c @ 2216:4e27c36f947c

Add disassemble command to debugger
author Michael Pavone <pavone@retrodev.com>
date Tue, 30 Aug 2022 18:42:45 -0700
parents 7591c67b8d1e
children 6a07b13894f7
comparison
equal deleted inserted replaced
2215:a8af8d898a7c 2216:4e27c36f947c
1882 //TODO: Make sure we don't wander into an invalid memory region 1882 //TODO: Make sure we don't wander into an invalid memory region
1883 } while (stack && non_adr_count < 6); 1883 } while (stack && non_adr_count < 6);
1884 return 1; 1884 return 1;
1885 } 1885 }
1886 1886
1887 static uint8_t cmd_disassemble_m68k(debug_root *root, parsed_command *cmd)
1888 {
1889 m68k_context *context = root->cpu_context;
1890 uint32_t address = root->address;
1891 if (cmd->num_args) {
1892 address = cmd->args[0].value;
1893 }
1894 char disasm_buf[1024];
1895 m68kinst inst;
1896 do {
1897 label_def *def = find_label(root->disasm, address);
1898 if (def) {
1899 for (uint32_t i = 0; i < def->num_labels; i++)
1900 {
1901 printf("%s:\n", def->labels[i]);
1902 }
1903 }
1904
1905 address = m68k_decode(m68k_instruction_fetch, context, &inst, address);
1906 m68k_disasm_labels(&inst, disasm_buf, root->disasm);
1907 printf("\t%s\n", disasm_buf);
1908 } while(!m68k_is_terminal(&inst));
1909 return 1;
1910 }
1911
1887 static uint8_t cmd_vdp_sprites(debug_root *root, parsed_command *cmd) 1912 static uint8_t cmd_vdp_sprites(debug_root *root, parsed_command *cmd)
1888 { 1913 {
1889 m68k_context *context = root->cpu_context; 1914 m68k_context *context = root->cpu_context;
1890 genesis_context * gen = context->system; 1915 genesis_context * gen = context->system;
1891 vdp_print_sprite_table(gen->vdp); 1916 vdp_print_sprite_table(gen->vdp);
2262 }, 2287 },
2263 .usage = "delete BREAKPOINT", 2288 .usage = "delete BREAKPOINT",
2264 .desc = "Remove breakpoint identified by BREAKPOINT", 2289 .desc = "Remove breakpoint identified by BREAKPOINT",
2265 .impl = cmd_delete_m68k, 2290 .impl = cmd_delete_m68k,
2266 .min_args = 1, 2291 .min_args = 1,
2292 .max_args = 1
2293 },
2294 {
2295 .names = (const char *[]){
2296 "disassemble", "disasm", NULL
2297 },
2298 .usage = "disassemble [ADDRESS]",
2299 .desc = "Disassemble code starting at ADDRESS if provided or the current address if not",
2300 .impl = cmd_disassemble_m68k,
2301 .min_args = 0,
2267 .max_args = 1 2302 .max_args = 1
2268 } 2303 }
2269 }; 2304 };
2270 2305
2271 #define NUM_68K (sizeof(m68k_commands)/sizeof(*m68k_commands)) 2306 #define NUM_68K (sizeof(m68k_commands)/sizeof(*m68k_commands))
2503 //TODO: Make sure we don't wander into an invalid memory region 2538 //TODO: Make sure we don't wander into an invalid memory region
2504 } while (stack && non_adr_count < 6); 2539 } while (stack && non_adr_count < 6);
2505 return 1; 2540 return 1;
2506 } 2541 }
2507 2542
2543 static uint8_t cmd_disassemble_z80(debug_root *root, parsed_command *cmd)
2544 {
2545 z80_context *context = root->cpu_context;
2546 uint32_t address = root->address;
2547 if (cmd->num_args) {
2548 address = cmd->args[0].value;
2549 }
2550 char disasm_buf[1024];
2551 z80inst inst;
2552 do {
2553 label_def *def = find_label(root->disasm, address);
2554 if (def) {
2555 for (uint32_t i = 0; i < def->num_labels; i++)
2556 {
2557 printf("%s:\n", def->labels[i]);
2558 }
2559 }
2560 uint8_t *pc = get_native_pointer(address, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
2561 uint8_t *after = z80_decode(pc, &inst);
2562 z80_disasm(&inst, disasm_buf, address);
2563 address += after - pc;
2564 printf("\t%s\n", disasm_buf);
2565 } while(!z80_is_terminal(&inst));
2566 return 1;
2567 }
2568
2508 static uint8_t cmd_gen_m68k(debug_root *root, parsed_command *cmd) 2569 static uint8_t cmd_gen_m68k(debug_root *root, parsed_command *cmd)
2509 { 2570 {
2510 char *param = cmd->raw; 2571 char *param = cmd->raw;
2511 while (param && *param && isblank(*param)) 2572 while (param && *param && isblank(*param))
2512 { 2573 {
2616 }, 2677 },
2617 .usage = "delete BREAKPOINT", 2678 .usage = "delete BREAKPOINT",
2618 .desc = "Remove breakpoint identified by BREAKPOINT", 2679 .desc = "Remove breakpoint identified by BREAKPOINT",
2619 .impl = cmd_delete_z80, 2680 .impl = cmd_delete_z80,
2620 .min_args = 1, 2681 .min_args = 1,
2682 .max_args = 1
2683 },
2684 {
2685 .names = (const char *[]){
2686 "disassemble", "disasm", NULL
2687 },
2688 .usage = "disassemble [ADDRESS]",
2689 .desc = "Disassemble code starting at ADDRESS if provided or the current address if not",
2690 .impl = cmd_disassemble_z80,
2691 .min_args = 0,
2621 .max_args = 1 2692 .max_args = 1
2622 } 2693 }
2623 }; 2694 };
2624 2695
2625 #define NUM_Z80 (sizeof(z80_commands)/sizeof(*z80_commands)) 2696 #define NUM_Z80 (sizeof(z80_commands)/sizeof(*z80_commands))
3236 root->resolve = resolve_z80; 3307 root->resolve = resolve_z80;
3237 } 3308 }
3238 root->read_mem = read_z80; 3309 root->read_mem = read_z80;
3239 root->write_mem = write_z80; 3310 root->write_mem = write_z80;
3240 root->set = set_z80; 3311 root->set = set_z80;
3312 root->disasm = create_z80_disasm();
3241 } 3313 }
3242 return root; 3314 return root;
3243 } 3315 }
3244 3316
3245 z80_context * zdebugger(z80_context * context, uint16_t address) 3317 z80_context * zdebugger(z80_context * context, uint16_t address)