Skip to content
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

make function calls contain debug stmt line/column info #11158

Closed
Tracked by #89
andrewrk opened this issue Mar 14, 2022 · 0 comments · Fixed by #11177
Closed
Tracked by #89

make function calls contain debug stmt line/column info #11158

andrewrk opened this issue Mar 14, 2022 · 0 comments · Fixed by #11177
Assignees
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Mar 14, 2022

Zig version: 0.10.0-dev.1311+5ea94e771

const std = @import("std");

pub fn main() void {
    var x: i32 = 1234;
    x += foo() +
        bar();
}

fn foo() i32 {
    return 1;
}

fn bar() i32 {
    @panic("crash");
}

Here you can see in a debugging session, the traceback points back to the wrong function call:

$ ./stage2/bin/zig build-exe test3.zig -fLLVM
$ gdb ./test3 -ex run
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00000000002019e7 in builtin.default_panic (msg=..., error_return_trace=<optimized out>) at /home/andy/dev/zig/lib/std/builtin.zig:758
758	            @breakpoint();
(gdb) up
#1  0x0000000000202127 in test3.bar () at test3.zig:14
14	    @panic("crash");
(gdb) 
#2  0x0000000000201b42 in test3.main () at test3.zig:5
5	    x += foo() +
(gdb) 

This is because in the ZIR we only emit dbg_stmt for the var decl, not each function call:

      %11 = dbg_stmt(3, 5)
      %12 = load(%7) node_offset:5:7
      %13 = typeof(%12) node_offset:5:7
      %14 = decl_val("foo") token_offset:5:10
      %15 = call(.auto, %14, []) node_offset:5:13
      %16 = decl_val("bar") token_offset:6:9
      %17 = call(.auto, %16, []) node_offset:6:12
      %18 = add(%15, %17) node_offset:5:16
      %19 = add(%12, %18) node_offset:5:7
      %20 = store(%7, %19)
      %21 = ret_tok(@Ref.void_value) token_offset:7:1

The two call instructions do have a source node, but only the index is communicated; not line/column info for use by debug info.

We need to augment the call ZIR instruction with the same information as provided by dbg_stmt and then treat each function call as an implicit dbg_stmt instruction.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Mar 14, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Mar 14, 2022
@Vexu Vexu self-assigned this Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants