📄 monitor.c
字号:
/* If anything but a y or z command, convert to lower case */ if ( ((*token[0]) != 'y') && ((*token[0]) != 'z') ) lcase_tokens(token, token_count); if ((Indx = FindCmdIndx(token[0])) != (int) FAILURE) io_config.cmd_ready = TRUE; else { warning(EMNOSUCHCMD); /* Print a prompt */ fprintf(stderr, "\n%s>", ProgramName); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "\n%s>", ProgramName); io_config.cmd_ready = FALSE; /* nothing to execute */ } } /* ** Execute command */ if (io_config.cmd_ready == TRUE) { retval = MonitorCommands[Indx].CmdFn(token, token_count); io_config.cmd_ready = FALSE; if (retval == FAILURE) { fprintf(stderr, "Command failed\n"); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Command failed\n"); } else if (retval != SUCCESS) { warning(retval); }; /* Print a prompt */ if (io_config.io_control == TERM_USER) { fprintf(stderr, "%s>", ProgramName); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "%s>", ProgramName); } else { display_term29k(); } } /* if cmd ready */ } while (exit_loop != TRUE); /* end of do-while */ /* Close log file */ if (io_config.log_mode == (INT32) TRUE) (void) fclose(io_config.log_file); if (bkpt_table != NULL) (void) free((char *) bkpt_table);}/*** This function takes in a string and produces a lower case,** " argv - argc" style array. Then number of elements in the** array is returned.*/inttokenize_cmd(cmd, token) char *cmd; char *token[]; { int token_count; /* Break input into tokens */ token_count = 0; token[0] = cmd; if (cmd[0] != '\0') { token[token_count] = strtok(cmd, " \t,;\n\r"); if (token[token_count] != NULL) { do { token_count = token_count + 1; token[token_count] = strtok((char *) NULL, " \t,;\n\r"); } while ((token[token_count] != NULL) && (token_count < MAX_TOKENS)); } else { token[0] = cmd; *token[0] = '\0'; } } return (token_count); } /* end tokenize_cmd() *//*** This function is used to convert a list of tokens** to all lower case letters.*/voidlcase_tokens(token, token_count) char *token[MAX_TOKENS]; int token_count; { int i; char *temp_str; for (i=0; i<token_count; i=i+1) { temp_str = token[i]; while (*temp_str != '\0') { if (isupper(*temp_str)) *temp_str = (char) tolower(*temp_str); temp_str++; } } /* end for() */ } /* end lcase_string() */INT32Mini_go_forever(){ static int complete=0; /* Terminal control initialization. */ io_config.io_control = TERM_USER; /* 3.1-7 */ io_config.target_running = TRUE;#ifndef MSDOS ioctl (fileno(stdin), TCGETA, &OldTermbuf); /* Initial settings */#endif /* Install ctrl-C handler */ if (signal (SIGINT, Mini_Ctrl_C_Handler) == SIG_ERR) { fprintf(stderr, "Ctrl-C handler not installed.\n"); /* warning */ if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Ctrl-C handler not installed.\n"); /* warning */ } /* ** Open cmd file (if necessary) */ if (io_config.cmd_file_io == TRUE) { /* TRUE if -c option given */ io_config.cmd_file = fopen(io_config.cmd_filename, "r"); if (io_config.cmd_file == NULL) { warning (EMCMDOPEN); io_config.cmd_file_io = FALSE; } else { /* MON_STDIN is command file */ MON_STDIN = fileno(io_config.cmd_file); /* set MON_STDIN */ }; } Mini_go(); /* set target running */ do { /* ** If the target was set to run, get its current status. */ if (Mini_get_target_stats((INT32) udi_waittime, &ProcessorState) != SUCCESS) { Mini_TIP_DestroyProc(); Mini_TIP_exit(); fatal_error(EMFATAL); } GrossState = (int) (ProcessorState & 0xFF); switch (GrossState) { case NOTEXECUTING: /* do nothing */ io_config.io_control = TERM_USER; io_config.target_running = FALSE; break; case EXITED: /* do nothing */ if (!QuietMode) { fprintf (stderr, "Process exited with 0x%lx\n", (ProcessorState >> 8)); if (io_config.echo_mode == (INT32) TRUE) fprintf (io_config.echo_file, "Process exited with 0x%lx\n", (ProcessorState >> 8)); } io_config.io_control = TERM_USER; io_config.target_running = FALSE; complete=1; break; case RUNNING: /* any request from target? */ break; case STOPPED: complete=1; io_config.io_control = TERM_USER; io_config.target_running = FALSE; fprintf(stderr, "Execution stopped at "); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Execution stopped at "); display_msg(); break; case BREAK: complete=1; io_config.io_control = TERM_USER; io_config.target_running = FALSE; fprintf(stderr, "Breakpoint hit at "); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Breakpoint hit at "); display_msg(); break; case STEPPED: complete=1; io_config.io_control = TERM_USER; io_config.target_running = FALSE; fprintf(stderr, "Stepping...Execution stopped at "); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Stepping...Execution stopped at "); display_msg(); break; case WAITING: complete=1; io_config.io_control = TERM_USER; io_config.target_running = FALSE; break; case HALTED: complete=1; io_config.io_control = TERM_USER; io_config.target_running = FALSE; fprintf(stderr, "Execution halted at "); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Execution halted at "); display_msg(); break; case WARNED: complete=1; io_config.io_control = TERM_USER; io_config.target_running = FALSE; break; case TRAPPED: complete=1; io_config.io_control = TERM_USER; io_config.target_running = FALSE; PrintTrapMsg((int) (ProcessorState >> 8)); display_msg(); break; case STDOUT_READY: io_bufsize = 0; io_count_done = (INT32) 0; do { Mini_get_stdout(io_buffer, IO_BUFSIZE, &io_count_done); write(MON_STDOUT, &io_buffer[0], (int) io_count_done); if (io_config.echo_mode == (INT32) TRUE) { fflush (io_config.echo_file); write (fileno(io_config.echo_file), &io_buffer[0], (int) io_count_done); } } while (io_count_done == (INT32) IO_BUFSIZE); break; case STDERR_READY: io_bufsize = 0; io_count_done = (INT32) 0; do { Mini_get_stderr(io_buffer, IO_BUFSIZE, &io_count_done); write(MON_STDERR, &io_buffer[0], (int) io_count_done); if (io_config.echo_mode == (INT32) TRUE) { fflush (io_config.echo_file); write (fileno(io_config.echo_file), &io_buffer[0], (int) io_count_done); } } while (io_count_done == (INT32) IO_BUFSIZE); break; case STDIN_NEEDED: /* Line buffered reads only */ if (io_config.cmd_file_io == TRUE) { /* read from command file */ if (Mini_cmdfile_input(io_buffer, IO_BUFSIZE) == SUCCESS) { io_bufsize = strlen(io_buffer); fprintf(stderr, "%s", io_buffer); /* echo */ if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "%s", io_buffer); /* echo */ } else { /* read from terminal */ io_bufsize = read( fileno(stdin), io_buffer, IO_BUFSIZE ); } } else { io_bufsize = read( fileno(stdin), io_buffer, IO_BUFSIZE ); }; if (io_bufsize < 0) { fprintf(stderr, "fatal error reading from stdin\n"); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "fatal error reading from stdin\n"); } if (io_config.echo_mode == (INT32) TRUE) { fflush (io_config.echo_file); write (fileno(io_config.echo_file), &io_buffer[0], (int) io_bufsize); } Mini_put_stdin(io_buffer, io_bufsize, &io_count_done); break; case STDINMODEX: /* call TIP to get StdinMode */ Mini_stdin_mode_x((INT32 *)&TipStdinMode); if (TipStdinMode & TIP_NBLOCK) io_config.io_control = TERM_29K; else if (TipStdinMode & TIP_ASYNC) io_config.io_control = TERM_29K; else if (TipStdinMode == TIP_COOKED) io_config.io_control = TERM_USER; else { fprintf(stderr, "DFEWARNING: TIP Requested Stdin Mode Not Supported.\n"); fprintf(stderr, "DFEWARNING: Using default mode.\n"); TipStdinMode = TIP_COOKED; io_config.io_control = TERM_USER; } if (io_config.io_control == TERM_29K) display_term29k(); break; default: complete=1; io_config.io_control = TERM_USER; io_config.target_running = FALSE; break; }; /* end switch */#ifdef MSDOS if (!complete) kbhit(); /* Poll for Ctrl-C */#endif if (CtrlCHit) { CtrlCHit = 0; complete = 1; } if (io_config.io_control == TERM_29K) if (GrossState == RUNNING) Mini_poll_channel0(); /* non-blocking */ else TipStdinMode = TIP_COOKED; } while (!complete);#ifndef MSDOS ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */#endif fflush(stdout); fflush(stderr); Mini_TIP_DestroyProc(); Mini_TIP_exit(); NumberOfConnections=0; return (SUCCESS);}INT32get_pc_addrs(pc1, cps)ADDR32 *pc1;ADDR32 *cps;{ ADDR32 pc_1; ADDR32 cps_b; INT32 hostendian; INT32 bytes_ret; INT32 retval; hostendian = FALSE; if ((retval = Mini_read_req (PC_SPACE, (ADDR32) 0, /* doesn't matter */ (INT32) 1, (INT16) 4, /* size */ &bytes_ret, (BYTE *) &pc_1, hostendian)) != SUCCESS) { return(FAILURE); }; *pc1 = (ADDR32) pc_1; if (host_config.host_endian != host_config.target_endian) { convert32((BYTE *)pc1); } /* get cps */ hostendian = FALSE; if ((retval = Mini_read_req (SPECIAL_REG, (ADDR32) 2, (INT32) 1, (INT16) 4, /* size */ &bytes_ret, (BYTE *) &cps_b, hostendian)) != SUCCESS) { return(FAILURE); }; *cps = (ADDR32) cps_b; if (host_config.host_endian != host_config.target_endian) { convert32((BYTE *)cps); } return (SUCCESS);}INT32get_pc1_inst(cps, pc1, inst)ADDR32 cps;ADDR32 pc1;BYTE *inst;{ INT32 bytes_ret; INT32 hostendian; INT32 retval; INT32 memory_space; hostendian = FALSE; if (cps & 0x100L) /* RE bit */ memory_space = I_ROM; else memory_space = I_MEM; if ((retval = Mini_read_req(memory_space, pc1, (INT32) 1, (INT16) sizeof(INST32), /* size */ &bytes_ret, (BYTE *) inst, hostendian)) != SUCCESS) { return(FAILURE); }; return (SUCCESS);}voiddisplay_msg(){ ADDR32 c_pc1; ADDR32 c_cps; union instruction_t { BYTE buf[sizeof(struct instr_t)]; struct instr_t instr; }; union instruction_t instruction; struct instr_t temp; (void) get_pc_addrs(&c_pc1, &c_cps); (void) get_pc1_inst(c_cps, c_pc1, instruction.buf); fprintf(stderr, " %08lx\n", c_pc1); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, " %08lx\n", c_pc1); if (host_config.target_endian == LITTLE) { temp.op = instruction.instr.b; temp.c = instruction.instr.a; temp.a = instruction.instr.c; temp.b = instruction.instr.op; } else { /* default BIG endian */ temp.op = instruction.instr.op; temp.c = instruction.instr.c; temp.a = instruction.instr.a; temp.b = instruction.instr.b; } fprintf(stderr, "%08lx\t %02x%02x%02x%02x\t", c_pc1, temp.op, temp.c, temp.a, temp.b); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "%08lx\t %02x%02x%02x%02x\t", c_pc1, temp.op, temp.c, temp.a, temp.b); (void) dasm_instr(c_pc1, &(temp)); if (io_config.io_control == TERM_USER) { fprintf(stderr, "\n%s>", ProgramName); fflush(stderr); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "\n%s>", ProgramName); }}intMini_cmdfile_input(cmd_buffer, size)char *cmd_buffer;int size;{ if (fgets(cmd_buffer, size, io_config.cmd_file) == NULL) { io_config.cmd_file_io = FALSE; (void) fclose(io_config.cmd_file); MON_STDIN = fileno (stdin); /* reset to terminal after EOF */ return (FAILURE); } else { return (SUCCESS); }}voidMini_Ctrl_C_Handler(num)int num;{ CtrlCHit = 1; /* used for run-only mode, no debugging */ if (io_config.io_control == TERM_29K) {#ifndef MSDOS ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */#endif } if (io_config.target_running == TRUE) Mini_break(); io_config.cmd_ready == FALSE;#ifdef MSDOS if (signal (SIGINT, Mini_Ctrl_C_Handler) == SIG_ERR) { fprintf(stderr, "Ctrl-C handler not installed.\n"); /* warning */ if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Ctrl-C handler not installed.\n"); /* warning */ }#endif return;}static intFindCmdIndx(CmdString)char *CmdString;{ int i; i = 0; while (MonitorCommands[i].CmdString) { if (strcmp(CmdString, MonitorCommands[i].CmdString)) i++; else return (i); }; return (-1);}INT32escape_cmd(token, tokencnt)char **token;int tokencnt;{ int retval;#ifdef MSDOS if ((retval = system ((char *) getenv("COMSPEC"))) != 0) return ((INT32) EMDOSERR); return ((INT32) SUCCESS);#else if ((retval = system ((char *) getenv("SHELL"))) != 0) return ((INT32) EMSYSERR); return ((INT32) SUCCESS);#endif}INT32dummy_cmd(token, tokencnt)char **token;int tokencnt;{ return ((INT32) 0);}INT32quit_cmd(token, tokencnt)char **token;int tokencnt;{ int i; for (i =0; i < NumberOfConnections; i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -