authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-04-18 13:11:37+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-04-18 13:11:37+02:00
log2193f7c4a2b56f67bf07d27c3f715cf3969c392f
tree94ccfd7887dc5ac6d5d213eb34c4f6553b2b9938
parentf8d2b87fa122a948e2c8e1056e2ec4cfd4cf01bf
signature Commit is signed but in an unrecognized format.

wasm: Add support for debug info

This implements basic DWARF output when building for the wasm target. Stacktraces, however, are currently not supported.

4 files changed, 10 insertions(+), 2 deletions(-)

lib/std/debug.zig+4
......@@ -114,6 +114,10 @@ pub fn detectTTYConfig() TTY.Config {
114114pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
115115 nosuspend {
116116 const stderr = io.getStdErr().writer();
117 if (comptime builtin.target.isWasm()) {
118 stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
119 return;
120 }
117121 if (builtin.strip_debug_info) {
118122 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
119123 return;
src/stage1/codegen.cpp+3
......@@ -2645,6 +2645,9 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, Stage1Air *executabl
26452645 Stage1AirInstSaveErrRetAddr *save_err_ret_addr_instruction)
26462646{
26472647 assert(g->have_err_ret_tracing);
2648 if ((target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) || target_is_bpf(g->zig_target)) {
2649 return nullptr;
2650 }
26482651
26492652 LLVMValueRef return_err_fn = get_return_err_fn(g);
26502653 bool is_llvm_alloca;
src/stage1/target.cpp+1-1
......@@ -1000,7 +1000,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
10001000}
10011001
10021002bool target_has_debug_info(const ZigTarget *target) {
1003 return !target_is_wasm(target);
1003 return true;
10041004}
10051005
10061006bool target_long_double_is_f128(const ZigTarget *target) {
src/target.zig+2-1
......@@ -455,7 +455,8 @@ pub fn classifyCompilerRtLibName(target: std.Target, name: []const u8) CompilerR
455455}
456456
457457pub fn hasDebugInfo(target: std.Target) bool {
458 return !target.cpu.arch.isWasm();
458 _ = target;
459 return true;
459460}
460461
461462pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.Mode {