public RuntimeProcess(DisassembledFileBase file, ITerminal terminal) { // intialize this so that we're signaled. this will allow the run task // to be initialized to not wait until the user actually commands us to pause m_RunTimer = new Stopwatch(); m_ProcCtrl = new ChildProcControl(); m_InstructionAddrToBreakpointMap = new Dictionary <int, bool>(); m_ExecutionState = PrgmExecutionState.Stopped; m_Terminal = terminal; m_RegMgr = new RegisterManager(file.TextSegment.StartingSegmentAddress, CommonConstants.DEFAULT_STACK_ADDRESS); m_DataSegment = new RuntimeDataSegmentAccessor(file.DataSegment); m_Ctx = new Interpreter.ExecutionContext(this, terminal, m_DataSegment, m_RegMgr, file.TextSegment); // initialize the instruction breakpoint map. // this will give us a positive performance boost when we execute the program // since we will not be creating new boolean entries in the hash table. int endingTxtSegmentAddr = file.TextSegment.StartingSegmentAddress + file.TextSegment.SegmentSize; for (int instructionAddr = file.TextSegment.StartingSegmentAddress; instructionAddr < endingTxtSegmentAddr; instructionAddr += sizeof(int)) { m_InstructionAddrToBreakpointMap.Add(instructionAddr, false); } }
/// <summary> /// Task for disassembling one individual file. /// </summary> /// <param name="logger">The logging implementation to log errors/info to.</param> /// <param name="options">The options to use while disassembling.</param> /// <returns>True if the disassembler could successfully disassemble the file; otherwise returns false.</returns> public bool DisassembleFile(ILogger logger, DisassemblerOptions options) { bool success = true; logger.Log(LogLevel.Info, "Invoking disassembler for file " + options.InputFileName); try { ICompiledFileReader fileParser = m_FileParserFac.GetFileParser(options.InputFileName); DisassembledFileBase fileBase = fileParser.ParseFile(options.InputFileName, logger); IAssemblyFileWriter fileWriter = fileBase.AssemblyTextFileWriter; fileWriter.GenerateOutputFile(options.OutputFileName); } catch (IOException ex) { logger.Log(LogLevel.Critical, ex.Message); success = false; } catch (Exception ex) { logger.Log(LogLevel.Critical, "In file " + options.InputFileName + ":"); logger.Log(LogLevel.Critical, ex.Message); success = false; } return(success); }
private string DisassembleToTemporaryFile(string inputFileName, ILogger logger) { string outputFileName = Path.GetTempFileName(); logger.Log(LogLevel.Info, "Invoking disassembler for file " + inputFileName); try { ICompiledFileReader fileParser = m_FileParserFac.GetFileParser(inputFileName); DisassembledFileBase fileBase = fileParser.ParseFile(inputFileName, logger); IAssemblyFileWriter fileWriter = fileBase.AssemblyTextFileWriter; fileWriter.GenerateOutputFile(outputFileName); } catch (IOException ex) { logger.Log(LogLevel.Critical, ex.Message); throw; } catch (Exception ex) { logger.Log(LogLevel.Critical, "In file " + inputFileName + ":"); logger.Log(LogLevel.Critical, ex.Message); throw; } return(outputFileName); }
public ConsoleSimulation(string inputFileName, CommandInterpreter interpreter) { m_Terminal = new ConsoleEmulator(interpreter); m_Logger = new ConsoleLogger(); m_TerminationMgr = new TerminationManager(inputFileName); var fileParserFac = new FileReaderFactory(); ICompiledFileReader fileParser = fileParserFac.GetFileParser(inputFileName); DisassembledFileBase file = fileParser.ParseFile(inputFileName, m_Logger); m_Terminal.PrintString("Successfully loaded " + inputFileName + " (source file: " + file.SourceInformation.SourceFilePath + "; " + file.TotalFileSize + " bytes)\n"); m_ExecCtx = new RuntimeProcess(file, m_Terminal); IEnumerable <InstructionData> programInstructions = DisassemblerServices.GenerateInstructionData(file.SymbolTable, file.TextSegment, file.SourceInformation); m_SrcMapping = new Dictionary <int, SourceLineInformation>(); foreach (InstructionData instructionElem in programInstructions) { m_SrcMapping.Add(instructionElem.ProgramCounterLocation, new SourceLineInformation(instructionElem)); } m_CmdTable = new CommandTable(m_SrcMapping, m_ExecCtx, m_Terminal, m_TerminationMgr); m_Terminal.AddAvailableCommands(m_CmdTable.AllCommands); }
public DisassembledFileViewModel(string fileName, DisassembledFileBase runtimeFile) { m_UnderlyingFile = runtimeFile; m_Instructions = new BindingList <ProgramInstructionViewModel>(); m_FilePath = fileName; IEnumerable <InstructionData> programInstructions = DisassemblerServices.GenerateInstructionData(runtimeFile.SymbolTable, runtimeFile.TextSegment, runtimeFile.SourceInformation); foreach (InstructionData instructionElem in programInstructions) { m_Instructions.Add(new ProgramInstructionViewModel(instructionElem)); } }
private void LoadFile(string fileName) { // see if we already have this file open. if so, just refresh it // by removing the existing version and adding a new one to the model. int fileIdx = m_FilesToExecute.IndexOf((vm) => vm.FilePath == fileName); if (fileIdx >= 0) { m_FilesToExecute.RemoveAt(fileIdx); } var fileReader = m_FileProc.GetFileParser(fileName); DisassembledFileBase file = fileReader.ParseFile(fileName, m_LoggerVm.Logger); m_FilesToExecute.Add(new DisassembledFileViewModel(fileName, file)); ActiveTabIdx = (m_FilesToExecute.Count - 1); }
public ElfAssemblyFileWriter(DisassembledFileBase underlyingFile) { m_UnderlyingFile = underlyingFile; }
public ExecutionViewModel(ITerminal terminal, DisassembledFileViewModel underlyingVm, IList<ProgramInstructionViewModel> instructionVm) { // intialize this so that we're signaled. this will allow the run task // to be initialized to not wait until the user actually commands us to pause m_PauseCtrl = new PauseController(); m_InstructionAddrToBreakpointMap = new Dictionary<int, bool>(); m_ExecutionState = PrgmExecutionState.Stopped; m_Terminal = terminal; var registers = new RegisterViewModel[InterpreterCommon.MAX_BASIC_REGISTERS]; for (int i = 0; i < InterpreterCommon.MAX_BASIC_REGISTERS; ++i) { if (i == 0) { registers[i] = new ZeroRegisterViewModel(); } else { registers[i] = new RegisterViewModel(i); } } DisassembledFileBase file = underlyingVm.FileData; var dataSegmentAccessor = new BindableDataSegmentAccessor(file.DataSegment); var fltPtRegs = new FloatingPointRegisterViewModel[InterpreterCommon.MAX_FLOATING_PT_REGISTERS]; for (int i = 0; i < fltPtRegs.Length; ++i) { fltPtRegs[i] = new FloatingPointRegisterViewModel(i); } m_RegMgr = new RegisterManager(registers, fltPtRegs, file.TextSegment.StartingSegmentAddress, CommonConstants.DEFAULT_STACK_ADDRESS); m_Ctx = new Interpreter.ExecutionContext(this, terminal, dataSegmentAccessor, m_RegMgr, file.TextSegment); m_DataSegmentElements = new BindingList<DataAddressViewModel>(); // increment this by 16. Each row will display four words. for (int currElem = file.DataSegment.BaseRuntimeDataAddress; currElem < file.DataSegment.BaseRuntimeDataAddress + file.DataSegmentLength; currElem += 16) { m_DataSegmentElements.Add(new DataAddressViewModel(currElem, dataSegmentAccessor)); } m_ExecuteFileCmd = new RelayCommand(() => OnExecutionTaskBegin(), true); m_TerminateExecutionCmd = new RelayCommand(() => CancelExecution(), false); m_SwitchRepresentationCmd = new RelayCommand<RegisterDisplayType>((param) => SwitchRegisterDisplayType(param), true); m_SwitchDataRepresentationCmd = new RelayCommand<RegisterDisplayType>((param) => SwitchDataDisplayType(param), true); m_PauseExecutionCmd = new RelayCommand(() => PauseExecution(), false); m_ResumeExecutionCmd = new RelayCommand(() => ResumeExecution(), false); m_InstructionStepCmd = new RelayCommand(() => TemporarilyUnblockExecutionTask(), false); m_SetBreakpointCmd = new RelayCommand<int>(param => SetProgramBreakpoint(param), true); m_UnsetBreakpointCmd = new RelayCommand<int>(param => UnsetProgramBreakpoint(param), true); // initialize the instruction breakpoint map. // this will give us a positive performance boost when we execute the program // since we will not be creating new boolean entries in the hash table. foreach (var instruction in instructionVm) { m_InstructionAddrToBreakpointMap.Add(instruction.ProgramCounterLocation, false); instruction.PropertyChanged += OnFileViewModelPropertyChanged; } }