diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-08-23 07:10:09 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-08-29 22:13:59 -0700 |
| commit | 6149f7318986214a34b09347f28ba48b2a614fef (patch) | |
| tree | 8b98adae2cf59dbf807c95d7a91102310a416ddf /std/debug.zig | |
| parent | ed50bd1b655ff028bdd650edecdcdd6675f1dee0 (diff) | |
| download | zig-6149f7318986214a34b09347f28ba48b2a614fef.tar.gz zig-6149f7318986214a34b09347f28ba48b2a614fef.zip | |
std: more progress toward stack printing
Diffstat (limited to 'std/debug.zig')
| -rw-r--r-- | std/debug.zig | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/std/debug.zig b/std/debug.zig index 2636799487..8781c87b25 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -2,6 +2,7 @@ const Allocator = @import("mem.zig").Allocator; const io = @import("io.zig"); const os = @import("os.zig"); const elf = @import("elf.zig"); +const DW = @import("dwarf.zig"); pub error MissingDebugInfo; pub error InvalidDebugInfo; @@ -27,6 +28,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream) -> %void { defer %return st.elf.close(); st.aranges = %return st.elf.findSection(".debug_aranges"); + st.debug_info = (%return st.elf.findSection(".debug_info")) ?? return error.MissingDebugInfo; var maybe_fp: ?&const u8 = @frameAddress(); while (true) { @@ -34,7 +36,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream) -> %void { const return_address = *(&const usize)(usize(fp) + @sizeOf(usize)); // read .debug_aranges to find out which compile unit the address is in - const debug_info_offset = %return debugInfoOffset(&st, return_address); + const compile_unit_offset = %return findCompileUnitOffset(&st, return_address); %return out_stream.printInt(usize, return_address); %return out_stream.printf(" -> "); @@ -59,11 +61,28 @@ struct ElfStackTrace { self_exe_stream: io.InStream, elf: elf.Elf, aranges: ?&elf.SectionHeader, + debug_info: &elf.SectionHeader, } -fn debugInfoOffset(st: &ElfStackTrace, target_address: usize) -> %u64 { - // when there is no .debug_aranges section, offset into debug info is 0x0 - const aranges = st.aranges ?? return 0; +fn findCompileUnitOffset(st: &ElfStackTrace, target_address: usize) -> %u64 { + if (const result ?= %return arangesOffset(st, target_address)) + return result; + + // iterate over compile units looking for a match with the low pc and high pc + %return st.elf.seekToSection(st.debug_info); + + while (true) { + const tag_id = %return st.self_exe_stream.readByte(); + if (tag_id == DW.TAG_compile_unit) { + + } else { + + } + } +} + +fn arangesOffset(st: &ElfStackTrace, target_address: usize) -> %?u64 { + const aranges = ?return st.aranges; %return st.elf.seekToSection(aranges); |
