public static IEnumerable <InstructionData> GenerateInstructionData(ReverseSymbolTable symTable,
                                                                            TextSegmentAccessor textSegment,
                                                                            SourceDebugData dbgData)
        {
            IEnumerable <InstructionData> ret = null;

            if (File.Exists(dbgData.SourceFilePath))
            {
                try
                {
                    ret = GenerateInstructionDataWithSource(symTable, textSegment, dbgData);
                }
                catch (Exception)
                {
                    // if anything goes wrong, try just parsing the file with no source.
                    ret = GenerateInstructionDataWithNoSource(symTable, textSegment);
                }
            }
            else
            {
                ret = GenerateInstructionDataWithNoSource(symTable, textSegment);
            }

            return(ret);
        }
Пример #2
0
 public DisassembledJefFile(DataSegmentAccessor dataSegment, TextSegmentAccessor instructions,
                            IEnumerable <byte> externSegment, ReverseSymbolTable symTable,
                            IEnumerable <MetadataElement> metadata, SourceDebugData dbgData) :
     base(dataSegment, instructions, externSegment, symTable, dbgData)
 {
     m_FileWriter = new JefAssemblyFileWriter(this);
     m_Metadata   = metadata;
 }
Пример #3
0
 /// <summary>
 /// Creates an instance of the disassembled file.
 /// </summary>
 /// <param name="dataSegment">The disassembled .data segment of the file.</param>
 /// <param name="instructions">The disassembled .text segment of the file.</param>
 /// <param name="externSegment">The constituent bytes of the .extern segment.</param>
 /// <param name="symTable">The symbol table associated with the file.</param>
 /// <param name="dbgData">The source file information associated with the file.</param>
 protected DisassembledFileBase(DataSegmentAccessor dataSegment, TextSegmentAccessor instructions,
                                IEnumerable <byte> externSegment, ReverseSymbolTable symTable,
                                SourceDebugData dbgData)
 {
     m_DataSegment = dataSegment;
     m_TextSegment = instructions;
     m_ExternSize  = externSegment.Count();
     m_SymTbl      = symTable;
     m_DbgInfo     = dbgData;
 }
 public DisassembledElfFile(DataSegmentAccessor dataSegment, TextSegmentAccessor instructions,
                            IEnumerable <byte> externSegment, ReverseSymbolTable symTable) :
     base(dataSegment, instructions, externSegment, symTable, new SourceDebugData(string.Empty))
 {
     m_FileWriter = new ElfAssemblyFileWriter(this);
 }
        private static IEnumerable <InstructionData> GenerateInstructionDataWithNoSource(ReverseSymbolTable symTable,
                                                                                         TextSegmentAccessor textSegment)
        {
            var instructions = new List <InstructionData>();
            int currPgrmCtr  = textSegment.StartingSegmentAddress;

            foreach (DisassembledInstruction inst in textSegment.RawInstructions)
            {
                IParameterStringifier stringifier = InstructionTextMap.GetParameterStringifier(inst.InstructionType);
                string formattedInstruction       = stringifier.GetFormattedInstruction(currPgrmCtr, inst, symTable);
                var    srcLineInfo     = new SourceLineInformation(string.Empty, -1, currPgrmCtr);
                var    instructionElem = new InstructionData(inst.InstructionWord, currPgrmCtr, formattedInstruction, srcLineInfo);
                instructions.Add(instructionElem);
                currPgrmCtr += sizeof(int);
            }

            return(instructions);
        }
        private static IEnumerable <InstructionData> GenerateInstructionDataWithSource(ReverseSymbolTable symTable,
                                                                                       TextSegmentAccessor textSegment,
                                                                                       SourceDebugData dbgData)
        {
            var instructions = new List <InstructionData>();

            using (var reader = File.OpenText(dbgData.SourceFilePath))
            {
                int currPgrmCtr = textSegment.StartingSegmentAddress;
                foreach (DisassembledInstruction inst in textSegment.RawInstructions)
                {
                    IParameterStringifier stringifier = InstructionTextMap.GetParameterStringifier(inst.InstructionType);
                    string formattedInstruction       = stringifier.GetFormattedInstruction(currPgrmCtr, inst, symTable);
                    string originalSourceLine         = string.Empty;
                    int    lineNum = -1;
                    if (dbgData.IsSourceTextAssociatedWithAddress(currPgrmCtr))
                    {
                        lineNum            = dbgData.GetLineNumberAssociatedWithAddress(currPgrmCtr);
                        originalSourceLine = reader.ReadLineAt(lineNum);
                        originalSourceLine = originalSourceLine.Trim();
                    }
                    var srcLineInfo     = new SourceLineInformation(dbgData.SourceFilePath, lineNum, currPgrmCtr, originalSourceLine);
                    var instructionElem = new InstructionData(inst.InstructionWord, currPgrmCtr, formattedInstruction, srcLineInfo);
                    instructions.Add(instructionElem);
                    currPgrmCtr += sizeof(int);
                }

                return(instructions);
            }
        }