public void TestDebugInfoSmall() { var cppName = "small"; var cppObj = $"{cppName}_debug.o"; LinuxUtil.RunLinuxExe("gcc", $"{cppName}.cpp -g -c -o {cppObj}"); ElfObjectFile elf; using (var inStream = File.OpenRead(cppObj)) { elf = ElfObjectFile.Read(inStream); elf.Print(Console.Out); } var elfContext = new DwarfElfContext(elf); var inputContext = new DwarfReaderContext(elfContext); var dwarf = DwarfFile.Read(inputContext); dwarf.AbbreviationTable.Print(Console.Out); dwarf.InfoSection.Print(Console.Out); dwarf.AddressRangeTable.Print(Console.Out); PrintStreamLength(inputContext); Console.WriteLine(); Console.WriteLine("===================================================================="); Console.WriteLine("Write Back"); Console.WriteLine("===================================================================="); var outputContext = new DwarfWriterContext { IsLittleEndian = inputContext.IsLittleEndian, AddressSize = inputContext.AddressSize, DebugAbbrevStream = new MemoryStream(), DebugLineStream = new MemoryStream(), DebugInfoStream = new MemoryStream(), DebugStringStream = new MemoryStream(), DebugAddressRangeStream = new MemoryStream() }; dwarf.Write(outputContext); dwarf.AbbreviationTable.Print(Console.Out); dwarf.InfoSection.Print(Console.Out); dwarf.InfoSection.PrintRelocations(Console.Out); dwarf.AddressRangeTable.Print(Console.Out); dwarf.AddressRangeTable.PrintRelocations(Console.Out); dwarf.WriteToElf(elfContext); var cppObj2 = $"{cppName}_debug2.o"; using (var outStream = new FileStream(cppObj2, FileMode.Create)) { elf.Write(outStream); } PrintStreamLength(outputContext); }
public void TestDebugLineSmall() { var cppName = "small"; var cppObj = $"{cppName}_debug.o"; LinuxUtil.RunLinuxExe("gcc", $"{cppName}.cpp -g -c -o {cppObj}"); ElfObjectFile elf; using (var inStream = File.OpenRead(cppObj)) { Console.WriteLine($"ReadBack from {cppObj}"); elf = ElfObjectFile.Read(inStream); elf.Print(Console.Out); } var elfContext = new DwarfElfContext(elf); var inputContext = new DwarfReaderContext(elfContext); inputContext.DebugLinePrinter = Console.Out; var dwarf = DwarfFile.Read(inputContext); inputContext.DebugLineStream.Position = 0; var copyInputDebugLineStream = new MemoryStream(); inputContext.DebugLineStream.CopyTo(copyInputDebugLineStream); inputContext.DebugLineStream.Position = 0; var outputContext = new DwarfWriterContext { IsLittleEndian = inputContext.IsLittleEndian, AddressSize = inputContext.AddressSize, DebugLineStream = new MemoryStream() }; dwarf.Write(outputContext); Console.WriteLine(); Console.WriteLine("====================================================="); Console.WriteLine("Readback"); Console.WriteLine("====================================================="); Console.WriteLine(); var reloadContext = new DwarfReaderContext() { IsLittleEndian = outputContext.IsLittleEndian, AddressSize = outputContext.AddressSize, DebugLineStream = outputContext.DebugLineStream }; reloadContext.DebugLineStream.Position = 0; reloadContext.DebugLineStream = outputContext.DebugLineStream; reloadContext.DebugLinePrinter = Console.Out; var dwarf2 = DwarfFile.Read(reloadContext); var inputDebugLineBuffer = copyInputDebugLineStream.ToArray(); var outputDebugLineBuffer = ((MemoryStream)reloadContext.DebugLineStream).ToArray(); Assert.AreEqual(inputDebugLineBuffer, outputDebugLineBuffer); }