comparison blastem.c @ 515:1495179d6737

Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
author Mike Pavone <pavone@retrodev.com>
date Sat, 08 Feb 2014 23:37:09 -0800
parents a277de8c1a18
children 7f54f1773e84
comparison
equal deleted inserted replaced
514:f66c78cbdcaa 515:1495179d6737
8 #include "z80_to_x86.h" 8 #include "z80_to_x86.h"
9 #include "mem.h" 9 #include "mem.h"
10 #include "vdp.h" 10 #include "vdp.h"
11 #include "render.h" 11 #include "render.h"
12 #include "blastem.h" 12 #include "blastem.h"
13 #include "gdb_remote.h"
13 #include "gst.h" 14 #include "gst.h"
14 #include "util.h" 15 #include "util.h"
15 #include <stdio.h> 16 #include <stdio.h>
16 #include <stdlib.h> 17 #include <stdlib.h>
17 #include <string.h> 18 #include <string.h>
1583 fwrite(genesis->save_ram, 1, size, f); 1584 fwrite(genesis->save_ram, 1, size, f);
1584 fclose(f); 1585 fclose(f);
1585 printf("Saved SRAM to %s\n", sram_filename); 1586 printf("Saved SRAM to %s\n", sram_filename);
1586 } 1587 }
1587 1588
1588 void init_run_cpu(genesis_context * gen, int debug, FILE * address_log, char * statefile) 1589 void init_run_cpu(genesis_context * gen, FILE * address_log, char * statefile, uint8_t * debugger)
1589 { 1590 {
1590 m68k_context context; 1591 m68k_context context;
1591 x86_68k_options opts; 1592 x86_68k_options opts;
1592 gen->m68k = &context; 1593 gen->m68k = &context;
1593 memmap_chunk memmap[MAX_MAP_CHUNKS]; 1594 memmap_chunk memmap[MAX_MAP_CHUNKS];
1704 if (!pc) { 1705 if (!pc) {
1705 fprintf(stderr, "Failed to load save state %s\n", statefile); 1706 fprintf(stderr, "Failed to load save state %s\n", statefile);
1706 exit(1); 1707 exit(1);
1707 } 1708 }
1708 printf("Loaded %s\n", statefile); 1709 printf("Loaded %s\n", statefile);
1709 if (debug) { 1710 if (debugger) {
1710 insert_breakpoint(&context, pc, (uint8_t *)debugger); 1711 insert_breakpoint(&context, pc, debugger);
1711 } 1712 }
1712 adjust_int_cycle(gen->m68k, gen->vdp); 1713 adjust_int_cycle(gen->m68k, gen->vdp);
1713 gen->z80->native_pc = z80_get_native_address_trans(gen->z80, gen->z80->pc); 1714 gen->z80->native_pc = z80_get_native_address_trans(gen->z80, gen->z80->pc);
1714 start_68k_context(&context, pc); 1715 start_68k_context(&context, pc);
1715 } else { 1716 } else {
1716 if (debug) { 1717 if (debugger) {
1717 insert_breakpoint(&context, address, (uint8_t *)debugger); 1718 insert_breakpoint(&context, address, debugger);
1718 } 1719 }
1719 m68k_reset(&context); 1720 m68k_reset(&context);
1720 } 1721 }
1721 } 1722 }
1722 1723
1806 int loaded = 0; 1807 int loaded = 0;
1807 uint8_t force_version = 0; 1808 uint8_t force_version = 0;
1808 char * romfname = NULL; 1809 char * romfname = NULL;
1809 FILE *address_log = NULL; 1810 FILE *address_log = NULL;
1810 char * statefile = NULL; 1811 char * statefile = NULL;
1812 uint8_t * debuggerfun = NULL;
1811 uint8_t fullscreen = 0, use_gl = 1; 1813 uint8_t fullscreen = 0, use_gl = 1;
1812 for (int i = 1; i < argc; i++) { 1814 for (int i = 1; i < argc; i++) {
1813 if (argv[i][0] == '-') { 1815 if (argv[i][0] == '-') {
1814 switch(argv[i][1]) { 1816 switch(argv[i][1]) {
1815 case 'b': 1817 case 'b':
1820 } 1822 }
1821 headless = 1; 1823 headless = 1;
1822 exit_after = atoi(argv[i]); 1824 exit_after = atoi(argv[i]);
1823 break; 1825 break;
1824 case 'd': 1826 case 'd':
1825 debug = 1; 1827 debuggerfun = (uint8_t *)debugger;
1828 break;
1829 case 'D':
1830 gdb_remote_init();
1831 debuggerfun = (uint8_t *)gdb_debug_enter;
1826 break; 1832 break;
1827 case 'f': 1833 case 'f':
1828 fullscreen = 1; 1834 fullscreen = 1;
1829 break; 1835 break;
1830 case 'g': 1836 case 'g':
1978 if (i < 0) { 1984 if (i < 0) {
1979 strcpy(sram_filename + fname_size, ".sram"); 1985 strcpy(sram_filename + fname_size, ".sram");
1980 } 1986 }
1981 set_keybindings(); 1987 set_keybindings();
1982 1988
1983 init_run_cpu(&gen, debug, address_log, statefile); 1989 init_run_cpu(&gen, address_log, statefile, debuggerfun);
1984 return 0; 1990 return 0;
1985 } 1991 }