Skip to content

stage1: incorrect and missing debug information for globals #10252

@leecannon

Description

@leecannon

Zig Version

0.9.0-dev.1827+1e0addcf7

Steps to Reproduce

Compile the below in debug mode

var this_one_isnt: u8 = 10;

const g = struct {
    pub const a_constant: u8 = 10;
};

pub fn main() void {
    var this_one_is: u8 = g.a_constant;
    this_one_is += 1;
    this_one_isnt += 1;
}

Then use llvm-dwarfdump to view the dwarf info.

Expected Behavior

Global variables being present in debug information and debuggers being able to inspect globals.

Actual Behavior

  • local variables are in the debug info and in the correct scope (see debug info for this_one_is below)
  • global variables are not in the debug info at all (see debug info for this_one_is below), marking the variable as pub or export does not affect the issue
  • global constants are in the debug info and correctly scoped (see debug info for this_one_is below) but not in the list of globals set in the DICompileUnit of the llvm IR (a trimmed copy of the verbose llvm ir is provided below showing the pertinant lines)

debug info for this_one_is

$ llvm-dwarfdump zig-out/bin/fff --all -p --name this_one_is
zig-out/bin/fff:	file format elf64-x86-64

0x0000000b: DW_TAG_compile_unit
              DW_AT_producer	("zig 0.9.0")
              DW_AT_language	(DW_LANG_C99)
              DW_AT_name	("fff")
              DW_AT_stmt_list	(0x00000000)
              DW_AT_comp_dir	("/home/lee/fff/src")
              DW_AT_GNU_pubnames	(true)
              DW_AT_low_pc	(0x0000000000000000)
              DW_AT_ranges	(0x000026b0
                 [0x0000000000204c10, 0x0000000000206f7e)
                 [0x0000000000206fd0, 0x000000000020c902)
                 [0x000000000020c9b0, 0x0000000000233b9d))

0x0000ea56:   DW_TAG_subprogram
                DW_AT_low_pc	(0x000000000022a550)
                DW_AT_high_pc	(0x000000000022a5be)
                DW_AT_frame_base	(DW_OP_reg6 RBP)
                DW_AT_name	("main")
                DW_AT_decl_file	("/home/lee/fff/src/main.zig")
                DW_AT_decl_line	(5)

0x0000ea6b:     DW_TAG_lexical_block
                  DW_AT_low_pc	(0x000000000022a558)
                  DW_AT_high_pc	(0x000000000022a5be)

0x0000ea78:       DW_TAG_variable
                    DW_AT_location	(DW_OP_fbreg -1)
                    DW_AT_name	("this_one_is")
                    DW_AT_decl_file	("/home/lee/fff/src/main.zig")
                    DW_AT_decl_line	(6)
                    DW_AT_type	(0x000004cc "u8")

debug info for this_one_isnt

$ llvm-dwarfdump zig-out/bin/fff --all -p --name this_one_isnt
zig-out/bin/fff:	file format elf64-x86-64

debug info for a_constant

$ llvm-dwarfdump zig-out/bin/fff --all -p --name a_constant
zig-out/bin/fff:	file format elf64-x86-64

0x0000000b: DW_TAG_compile_unit
              DW_AT_producer	("zig 0.9.0")
              DW_AT_language	(DW_LANG_C99)
              DW_AT_name	("fff")
              DW_AT_stmt_list	(0x00000000)
              DW_AT_comp_dir	("/home/lee/fff/src")
              DW_AT_GNU_pubnames	(true)
              DW_AT_low_pc	(0x0000000000000000)
              DW_AT_ranges	(0x000026b0
                 [0x0000000000204c30, 0x0000000000206f9e)
                 [0x0000000000206ff0, 0x000000000020c922)
                 [0x000000000020c9d0, 0x0000000000233bbd))

0x000036e1:   DW_TAG_structure_type
                DW_AT_name	("g")
                DW_AT_byte_size	(0x00)
                DW_AT_decl_file	("/home/lee/fff/src/main.zig")
                DW_AT_decl_line	(5)

0x000036e9:     DW_TAG_variable
                  DW_AT_name	("a_constant")
                  DW_AT_type	(0x000004cc "u8")
                  DW_AT_decl_file	("/home/lee/fff/src/main.zig")
                  DW_AT_decl_line	(6)
                  DW_AT_linkage_name	("a_constant")

trimmed llvm ir showing a_constant not in the list of globals

!2 = distinct !DICompileUnit( `standard debug mode stuff...` , globals: !1238)

// list of globals
!1238 = !{!1239, !1243, `...list continues but does not contain !2176` }

// global variable as well as its scope/file
!2176 = !DIGlobalVariableExpression(var: !2177, expr: !DIExpression())
!2177 = distinct !DIGlobalVariable(name: "a_constant", linkageName: "a_constant", scope: !2178, file: !2179, line: 6, type: !87, isLocal: true, isDefinition: true)
!2178 = !DICompositeType(tag: DW_TAG_structure_type, name: "g", scope: !2179, file: !2179, line: 5, elements: !1300)
!2179 = !DIFile(filename: "main.zig", directory: "/home/lee/fff/src")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions