| ... | @@ -950,30 +950,6 @@ fn openSelfDebugInfoLinux(allocator: *mem.Allocator) !DebugInfo { | ... | @@ -950,30 +950,6 @@ fn openSelfDebugInfoLinux(allocator: *mem.Allocator) !DebugInfo { |
| 950 | ); | 950 | ); |
| 951 | } | 951 | } |
| 952 | | 952 | |
| 953 | pub fn findElfSection(elf: *Elf, name: []const u8) ?*elf.Shdr { | | |
| 954 | var file_stream = elf.in_file.inStream(); | | |
| 955 | const in = &file_stream.stream; | | |
| 956 | | | |
| 957 | section_loop: for (elf.section_headers) |*elf_section| { | | |
| 958 | if (elf_section.sh_type == SHT_NULL) continue; | | |
| 959 | | | |
| 960 | const name_offset = elf.string_section.offset + elf_section.name; | | |
| 961 | try elf.in_file.seekTo(name_offset); | | |
| 962 | | | |
| 963 | for (name) |expected_c| { | | |
| 964 | const target_c = try in.readByte(); | | |
| 965 | if (target_c == 0 or expected_c != target_c) continue :section_loop; | | |
| 966 | } | | |
| 967 | | | |
| 968 | { | | |
| 969 | const null_byte = try in.readByte(); | | |
| 970 | if (null_byte == 0) return elf_section; | | |
| 971 | } | | |
| 972 | } | | |
| 973 | | | |
| 974 | return null; | | |
| 975 | } | | |
| 976 | | | |
| 977 | fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo { | 953 | fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo { |
| 978 | const hdr = &std.c._mh_execute_header; | 954 | const hdr = &std.c._mh_execute_header; |
| 979 | assert(hdr.magic == std.macho.MH_MAGIC_64); | 955 | assert(hdr.magic == std.macho.MH_MAGIC_64); |
| ... | @@ -1107,6 +1083,31 @@ const MachOFile = struct { | ... | @@ -1107,6 +1083,31 @@ const MachOFile = struct { |
| 1107 | pub const DwarfSeekableStream = io.SeekableStream(anyerror, anyerror); | 1083 | pub const DwarfSeekableStream = io.SeekableStream(anyerror, anyerror); |
| 1108 | pub const DwarfInStream = io.InStream(anyerror); | 1084 | pub const DwarfInStream = io.InStream(anyerror); |
| 1109 | | 1085 | |
| | 1086 | pub const DwarfInfo = struct { |
| | 1087 | dwarf_seekable_stream: *DwarfSeekableStream, |
| | 1088 | dwarf_in_stream: *DwarfInStream, |
| | 1089 | elf: elf.Elf, |
| | 1090 | debug_info: *elf.SectionHeader, |
| | 1091 | debug_abbrev: *elf.SectionHeader, |
| | 1092 | debug_str: *elf.SectionHeader, |
| | 1093 | debug_line: *elf.SectionHeader, |
| | 1094 | debug_ranges: ?*elf.SectionHeader, |
| | 1095 | abbrev_table_list: ArrayList(AbbrevTableHeader), |
| | 1096 | compile_unit_list: ArrayList(CompileUnit), |
| | 1097 | |
| | 1098 | pub fn allocator(self: DebugInfo) *mem.Allocator { |
| | 1099 | return self.abbrev_table_list.allocator; |
| | 1100 | } |
| | 1101 | |
| | 1102 | pub fn readString(self: *DebugInfo) ![]u8 { |
| | 1103 | return readStringRaw(self.allocator(), self.dwarf_in_stream); |
| | 1104 | } |
| | 1105 | |
| | 1106 | pub fn close(self: *DebugInfo) void { |
| | 1107 | self.elf.close(); |
| | 1108 | } |
| | 1109 | }; |
| | 1110 | |
| 1110 | pub const DebugInfo = switch (builtin.os) { | 1111 | pub const DebugInfo = switch (builtin.os) { |
| 1111 | builtin.Os.macosx => struct { | 1112 | builtin.Os.macosx => struct { |
| 1112 | symbols: []const MachoSymbol, | 1113 | symbols: []const MachoSymbol, |
| ... | @@ -1130,30 +1131,7 @@ pub const DebugInfo = switch (builtin.os) { | ... | @@ -1130,30 +1131,7 @@ pub const DebugInfo = switch (builtin.os) { |
| 1130 | sect_contribs: []pdb.SectionContribEntry, | 1131 | sect_contribs: []pdb.SectionContribEntry, |
| 1131 | modules: []Module, | 1132 | modules: []Module, |
| 1132 | }, | 1133 | }, |
| 1133 | builtin.Os.linux => struct { | 1134 | builtin.Os.linux => DwarfInfo, |
| 1134 | dwarf_seekable_stream: *DwarfSeekableStream, | | |
| 1135 | dwarf_in_stream: *DwarfInStream, | | |
| 1136 | elf: elf.Elf, | | |
| 1137 | debug_info: *elf.SectionHeader, | | |
| 1138 | debug_abbrev: *elf.SectionHeader, | | |
| 1139 | debug_str: *elf.SectionHeader, | | |
| 1140 | debug_line: *elf.SectionHeader, | | |
| 1141 | debug_ranges: ?*elf.SectionHeader, | | |
| 1142 | abbrev_table_list: ArrayList(AbbrevTableHeader), | | |
| 1143 | compile_unit_list: ArrayList(CompileUnit), | | |
| 1144 | | | |
| 1145 | pub fn allocator(self: DebugInfo) *mem.Allocator { | | |
| 1146 | return self.abbrev_table_list.allocator; | | |
| 1147 | } | | |
| 1148 | | | |
| 1149 | pub fn readString(self: *DebugInfo) ![]u8 { | | |
| 1150 | return readStringRaw(self.allocator(), self.dwarf_in_stream); | | |
| 1151 | } | | |
| 1152 | | | |
| 1153 | pub fn close(self: *DebugInfo) void { | | |
| 1154 | self.elf.close(); | | |
| 1155 | } | | |
| 1156 | }, | | |
| 1157 | builtin.Os.freebsd => struct {}, | 1135 | builtin.Os.freebsd => struct {}, |
| 1158 | else => @compileError("Unsupported OS"), | 1136 | else => @compileError("Unsupported OS"), |
| 1159 | }; | 1137 | }; |