Annotation of uae/debug.c, revision 1.1.1.2

1.1       root        1:  /* 
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   * 
                      4:   * Debugger
                      5:   * 
                      6:   * (c) 1995 Bernd Schmidt
                      7:   * 
                      8:   */
                      9: 
1.1.1.2 ! root       10: #include "sysconfig.h"
        !            11: #include "sysdeps.h"
        !            12: 
1.1       root       13: #include <ctype.h>
                     14: #include <signal.h>
                     15: 
                     16: #include "config.h"
                     17: #include "options.h"
                     18: #include "debug.h"
                     19: #include "memory.h"
                     20: #include "custom.h"
                     21: #include "newcpu.h"
                     22: #include "cia.h"
                     23: #include "xwin.h"
1.1.1.2 ! root       24: #include "gui.h"
1.1       root       25: 
                     26: #ifdef __cplusplus
1.1.1.2 ! root       27: static RETSIGTYPE sigbrkhandler(...)
1.1       root       28: #else
1.1.1.2 ! root       29: static RETSIGTYPE sigbrkhandler(int foo)
1.1       root       30: #endif
                     31: {
1.1.1.2 ! root       32:     broken_in = 1;
1.1       root       33:     specialflags |= SPCFLAG_BRK;
                     34:     signal(SIGINT, sigbrkhandler);
                     35: }
                     36: 
                     37: static void ignore_ws(char **c)
                     38: {
                     39:     while (**c && isspace(**c)) (*c)++;
                     40: }
                     41: 
                     42: static ULONG readhex(char **c)
                     43: {
                     44:     ULONG val = 0;
                     45:     char nc;
                     46: 
                     47:     ignore_ws(c);
                     48:     
                     49:     while (isxdigit(nc = **c)){
                     50:        (*c)++;
                     51:        val *= 16;
                     52:        nc = toupper(nc);
                     53:        if (isdigit(nc)) {
                     54:            val += nc - '0';
                     55:        } else {
                     56:            val += nc - 'A' + 10;
                     57:        }
                     58:     }
                     59:     return val;
                     60: }
                     61: 
                     62: static char next_char(char **c)
                     63: {
                     64:     ignore_ws(c);
                     65:     return *(*c)++;
                     66: }
                     67: 
