--- uae/src/debug.c 2018/04/24 16:39:56 1.1.1.3 +++ uae/src/debug.c 2018/04/24 16:54:44 1.1.1.7 @@ -31,15 +31,20 @@ static uaecptr skipaddr; static int do_skip; int debugging = 0; -void activate_debugger(void) +static FILE *logfile; + +void activate_debugger (void) { + if (logfile) + fclose (logfile); + logfile = 0; do_skip = 0; if (debugger_active) return; debugger_active = 1; regs.spcflags |= SPCFLAG_BRK; debugging = 1; - use_debugger = 1; + /* use_debugger = 1; */ } int firsthist = 0; @@ -51,19 +56,19 @@ union flagu historyf[MAX_HIST]; uaecptr history[MAX_HIST]; #endif -static void ignore_ws(char **c) +static void ignore_ws (char **c) { while (**c && isspace(**c)) (*c)++; } -static uae_u32 readhex(char **c) +static uae_u32 readhex (char **c) { uae_u32 val = 0; char nc; - ignore_ws(c); + ignore_ws (c); - while (isxdigit(nc = **c)){ + while (isxdigit(nc = **c)) { (*c)++; val *= 16; nc = toupper(nc); @@ -76,28 +81,28 @@ static uae_u32 readhex(char **c) return val; } -static char next_char(char **c) +static char next_char( char **c) { - ignore_ws(c); + ignore_ws (c); return *(*c)++; } -static int more_params(char **c) +static int more_params (char **c) { - ignore_ws(c); + ignore_ws (c); return (**c) != 0; } -static void dumpmem(uaecptr addr, uaecptr *nxmem, int lines) +static void dumpmem (uaecptr addr, uaecptr *nxmem, int lines) { broken_in = 0; - for (;lines-- && !broken_in;){ + for (;lines-- && !broken_in;) { int i; - printf("%08lx ", addr); - for(i=0; i< 16; i++) { - printf("%04x ", get_word(addr)); addr += 2; + printf ("%08lx ", addr); + for (i = 0; i < 16; i++) { + printf ("%04x ", get_word(addr)); addr += 2; } - printf("\n"); + printf ("\n"); } *nxmem = addr; } @@ -122,18 +127,18 @@ static void foundmod (uae_u32 ptr, char /* Add sample lengths */ ptr2 += 0x2A; - for(i = 0; i < 31; i++, ptr2 += 30) + for (i = 0; i < 31; i++, ptr2 += 30) length += 2*((ptr2[0]<<8)+ptr2[1]); - printf("Name \"%s\", Length 0x%lx bytes.\n", name, length); + printf ("Name \"%s\", Length 0x%lx bytes.\n", name, length); } -static void modulesearch(void) +static void modulesearch (void) { uae_u8 *p = get_real_address (0); uae_u32 ptr; - for (ptr = 0; ptr < chipmem_size - 40; ptr += 2, p += 2) { + for (ptr = 0; ptr < allocated_chipmem - 40; ptr += 2, p += 2) { /* Check for Mahoney & Kaktus */ /* Anyone got the format of old 15 Sample (SoundTracker)modules? */ if (ptr >= 0x438 && p[0] == 'M' && p[1] == '.' && p[2] == 'K' && p[3] == '.') @@ -172,13 +177,118 @@ static void modulesearch(void) } } -void debug(void) +/* cheat-search by Holger Jakob */ +static void cheatsearch (char **c) +{ + uae_u8 *p = get_real_address (0); + static uae_u32 *vlist = NULL; + uae_u32 ptr; + uae_u32 val = 0; + uae_u32 type = 0; /* not yet */ + uae_u32 count = 0; + uae_u32 fcount = 0; + uae_u32 full = 0; + char nc; + + ignore_ws (c); + + while (isxdigit (nc = **c)) { + (*c)++; + val *= 10; + nc = toupper (nc); + if (isdigit (nc)) { + val += nc - '0'; + } + } + if (vlist == NULL) { + vlist = malloc (256*4); + if (vlist != 0) { + for (count = 0; count<255; count++) + vlist[count] = 0; + count = 0; + for (ptr = 0; ptr < allocated_chipmem - 40; ptr += 2, p += 2) { + if (ptr >= 0x438 && p[3] == (val & 0xff) + && p[2] == (val >> 8 & 0xff) + && p[1] == (val >> 16 & 0xff) + && p[0] == (val >> 24 & 0xff)) + { + if (count < 255) { + vlist[count++]=ptr; + printf ("%08x: %x%x%x%x\n",ptr,p[0],p[1],p[2],p[3]); + } else + full = 1; + } + } + printf ("Found %d possible addresses with %d\n",count,val); + printf ("Now continue with 'g' and use 'C' with a different value\n"); + } + } else { + for (count = 0; count<255; count++) { + if (p[vlist[count]+3] == (val & 0xff) + && p[vlist[count]+2] == (val>>8 & 0xff) + && p[vlist[count]+1] == (val>>16 & 0xff) + && p[vlist[count]] == (val>>24 & 0xff)) + { + fcount++; + printf ("%08x: %x%x%x%x\n", vlist[count], p[vlist[count]], + p[vlist[count]+1], p[vlist[count]+2], p[vlist[count]+3]); + } + } + printf ("%d hits of %d found\n",fcount,val); + free (vlist); + vlist = NULL; + } +} + +static void writeintomem (char **c) { - char input[80],c; + uae_u8 *p = get_real_address (0); + uae_u32 addr = 0; + uae_u32 val = 0; + char nc; + + ignore_ws(c); + while (isxdigit(nc = **c)) { + (*c)++; + addr *= 16; + nc = toupper(nc); + if (isdigit(nc)) { + addr += nc - '0'; + } else { + addr += nc - 'A' + 10; + } + } + ignore_ws(c); + while (isxdigit(nc = **c)) { + (*c)++; + val *= 10; + nc = toupper(nc); + if (isdigit(nc)) { + val += nc - '0'; + } + } + + if (addr < allocated_chipmem) { + p[addr] = val>>24 & 0xff; + p[addr+1] = val>>16 & 0xff; + p[addr+2] = val>>8 & 0xff; + p[addr+3] = val & 0xff; + printf("Wrote %d at %08x\n",val,addr); + } else + printf("Invalid address %08x\n",addr); +} + +void debug (void) +{ + char input[80]; uaecptr nextpc,nxdis,nxmem; bogusframe = 1; + if (do_skip && skipaddr == 0xC0DEDBAD) { + m68k_dumpstate (logfile, &nextpc); + } + if (do_skip && (m68k_getpc() != skipaddr/* || regs.a[0] != 0x1e558*/)) { regs.spcflags |= SPCFLAG_BRK; return; @@ -196,22 +306,24 @@ void debug(void) if (++firsthist == MAX_HIST) firsthist = 0; } - m68k_dumpstate(&nextpc); + m68k_dumpstate (stdout, &nextpc); nxdis = nextpc; nxmem = 0; - for(;;){ - char cmd,*inptr; + for (;;) { + char cmd, *inptr; - printf(">"); + printf (">"); fflush (stdout); - if (fgets(input, 80, stdin) == 0) + if (fgets (input, 80, stdin) == 0) return; inptr = input; - cmd = next_char(&inptr); - switch(cmd){ - case 'c': dumpcia(); dumpcustom(); break; - case 'r': m68k_dumpstate(&nextpc); break; - case 'M': modulesearch(); break; + cmd = next_char (&inptr); + switch (cmd) { + case 'c': dumpcia (); dumpdisk (); dumpcustom (); break; + case 'r': m68k_dumpstate (stdout, &nextpc); break; + case 'M': modulesearch (); break; + case 'C': cheatsearch (&inptr); break; + case 'W': writeintomem (&inptr); break; case 'S': { uae_u8 *memp; @@ -269,7 +381,7 @@ void debug(void) count = readhex(&inptr); else count = 10; - m68k_disasm(daddr, &nxdis, count); + m68k_disasm (stdout, daddr, &nxdis, count); } break; case 't': regs.spcflags |= SPCFLAG_BRK; return; @@ -280,9 +392,11 @@ void debug(void) return; case 'f': - skipaddr = readhex(&inptr); + skipaddr = readhex (&inptr); do_skip = 1; regs.spcflags |= SPCFLAG_BRK; + if (skipaddr == 0xC0DEDBAD) + logfile = fopen ("uae.trace", "w"); return; case 'q': uae_quit(); @@ -321,9 +435,9 @@ void debug(void) #ifdef NEED_TO_DEBUG_BADLY regs = history[temp]; regflags = historyf[temp]; - m68k_dumpstate(NULL); + m68k_dumpstate (NULL); #else - m68k_disasm(history[temp], NULL, 1); + m68k_disasm (stdout, history[temp], NULL, 1); #endif if (++temp == MAX_HIST) temp = 0; } @@ -362,6 +476,8 @@ void debug(void) printf (" f
: Step forward until PC == \n"); printf (" H