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

implement debug info for global variables in the llvm backend #11097

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

implement debug info for global variables in the llvm backend #11097

andrewrk opened this issue Mar 9, 2022 · 0 comments · Fixed by #11147
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. 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 9, 2022

hello.zig

var blah: i32 = 1;

pub fn main() void {
    foo();
    blah = add(blah, 2);
}

fn foo() void {}

fn add(a: i32, b: i32) i32 {
    const result = a + b;
    return result;
}
gdb ./hello
(gdb) break hello.main
Breakpoint 1 at 0x2011b4: file hello.zig, line 4.
(gdb) run
Starting program: /home/andy/dev/zig/build-release/hello 

Breakpoint 1, hello.main () at hello.zig:4
4	    foo();
(gdb) info variables
All defined variables:

Non-debugging symbols:
...
0x0000000000202254  hello.blah
(gdb) p 'hello.blah'
'hello.blah' has unknown type; cast it to its declared type
(gdb) p (i32)'hello.blah'
$2 = 1

It looks like gdb is cleverly noticing symbols and treating them like typeless global variables. But to solve this issue we would expect to see the global variable in the "All defined variables" list, and it should have a type associated with it so that we do not have to manually cast it.

We would also expect to see some output from:

readelf --debug-dump=info ./hello | grep variable
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. frontend Tokenization, parsing, AstGen, Sema, and Liveness. backend-llvm The LLVM backend outputs an LLVM IR Module. labels Mar 9, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Mar 9, 2022
This was referenced Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. 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.

1 participant