Skip to content

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

@andrewrk

Description

@andrewrk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions