Commit ac4d633ed6
Changed files (3)
lib
std
lib/std/debug/Coverage.zig
@@ -145,6 +145,7 @@ pub const ResolveAddressesDwarfError = Dwarf.ScanError;
pub fn resolveAddressesDwarf(
cov: *Coverage,
gpa: Allocator,
+ endian: std.builtin.Endian,
/// Asserts the addresses are in ascending order.
sorted_pc_addrs: []const u64,
/// Asserts its length equals length of `sorted_pc_addrs`.
@@ -184,7 +185,7 @@ pub fn resolveAddressesDwarf(
if (cu.src_loc_cache == null) {
cov.mutex.unlock();
defer cov.mutex.lock();
- d.populateSrcLocCache(gpa, cu) catch |err| switch (err) {
+ d.populateSrcLocCache(gpa, endian, cu) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => {
out.* = SourceLocation.invalid;
continue :next_pc;
lib/std/debug/Dwarf.zig
@@ -652,7 +652,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator, endian: Endian) ScanErr
}
}
-pub fn populateRanges(d: *Dwarf, gpa: Allocator) ScanError!void {
+pub fn populateRanges(d: *Dwarf, gpa: Allocator, endian: Endian) ScanError!void {
assert(d.ranges.items.len == 0);
for (d.compile_unit_list.items, 0..) |*cu, cu_index| {
@@ -665,7 +665,7 @@ pub fn populateRanges(d: *Dwarf, gpa: Allocator) ScanError!void {
continue;
}
const ranges_value = cu.die.getAttr(AT.ranges) orelse continue;
- var iter = DebugRangeIterator.init(ranges_value, d, cu) catch continue;
+ var iter = DebugRangeIterator.init(ranges_value, d, endian, cu) catch continue;
while (try iter.next()) |range| {
// Not sure why LLVM thinks it's OK to emit these...
if (range.start == range.end) continue;
lib/std/debug/Info.zig
@@ -24,14 +24,15 @@ coverage: *Coverage,
pub const LoadError = Dwarf.ElfModule.LoadError;
pub fn load(gpa: Allocator, path: Path, coverage: *Coverage) LoadError!Info {
- var sections: Dwarf.SectionArray = Dwarf.null_section_array;
- var elf_module = try Dwarf.ElfModule.load(gpa, path, null, null, §ions, null);
- try elf_module.dwarf.populateRanges(gpa);
+ var elf_module = try Dwarf.ElfModule.load(gpa, path, null, null, null, null);
+ // This is correct because `Dwarf.ElfModule` currently only supports native-endian ELF files.
+ const endian = @import("builtin").target.cpu.arch.endian();
+ try elf_module.dwarf.populateRanges(gpa, endian);
var info: Info = .{
.address_map = .{},
.coverage = coverage,
};
- try info.address_map.put(gpa, elf_module.base_address, elf_module);
+ try info.address_map.put(gpa, 0, elf_module);
return info;
}
@@ -58,5 +59,7 @@ pub fn resolveAddresses(
assert(sorted_pc_addrs.len == output.len);
if (info.address_map.entries.len != 1) @panic("TODO");
const elf_module = &info.address_map.values()[0];
- return info.coverage.resolveAddressesDwarf(gpa, sorted_pc_addrs, output, &elf_module.dwarf);
+ // This is correct because `Dwarf.ElfModule` currently only supports native-endian ELF files.
+ const endian = @import("builtin").target.cpu.arch.endian();
+ return info.coverage.resolveAddressesDwarf(gpa, endian, sorted_pc_addrs, output, &elf_module.dwarf);
}