1.1.1.2 ! root       68: static int more_params(char **c)
1.1       root       69: {
                     70:     ignore_ws(c);
                     71:     return (**c) != 0;
                     72: }
                     73: 
                     74: static void dumpmem(CPTR addr, CPTR *nxmem, int lines)
                     75: {
1.1.1.2 ! root       76:     broken_in = 0;
1.1       root       77:     for (;lines-- && !broken_in;){
                     78:        int i;
                     79:        printf("%08lx ", addr);
                     80:        for(i=0; i< 16; i++) {
                     81:            printf("%04x ", get_word(addr)); addr += 2;
                     82:        }
                     83:        printf("\n");
                     84:     }
                     85:     *nxmem = addr;
                     86: }
                     87: 
                     88: void debug(void)
                     89: {
                     90:     char input[80],c;
                     91:     CPTR nextpc,nxdis,nxmem;
                     92:     
1.1.1.2 ! root       93:     if (debuggable()) {
        !            94: #if defined(__unix) && !defined(__NeXT__)
        !            95:        struct sigaction sa;
        !            96:        sa.sa_handler = sigbrkhandler;
        !            97: #ifdef SA_RESTART
        !            98:        sa.sa_flags = SA_RESTART;
        !            99: #endif
        !           100:        sigemptyset(&sa.sa_mask);
        !           101:        sigaction(SIGINT, &sa, NULL);
        !           102: #else
        !           103:        signal(SIGINT, sigbrkhandler);
        !           104: #endif
        !           105:     }
1.1       root      106:     if (!debuggable() || !use_debugger) {
                    107:        MC68000_run();
                    108:        if (!debuggable()) {        
                    109:            dumpcustom();
                    110:            return;
                    111:        }
                    112:     }
1.1.1.2 ! root      113:     
        !           114:     if (quit_program)
        !           115:        return;
        !           116: 
1.1       root      117:     printf("debugging...\n");
                    118:     MC68000_dumpstate(&nextpc);
                    119:     nxdis = nextpc; nxmem = 0;
                    120:     for(;;){
                    121:        char cmd,*inptr;
                    122:        
1.1.1.2 ! root      123:        if (quit_program)
        !           124:            return;
        !           125: 
        !           126:        bogusframe = 1;
1.1       root      127:        printf(">");
                    128:        fgets(input, 80, stdin);
                    129:        inptr = input;
                    130:        cmd = next_char(&inptr);
                    131:        switch(cmd){
                    132:         case 'q': 
                    133:            return;
                    134:         case 'c':
                    135:            dumpcia(); dumpcustom(); 
                    136:            break;
                    137:         case 'r':
                    138:            MC68000_dumpstate(&nextpc);
                    139:            break;
                    140:         case 'd': 
                    141:            {
                    142:                ULONG daddr;
                    143:                int count;
                    144:                
                    145:                if (more_params(&inptr))
                    146:                    daddr = readhex(&inptr);
                    147:                else 
                    148:                    daddr = nxdis;
                    149:                if (more_params(&inptr))
                    150:                    count = readhex(&inptr); 
                    151:                else
                    152:                    count = 10;
                    153:                MC68000_disasm(daddr, &nxdis, count);
                    154:            }
                    155:            break;
                    156:         case 't': 
                    157:            MC68000_step(); 
                    158:            MC68000_dumpstate(&nextpc); 
                    159:            break;
                    160:         case 'z': 
                    161:            MC68000_skip(nextpc);
                    162:            MC68000_dumpstate(&nextpc);
                    163:            nxdis = nextpc; 
                    164:            break;
                    165:         case 'f': 
                    166:            MC68000_skip(readhex(&inptr));
                    167:            MC68000_dumpstate(&nextpc); 
                    168:            break;
                    169:         case 'g':
                    170:            if (more_params (&inptr))
                    171:                m68k_setpc (readhex (&inptr));
                    172:            MC68000_run();
                    173:            MC68000_dumpstate(&nextpc);
                    174:            break;
                    175:         case 'm':
                    176:            {
                    177:                ULONG maddr; int lines;
                    178:                if (more_params(&inptr))
                    179:                    maddr = readhex(&inptr); 
                    180:                else 
                    181:                    maddr = nxmem;
                    182:                if (more_params(&inptr))
                    183:                    lines = readhex(&inptr); 
                    184:                else 
                    185:                    lines = 16;
                    186:                dumpmem(maddr, &nxmem, lines);
                    187:            }
                    188:            break;
1.1.1.2 ! root      189:           case 'h':
        !           190:           case '?':
        !           191:            {
        !           192:              printf ("          HELP for UAE Debugger\n");
        !           193:              printf ("         -----------------------\n\n");
        !           194:              printf ("  g: <address>          ");
        !           195:                 printf("Start execution at the current address or <address>.\n");
        !           196:              printf ("  c:                    ");
        !           197:                 printf("Dump state of the CIA and custom chips.\n");
        !           198:              printf ("  r:                    ");
        !           199:                 printf("Dump state of the CPU\n");
        !           200:              printf ("  m <address> <lines>:  ");
        !           201:                 printf ("Memory dump starting at <address>\n");
        !           202:              printf ("  d <address> <lines>:  ");
        !           203:                 printf ("Disassembly starting at <address>\n");
        !           204:              printf ("  t:                    ");
        !           205:                 printf ("Step one instruction\n");
        !           206:              printf ("  z:                    ");
        !           207:                 printf ("Step through one instruction - useful for JSR, DBRA etc\n");
        !           208:              printf ("  f <address>:          ");
        !           209:                 printf ("Step forward until PC == <address>\n");
        !           210:              printf ("  h,?:                  ");
        !           211:                 printf ("Show this help page\n");
        !           212:              printf ("  q:                    ");
        !           213:                 printf ("Quit the emulator. You don't want to use this command.\n\n");
        !           214:             }
        !           215:             break;
        !           216:              
1.1       root      217:        }
                    218:     }
                    219: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.