示例#1
0
static  void    BreakSignal( int sig ) {
//===================================================

    sig = sig;
    signal( SIGINT, BreakSignal );
 #if defined( __OS2__ ) || defined( __NT__ )
    signal( SIGBREAK, BreakSignal );
 #endif
    ProcessBreak();
}
示例#2
0
static  void    _handler BreakHandler( void ) {
//=============================================

    _enable();
    if( __UserBreakHandler != (fsig_func)SIG_DFL ) {
        if( (__UserBreakHandler != (fsig_func)SIG_IGN) &&
            (__UserBreakHandler != (fsig_func)SIG_ERR) ) {
            __UserBreakHandler( SIGBREAK );
        }
    } else {
        ProcessBreak();
    }
}
示例#3
0
Command* Runtime::Debugger::ProcessCommand(const wstring &line) {
#ifdef _DEBUG
  wcout << L"input: |" << line << L"|" << endl;
#endif

  // parser input
  is_next = is_next_line = false;
  Parser parser;
  Command* command = parser.Parse(L"?" + line);
  if(command) {
    switch(command->GetCommandType()) {
    case EXE_COMMAND:
      ProcessExe(static_cast<Load*>(command));
      break;

    case SRC_COMMAND:
      ProcessSrc(static_cast<Load*>(command));
      break;

    case ARGS_COMMAND:
      ProcessArgs(static_cast<Load*>(command));
      break;

    case QUIT_COMMAND:
      ClearBreaks();
      ClearProgram();
      wcout << L"goodbye." << endl;
      exit(0);
      break;

    case LIST_COMMAND: {
      FilePostion* file_pos = static_cast<FilePostion*>(command);

      wstring file_name;
      if(file_pos->GetFileName().size() > 0) {
        file_name = file_pos->GetFileName();
      }
      else {
        file_name = cur_file_name;
      }

      int line_num;
      if(file_pos->GetLineNumber() > 0) {
        line_num = file_pos->GetLineNumber();
      }
      else {
        line_num = cur_line_num;
      }

      const wstring &path = base_path + file_name;
      if(FileExists(path) && line_num > 0) {
        SourceFile src_file(path, cur_line_num);
        if(!src_file.Print(line_num)) {
          wcout << L"invalid line number." << endl;
          is_error = true;
        }
      }
      else {
        wcout << L"source file or line number doesn't exist, ensure the program is running." << endl;
        is_error = true;
      }
    }
      break;

    case BREAK_COMMAND:
      ProcessBreak(static_cast<FilePostion*>(command));
      break;

    case BREAKS_COMMAND:
      ProcessBreaks();
      break;

    case PRINT_COMMAND:
      ProcessPrint(static_cast<Print*>(command));
      break;

    case RUN_COMMAND:
      if(!cur_program) {
        ProcessRun();
      }
      else {
        wcout << L"instance already running." << endl;
        is_error = true;
      }
      break;

    case CLEAR_COMMAND: {
      wcout << L"  are sure you want to clear all breakpoints? [y/n] ";
      wstring line;
      getline(wcin, line);
      if(line == L"y" || line == L"yes") {
        ClearBreaks();
      }
    }
      break;

    case DELETE_COMMAND:
      ProcessDelete(static_cast<FilePostion*>(command));
      break;

    case NEXT_COMMAND:
      if(interpreter) {
        is_next = true;
      }
      else {
        wcout << L"program is not running." << endl;
      }
      break;

    case NEXT_LINE_COMMAND:
      if(interpreter) {
        is_next_line = true;
      }
      else {
        wcout << L"program is not running." << endl;
      }
      break;

    case JUMP_OUT_COMMAND:
      if(interpreter) {
        is_jmp_out = true;
      }
      else {
        wcout << L"program is not running." << endl;
      }
      break;

    case CONT_COMMAND:
      if(!interpreter) {
        wcout << L"program is not running." << endl;
      }
      cur_line_num = -2;
      break;

    case INFO_COMMAND:
      ProcessInfo(static_cast<Info*>(command));
      break;

    case STACK_COMMAND:
      if(interpreter) {
        wcout << L"stack:" << endl;
        StackMethod* method = cur_frame->method;
        wcerr << L"  frame: pos=" << cur_call_stack_pos << L", class=" << method->GetClass()->GetName() 
							<< L", method=" << PrintMethod(method);
        const long ip = cur_frame->ip;
        if(ip > -1) {
          StackInstr* instr = cur_frame->method->GetInstruction(ip);
          wcerr << L", file=" << method->GetClass()->GetFileName() << L":" << instr->GetLineNumber() << endl;
        }
        else {
          wcerr << endl;
        }

        long pos = cur_call_stack_pos - 1;
        do {
          StackMethod* method = cur_call_stack[pos]->method;
          wcerr << L"  frame: pos=" << pos << L", class=" << method->GetClass()->GetName() 
								<< L", method=" << PrintMethod(method);
          const long ip = cur_call_stack[pos]->ip;
          if(ip > -1) {
            StackInstr* instr = cur_call_stack[pos]->method->GetInstruction(ip);
            wcerr << L", file=" << method->GetClass()->GetFileName() << L":" << instr->GetLineNumber() << endl;
          }
          else {
            wcerr << endl;
          }
        }
        while(--pos);
      }
      else {
        wcout << L"program is not running." << endl;
      }
      break;

    default:
      break;
    }

    is_error = false;
    ref_mem = NULL;
    return command;
  }
  else {
    wcout << L"-- Unable to process command --" << endl;
  }

  is_error = false;
  ref_mem = NULL;
  return NULL;
}