/***************************************************************************** * file: dbaction.c * * Purpose: * * This file contains all action routines for OLCDBG. */ #include #include #include #ifdef PCDOS #include #include #include #else #include #endif #include "platform.h" #include "olc96fa.h" /* OLC Fall Semester 96 schema input file */ #include "olc3com.h" #include "activec.h" #include "activei.h" #include "eventin.h" #include "statemo.h" #include "procarch.h" #include "dbutils.h" #include "console.h" #include "dbaction.h" #ifdef PCDOS /* #define printf cprintf */ #endif PROTOTYPE(void DBAction1, (hcg_key EIid)) /*------------------------------------------------------------------- * Globals */ struct cpu_type { int pc; } cpu ; /* * List of possible OLCDBG debugger commands with function calls and * number of "possible" input arguments. */ enum Dbgcmd { STEP = 0, LIST, SELECT, RUN, REGISTER, RESET, MMODIFY, MDUMP, WATCH, STATE, QUIT, BREAK, CONTINUE, UNUSED_COMMAND }; DBG_CMD_DEF dbgcmd[MAX_CMDS] = { {"STEP", step_cmd, 1}, {"LIST", list_cmd, 3}, {"SELECT", select_cmd, 1}, {"RUN", run_cmd, 1}, {"REGISTER", register_cmd, 2}, {"RESET", reset_cmd, 2}, {"MMODIFY", mem_mod_cmd, 4}, {"MDUMP", mem_dump_cmd, 3}, {"WATCH", watch_cmd, 3}, {"STATE", state_cmd, 1}, {"QUIT", quit_cmd, 0}, {"BREAK", ibreak_cmd, 1}, {"CONTINUE", continue_cmd, 0} } ; OLCDBG_DEF olcdbg ; PREV_CMD_DEF prev_cmd ; #define W_LAST 1 /* last screen update included watch output */ #define S_LAST 2 /* last screen update included state output */ #define B_LAST 3 /* last screen update included break output */ #define XBREAK -1 long last_window = W_LAST ; /* start with watch output */ long pc = 1L; /*------------------------------------------------------------------- * external routine definitions */ extern void get_eiq_desc_at_pc(long pc, char *Instance); extern void get_eiq_desc_at_break(long pc, char *Instance); extern hcg_key get_eiq_eid_at_pc(long pc); extern hcg_key get_eiq_eid_at_break(long pc) ; extern void ProcessOneEvent(hcg_key EIid); extern void disp_ai_packet(long idx, char *Instance) ; /*------------------------------------------------------------------- * local routine definitions */ void init_db(); void get_db_cmd() ; void step_eiq_window(int x, int y, char *inst, int show_ptr) ; void move_eiq_window(int pc) ; void disp_eiq_header(int x, int y); void move_ai_window(void) ; void disp_ai_header(int x, int y); void show_c_window(); void get_word(char **lstr, char **wstr); void my_strupr(char *astr); long str2long(char *astr); int printf_dbg(const char *fmt, ...); /* */ /****************************************************/ /* */ /* Initialize Debugger */ /* */ /****************************************************/ FUNCTION1( void DBAction1, hcg_key, EIid ) { printf("Hello\n"); init_db() ; for (;;) get_db_cmd() ; } /* */ /*=================================================================== * * Function Name: init_db() * * Description: This function initializes the CHGEN debugger (olcdbg) * environment. */ void init_db() { long i,j; char str[80] ; cpu.pc = 1 ; /* initialize watch and break points */ for (j=0; j "); /* display prompt */ fflush(stdout); } /* */ /*=================================================================== * * Function Name: my_strupr() * * Description: This function converts the input string to upper case * */ void my_strupr(char *astr) { /* convert string to upper case */ for (; *astr != 0; astr++) *astr = toupper(*astr); } /*=================================================================== * * Function Name: str2long() * * Description: This function converts input hex or decimal string to * integer format. * */ long str2long(char *astr) { long temp ; /* convert hex or decimal string to integer format */ if ( *astr == '0' && toupper(*(astr+1)) == 'X') sscanf(astr+2,"%lx",&temp); else temp = atoi(astr); return(temp); } /* */ /*=================================================================== * * Function Name: get_word() * * Description: This function takes the input string, finds first * non-blank, and returns pointer to this "word". Also, * before exiting, the input string pointer is moved to the * next word for subsequent calls to this function. * */ void get_word(char **lstr, char **wstr) { char *p, *q ; /*find first non-blank */ for (p=*lstr; *p == ' '; p++) ; *wstr = p ; /*find next blank */ for (q=p; *q != 0 && !(*q == ' '); q++) ; /* find remaining line */ if (*q != 0 ) { *lstr = q+1; /* point to location following ' ' */ *q = 0 ; /* nullify location of ' ' */ } else *lstr = q ; /* return null pointer */ } /* */ /*=================================================================== * * Function Name: get_db_cmd() * * Description: This function executes the next SIS debugger command. * */ void get_db_cmd() { int cmd ; long pc ; char line[80] ; char estr[80] ; int stat ; char *pstr, *dbgstr ; #if 0 /* Display last middle window */ if ( last_window == W_LAST ) show_w_window(); else if ( last_window == S_LAST ) show_s_window(); else if ( last_window == B_LAST ) show_b_window(); #endif /* Show command prompt */ show_c_window(); /* Get debug command line */ gets(line); pstr = line ; get_word(&pstr,&dbgstr); /* get command */ my_strupr(dbgstr); /* convert to upper case */ if ( *dbgstr == 0 ) /* nothing entered - re-execute last command */ { stat = (*prev_cmd.func)(prev_cmd.iarg,prev_cmd.pstr) ; if ( stat != 0 ) { sprintf(estr,"Command failed for %-20s",line); printf_dbg(estr); return ; } } else { /* lookup input command in table */ for (cmd=0; cmd". * */ void step_eiq_window(int x, int y, char *instance, int current_pc) { char istr[80] ; console_clear_line(x,y,X_EQWIN_MAX); /* clear line */ console_move(x,y); /* move to line */ if (current_pc) { console_bgvideo(1); /* switch video color */ sprintf(istr,"> %-20s\n",instance); printf(istr); /* print message */ console_bgvideo(0); /* normal video color */ } else { sprintf(istr," %-20s\n",instance); printf(istr); } } /* */ /*=================================================================== * * Function Name: disp_ai_header() * * Description: This function displays contents of the Active Instance * queue in the form "AI Cur State". */ void disp_ai_header(int x, int y) { long i ; console_clear_line(x,y,X_PWIN_MAX); console_move(x,y); console_bgvideo(1); /* switch video color */ printf("AI Cur State\n"); console_bgvideo(0); /* normal video color */ /* clear Active Instance window */ for (i=1; i<10; i++) console_clear_line(1+X_PWIN,i+5,X_EQWIN_MAX); } /* */ /*=================================================================== * * Function Name: move_ai_window() * * Description: This function displays the Active Instances referenced within * the first N entries in the Active Instance queue. The * display is in form "AI Cur State" */ void move_ai_window(void) { long i ; char idescrip[80] ; /* Instance description */ /* display header */ disp_ai_header(1+X_PWIN,5) ; for (i=1;;i++) { disp_ai_packet(i,idescrip); if (idescrip[0] != '\0' ) { console_move(1+X_PWIN,i+6) ; printf(idescrip); } else break ; } } /* */ /*=================================================================== * * Function Name: move_eiq_window() * * Description: This function dissambles the Event Instance found at Event * Queue index == pc and displays it in the appropriate * "Asrc Ek Adest" format within the event instance view. */ void move_eiq_window(int pc) { long lineno,y,start; long current_pc ; long vaddr, inst ; char idescrip[80] ; /* Instance description */ char istr[80] ; char tstr[80] ; if (pc < 5L ) start = 1L ; /* start at first instance */ else start = pc - 5L; /* offset by 5 instances */ /* display Event Instance Queue (EIQ) " idx Asrc Ek Adest" header */ disp_eiq_header(1,5); /* * Starting at console line number "y=2L" display Y_EQWIN_MAX * Event Instance(s) within the debugger EIQ window. */ for (lineno=start, y=7L; lineno" PC pointer */ step_eiq_window(1L,y,idescrip,current_pc); } } /* */ /*=================================================================== * * Function Name: step_cmd() * * Description: This function executes the step command. * */ int step_cmd(int iarg, char *sarg) { char *lstr ; int i, j, pc ; long idx, status ; hcg_key EIid; hcg_key AIid; char idescrip[80] ; long cnt = 1L ; if (*sarg != 0) /* command argument(s) present */ { get_word(&sarg,&lstr); cnt = str2long(lstr) ; /* step cnt times before returning */ } /* Step cnt times and adjust instruction window accordingly */ pc = cpu.pc ; EIid = EventInstanceFirst(); if ( (long)EIid == XBREAK ) { EIid = get_eiq_eid_at_break(pc) ; if ( EIid == 0 ) { printf_dbg("FATAL: Could not find breakpoint instruction"); return 0 ; } } for (j=0; j