authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-12-02 20:08:06-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-12-02 20:08:06-05:00
log5c3b8cb3659172b539423972d996a66221c0e4a0
treed60be29bd87dc5088f119cdd9c4bda78dea8eb55
parenta436d2ab8c61f46d97a5c31ac083ef8fa54ed706
signaturelock-open Commit is signed but in an unrecognized format.

expose std.debug.DwarfInfo and delete unused function


1 files changed, 26 insertions(+), 48 deletions(-)

std/debug/index.zig+26-48
......@@ -950,30 +950,6 @@ fn openSelfDebugInfoLinux(allocator: *mem.Allocator) !DebugInfo {
950950 );
951951}
952952
953pub 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
977953fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo {
978954 const hdr = &std.c._mh_execute_header;
979955 assert(hdr.magic == std.macho.MH_MAGIC_64);
......@@ -1107,6 +1083,31 @@ const MachOFile = struct {
11071083pub const DwarfSeekableStream = io.SeekableStream(anyerror, anyerror);
11081084pub const DwarfInStream = io.InStream(anyerror);
11091085
1086pub 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
11101111pub const DebugInfo = switch (builtin.os) {
11111112 builtin.Os.macosx => struct {
11121113 symbols: []const MachoSymbol,
......@@ -1130,30 +1131,7 @@ pub const DebugInfo = switch (builtin.os) {
11301131 sect_contribs: []pdb.SectionContribEntry,
11311132 modules: []Module,
11321133 },
1133 builtin.Os.linux => struct {
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 },
1134 builtin.Os.linux => DwarfInfo,
11571135 builtin.Os.freebsd => struct {},
11581136 else => @compileError("Unsupported OS"),
11591137};