Ejemplo n.º 1
0
        public static void WriteDwarf2(this BinaryWriter writer, DebugLineHeader header)
        {
            writer.Write(header.UnitLength);
            writer.Write(header.Version);
            writer.Write(header.HeaderLength);
            writer.Write(header.MinimumInstructionLength);
            writer.Write(header.DefaultIsStatement);
            writer.Write(header.LineBase);
            writer.Write(header.LineRange);
            writer.Write(header.OpcodeBase);
            if (header.OpcodeBase > 0) {
                if (header.OpcodesArgsCount == null || header.OpcodesArgsCount.Length != header.OpcodeBase - 1) {
                    throw new Exception("Invalid or missing opcode args count");
                }
                foreach (int argsCount in header.OpcodesArgsCount) {
                    writer.Write(argsCount);
                }
            }
            if (header.IncludeDirectories != null) {
                foreach (var dir in header.IncludeDirectories) {
                    writer.WriteDwarfStringZ(dir);
                }
            }
            writer.Write((byte)0);

            if (header.FileNames != null) {
                foreach (var file in header.FileNames) {
                    writer.WriteDwarfStringZ(file.Name);
                    writer.WriteDwarfLeb128(file.DirectoryIndex);
                    writer.WriteDwarfLeb128(file.Time);
                    writer.WriteDwarfLeb128(file.Size);
                }
            }
            writer.Write((byte)0);
        }
Ejemplo n.º 2
0
 private void AddDebugLine(ElfFile file, AsmContext context)
 {
     var mem = new MemoryStream();
     var writer = new BinaryWriter(mem);
     var hdr = new DebugLineHeader {
         FileNames = new[]
         {
             new DebugLineFile {Name = "test.asm"},
             new DebugLineFile {Name = "test2.asm"},
         }
     };
     writer.WriteDwarf2(hdr);
     if (mem.Length > 0) {
         file.Sections.Add(new ElfSection {
             Name = file.Strings.SaveString(".debug_line"),
             Type = ElfSectionType.ProgBits,
             Address = 0,
             Flags = ElfSectionFlags.None,
             Size = (uint)mem.Length,
             Align = 1,
             Offset = (uint)file.Data.Position
         });
         file.Data.Write(mem.ToArray(), 0, (int)mem.Length);
     }
 }