-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
std: avoid pre-parsing dwarf info #3005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
0299bf8
to
9fb0149
Compare
I tried this out with the assertion from #2957 and it hung in findCompileUnit, endless loop in |
@andrewrk I'll have a look tonight. Any other notes/comments on the changes in this PR? |
219978a
to
c10eec5
Compare
Apologies for all the force pushes... I keep spying more memory leaks in std/debug.zig. Evidently the previous version of the code only expected to be run when everything was about to exit. |
Yes that's exactly true - the original version of this code had this assumption. It also has the assumption that it will only be called once. Fixing the leaks and this other assumption will require a full audit. |
I tried this again with the same test case. Master branch takes 5.244s and this branch takes 6.431s. Also master branch produces this trace, and this branch only produces one frame:
vs
|
std/debug.zig
Outdated
const line_info_offset = try compile_unit.die.getAttrSecOffset(DW.AT_stmt_list); | ||
fn getLineNumberInfoDwarf(di: *DwarfInfo, compile_unit_die: Die, target_address: usize) !LineInfo { | ||
const compile_unit_cwd = try compile_unit_die.getAttrString(di, di.allocator, DW.AT_comp_dir); | ||
defer di.allocator.free(compile_unit_cwd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: this defer
may be the cause of andrew's issue: I noticed the path in his short traceback is missing a leading /
. Perhaps it got freed and set to 0xaa
by compile_unit_cwd
getting collected.
std/debug.zig
Outdated
@@ -1439,6 +1468,11 @@ const LineNumberProgram = struct { | |||
}; | |||
} | |||
|
|||
pub fn deinit(self: *LineNumberProgram) void { | |||
self.include_dirs.deinit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: free .include_dirs
members?
What do you get with the test case of the following?: const std = @import("std");
pub fn main() void {
std.debug.dumpCurrentStackTrace(@returnAddress());
} With the test case from #2957 I get a fast full traceback in 1.32s (but no symbols... as my llvm library has been stripped). compared to 11 seconds with master (also no symbols due to stripping). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my test now:
master: 0m7.338s
when analyzing /home/andy/Downloads/zig/build/test.zig:4:9: assertion failed. This is a bug in the Zig compiler.
/home/andy/Downloads/zig/src-self-hosted/stage1.zig:37:5: 0xfe2ccc in stage2_panic (userland)
@panic(ptr[0..len]);
^
/home/andy/Downloads/zig/src/analyze.cpp:8898:0: 0xfc3367 in src_assert (/home/andy/Downloads/zig/src/analyze.cpp)
stage2_panic(msg, strlen(msg));
/home/andy/Downloads/zig/src/ir.cpp:8363:0: 0xf267fb in ir_gen_node_extra (/home/andy/Downloads/zig/src/ir.cpp)
src_assert(irb->exec->first_err_trace_msg != nullptr, node);
/home/andy/Downloads/zig/src/ir.cpp:3948:0: 0xf12d8e in ir_gen_assign (/home/andy/Downloads/zig/src/ir.cpp)
&result_loc_inst->base);
/home/andy/Downloads/zig/src/ir.cpp:4180:0: 0xf13d14 in ir_gen_bin_op (/home/andy/Downloads/zig/src/ir.cpp)
return ir_lval_wrap(irb, scope, ir_gen_assign(irb, scope, node), lval, result_loc);
/home/andy/Downloads/zig/src/ir.cpp:8211:0: 0xf25cd1 in ir_gen_node_raw (/home/andy/Downloads/zig/src/ir.cpp)
return ir_gen_bin_op(irb, scope, node, lval, result_loc);
/home/andy/Downloads/zig/src/ir.cpp:8358:0: 0xf2678f in ir_gen_node_extra (/home/andy/Downloads/zig/src/ir.cpp)
IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
/home/andy/Downloads/zig/src/ir.cpp:8369:0: 0xf26834 in ir_gen_node (/home/andy/Downloads/zig/src/ir.cpp)
return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
/home/andy/Downloads/zig/src/ir.cpp:3828:0: 0xf125c0 in ir_gen_block (/home/andy/Downloads/zig/src/ir.cpp)
IrInstruction *statement_value = ir_gen_node(irb, statement_node, child_scope);
/home/andy/Downloads/zig/src/ir.cpp:8207:0: 0xf25c87 in ir_gen_node_raw (/home/andy/Downloads/zig/src/ir.cpp)
return ir_gen_block(irb, scope, node, lval, result_loc);
/home/andy/Downloads/zig/src/ir.cpp:8358:0: 0xf2678f in ir_gen_node_extra (/home/andy/Downloads/zig/src/ir.cpp)
IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
/home/andy/Downloads/zig/src/ir.cpp:8401:0: 0xf269b6 in ir_gen (/home/andy/Downloads/zig/src/ir.cpp)
IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
/home/andy/Downloads/zig/src/ir.cpp:8425:0: 0xf26b01 in ir_gen_fn (/home/andy/Downloads/zig/src/ir.cpp)
return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);
/home/andy/Downloads/zig/src/analyze.cpp:4593:0: 0xfb49ab in analyze_fn_body (/home/andy/Downloads/zig/src/analyze.cpp)
ir_gen_fn(g, fn_table_entry);
/home/andy/Downloads/zig/src/analyze.cpp:4738:0: 0xfb5392 in semantic_analyze (/home/andy/Downloads/zig/src/analyze.cpp)
analyze_fn_body(g, fn_entry);
/home/andy/Downloads/zig/src/codegen.cpp:9123:0: 0xef5dc7 in gen_root_source (/home/andy/Downloads/zig/src/codegen.cpp)
semantic_analyze(g);
/home/andy/Downloads/zig/src/codegen.cpp:10095:0: 0xef9766 in codegen_build_and_link (/home/andy/Downloads/zig/src/codegen.cpp)
gen_root_source(g);
/home/andy/Downloads/zig/src/main.cpp:1343:0: 0xecf976 in main (/home/andy/Downloads/zig/src/main.cpp)
codegen_build_and_link(g);
???:?:?: 0x7ff9970a1b8d in ??? (???)
???:?:?: 0x6c66258d4c544154 in ??? (???)
Segmentation fault (core dumped)
this PR: 0m26.467s
when analyzing /home/andy/Downloads/zig/build/test.zig:4:9: assertion failed. This is a bug in the Zig compiler.
/home/andy/Downloads/zig/src-self-hosted/stage1.zig:37:5: 0xfe2ccc in stage2_panic (userland)
@panic(ptr[0..len]);
^
home/andy/Downloads/zig/src/analyze.cpp:8898:0: 0xfc3367 in src_assert (/home/andy/Downloads/zig/src/analyze.cpp)
home/andy/Downloads/zig/src/ir.cpp:8363:0: 0xf267fb in ir_gen_node_extra (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:3948:0: 0xf12d8e in ir_gen_assign (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:4180:0: 0xf13d14 in ir_gen_bin_op (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:8211:0: 0xf25cd1 in ir_gen_node_raw (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:8358:0: 0xf2678f in ir_gen_node_extra (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:8369:0: 0xf26834 in ir_gen_node (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:3828:0: 0xf125c0 in ir_gen_block (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:8207:0: 0xf25c87 in ir_gen_node_raw (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:8358:0: 0xf2678f in ir_gen_node_extra (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:8401:0: 0xf269b6 in ir_gen (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/ir.cpp:8425:0: 0xf26b01 in ir_gen_fn (/home/andy/Downloads/zig/src/ir.cpp)
home/andy/Downloads/zig/src/analyze.cpp:4593:0: 0xfb49ab in analyze_fn_body (/home/andy/Downloads/zig/src/analyze.cpp)
home/andy/Downloads/zig/src/analyze.cpp:4738:0: 0xfb5392 in semantic_analyze (/home/andy/Downloads/zig/src/analyze.cpp)
home/andy/Downloads/zig/src/codegen.cpp:9123:0: 0xef5dc7 in gen_root_source (/home/andy/Downloads/zig/src/codegen.cpp)
home/andy/Downloads/zig/src/codegen.cpp:10095:0: 0xef9766 in codegen_build_and_link (/home/andy/Downloads/zig/src/codegen.cpp)
home/andy/Downloads/zig/src/main.cpp:1343:0: 0xecf976 in main (/home/andy/Downloads/zig/src/main.cpp)
???:?:?: 0x7f9d00a33b8d in ??? (???)
???:?:?: 0x5f16258d4c544154 in ??? (???)
Segmentation fault (core dumped)
It's much slower and missing most of the useful content. Maybe I merged the conflicts incorrectly, let me know if I did.
I'll be happy to look at this again after you've demonstrated that you've tested on enough different cases to have confidence that it performs better, and doesn't cause any regressions.
c10eec5
to
0dbe3d4
Compare
I grabbed the sample you linked and put it into With current master (3aeb1b1):
With this PR:
Now that wasn't useful I guess.... I'm not sure why neither traceback has symbols. What did you compile/run to get them? Are you using the self-hosted compiler? How? |
0dbe3d4
to
6ce630b
Compare
I'm not convinced this is an improvement. All 3 times I tested this, it was worse than status quo. If you do another pass at this, I want to see a more detailed analysis of why the code is better than status quo. |
Fixes #2458
This pull request refactors debug.zig to not scan dwarf info. Instead the seekable stream is used directly to pull out info.