╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ crash_report.zig ─────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
109 threadlocal var already_dumped = false; 110 /// TODO: make this unnecessary. It exists because `print_zir` currently needs an allocator, 111 /// but that shouldn't be necessary---it's already only used in one place. 112 threadlocal var crash_heap: [64 * 1024]u8 = undefined; 113 }; 114 if (S.already_dumped) return; 115 S.already_dumped = true; 116 117 std.Options.debug_io.vtable.crashHandler(std.Options.debug_io.userdata); 118 119 // TODO: this does mean that a different thread could grab the stderr mutex between the context 120 // and the actual panic printing, which would be quite confusing. 121 const stderr = std.debug.lockStderr(&.{}); 122 defer std.debug.unlockStderr(); 123 const w = &stderr.file_writer.interface; 124 125 try w.writeAll("Compiler crash context:\n"); 126 127 if (CodegenFunc.current) |*cg| { 128 const func_nav = cg.zcu.funcInfo(cg.func_index).owner_nav; 129 const func_fqn = cg.zcu.intern_pool.getNav(func_nav).fqn; 130 try w.print("Generating function '{f}'\n\n", .{func_fqn.fmt(&cg.zcu.intern_pool)}); 131 } else if (AnalyzeBody.current) |anal| { 132 try dumpCrashContextSema(anal, w, &S.crash_heap); 133 } else if (LinkerOp.current) |linker_op| { 134 try w.writeAll("Linker snapshot:\n"); 135 switch (try linker_op.lf.dump(w, linker_op.tid)) { 136 .unimplemented => try w.writeAll("(backend does not support link snapshots)"), 137 .needs_extensions => try w.writeAll("(build with -Ddebug-extensions to dump linker state)"), 138 .disabled => try w.writeAll("(run with --debug-link-snapshot to dump linker state)"), 139 .enabled => {}, 140 } 141 try w.writeAll("\n\n"); 142 } else { 143 try w.writeAll("(no context)\n\n"); 144 } 145 } 146 fn dumpCrashContextSema(anal: *AnalyzeBody, stderr: *Io.Writer, crash_heap: []u8) Io.Writer.Error!void { 147 const block: *Sema.Block = anal.block; 148 const zcu = anal.sema.pt.zcu; 149 const comp = zcu.comp; 150 151 var fba: std.heap.FixedBufferAllocator = .init(crash_heap); 152 153 const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu) orelse { 154 const file = zcu.fileByIndex(block.src_base_inst.resolveFile(&zcu.intern_pool)); 155 try stderr.print("Analyzing lost instruction in file '{f}'. This should not happen!\n\n", .{file.path.fmt(comp)}); 156 return; 157 }; 158 159 try stderr.print("Analyzing '{f}'\n", .{file.path.fmt(comp)}); 160 161 print_zir.renderInstructionContext( 162 fba.allocator(), 163 anal.body, 164 anal.body_index, 165 file, 166 src_base_node, 167 6, // indent 168 stderr, 169 ) catch |err| switch (err) { 170 error.OutOfMemory => try stderr.writeAll(" <out of memory dumping zir>\n"), 171 else => |e| return e, 172 }; 173 try stderr.print( 174 \\ For full context, use the command 175 \\ {s} ast-check -t {f} 176 \\ 177 \\ 178 , .{ zig_argv0, file.path.fmt(comp) }); 179 180 var parent = anal.parent; 181 while (parent) |curr| { 182 fba.reset(); 183 const cur_block_file = zcu.fileByIndex(curr.block.src_base_inst.resolveFile(&zcu.intern_pool)); 184 try stderr.print(" in {f}\n", .{cur_block_file.path.fmt(comp)}); 185 _, const cur_block_src_base_node = Zcu.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, zcu) orelse { 186 try stderr.writeAll(" > [lost instruction; this should not happen]\n"); 187 parent = curr.parent; 188 continue; 189 }; 190 try stderr.writeAll(" > "); 191 print_zir.renderSingleInstruction( 192 fba.allocator(), 193 curr.body[curr.body_index], 194 cur_block_file, 195 cur_block_src_base_node, 196 6, // indent 197 stderr, 198 ) catch |err| switch (err) { 199 error.OutOfMemory => try stderr.writeAll(" <out of memory dumping zir>\n"), 200 else => |e| return e, 201 }; 202 try stderr.writeAll("\n"); 203 204 parent = curr.parent; 205 } 206 207 try stderr.writeByte('\n'); 208 } 209 210 const std = @import("std"); 211 const Io = std.Io; 212 const Zir = std.zig.Zir; 213 214 const Sema = @import("Sema.zig"); 215 const Zcu = @import("Zcu.zig"); 216 const link = @import("link.zig"); 217 const InternPool = @import("InternPool.zig"); 218 const print_zir = @import("print_zir.zig"); 219 220 const build_options = @import("build_options"); 221