Is some information missing from DWARF?

Hello,

I have been trying to play around with the DWARF info of the following program:

fn main() {
    let x = {1};
    let y = {3};
    let z = my_fun(x, y);
}

fn my_fun(arg1: usize, arg2: usize) -> usize{
    arg1 + arg2
}

I compile it with cargo build.

Then, after running, dwarfdump target/debug/debugee > debug_info.txt, I see the following:

< 1><0x0000046f>    DW_TAG_namespace
                      DW_AT_name                  debugee
< 2><0x00000474>      DW_TAG_subprogram
                        DW_AT_low_pc                0x00007710
                        DW_AT_high_pc               <offset-from-lowpc> 46 <highpc: 0x0000773e>
                        DW_AT_frame_base            len 0x0001: 0x57: 
                            DW_OP_reg7
                        DW_AT_linkage_name          _ZN7debugee4main17h431b3a7611d23d98E
                        DW_AT_name                  main
                        DW_AT_decl_file             0x00000008 /home/atticus/code/debugger/debugee/src/main.rs
                        DW_AT_decl_line             0x00000001
                        DW_AT_main_subprogram       yes(1)
< 3><0x0000048d>        DW_TAG_lexical_block
                          DW_AT_low_pc                0x00007714
                          DW_AT_high_pc               <offset-from-lowpc> 37 <highpc: 0x00007739>
< 4><0x0000049a>          DW_TAG_variable
                            DW_AT_location              len 0x0002: 0x9100: 
                                DW_OP_fbreg 0
                            DW_AT_name                  x
                            DW_AT_alignment             0x00000001
                            DW_AT_decl_file             0x00000008 /home/atticus/code/debugger/debugee/src/main.rs
                            DW_AT_decl_line             0x00000002
                            DW_AT_type                  <0x0000009f>
< 4><0x000004a9>          DW_TAG_lexical_block
                            DW_AT_low_pc                0x0000771c
                            DW_AT_high_pc               <offset-from-lowpc> 29 <highpc: 0x00007739>
< 5><0x000004b6>            DW_TAG_variable
                              DW_AT_location              len 0x0002: 0x9108: 
                                  DW_OP_fbreg 8
                              DW_AT_name                  y
                              DW_AT_alignment             0x00000001
                              DW_AT_decl_file             0x00000008 /home/atticus/code/debugger/debugee/src/main.rs
                              DW_AT_decl_line             0x00000003
                              DW_AT_type                  <0x0000009f>
< 2><0x000004c8>      DW_TAG_subprogram
                        DW_AT_low_pc                0x00007740
                        DW_AT_high_pc               <offset-from-lowpc> 67 <highpc: 0x00007783>
                        DW_AT_frame_base            len 0x0001: 0x57: 
                            DW_OP_reg7
                        DW_AT_linkage_name          _ZN7debugee6my_fun17h04dfe27b7095feedE
                        DW_AT_name                  my_fun
                        DW_AT_decl_file             0x00000008 /home/atticus/code/debugger/debugee/src/main.rs
                        DW_AT_decl_line             0x00000007
                        DW_AT_type                  <0x0000009f>
< 3><0x000004e5>        DW_TAG_formal_parameter
                          DW_AT_location              len 0x0002: 0x9108: 
                              DW_OP_fbreg 8
                          DW_AT_name                  arg1
                          DW_AT_decl_file             0x00000008 /home/atticus/code/debugger/debugee/src/main.rs
                          DW_AT_decl_line             0x00000007
                          DW_AT_type                  <0x0000009f>
< 3><0x000004f3>        DW_TAG_formal_parameter
                          DW_AT_location              len 0x0002: 0x9110: 
                              DW_OP_fbreg 16
                          DW_AT_name                  arg2
                          DW_AT_decl_file             0x00000008 /home/atticus/code/debugger/debugee/src/main.rs
                          DW_AT_decl_line             0x00000007
                          DW_AT_type                  <0x0000009f>

I am wondering why I am not seeing the z variable ? I thought about an optimization, but after checking the values passed to rustc in debug build, there should be none. And looking at LLVM IR with cargo rustc -- --emit=llvm-ir, I can see the all the expected variables:

; debugee::main
; Function Attrs: nonlazybind uwtable
define internal void @_ZN7debugee4main17h431b3a7611d23d98E() unnamed_addr #2 !dbg !181 {
start:
  %z.dbg.spill = alloca i64, align 8
  %y.dbg.spill = alloca i64, align 8
  %x.dbg.spill = alloca i64, align 8
  store i64 1, ptr %x.dbg.spill, align 8, !dbg !191
  call void @llvm.dbg.declare(metadata ptr %x.dbg.spill, metadata !185, metadata !DIExpression()), !dbg !191
  store i64 3, ptr %y.dbg.spill, align 8, !dbg !192
  call void @llvm.dbg.declare(metadata ptr %y.dbg.spill, metadata !187, metadata !DIExpression()), !dbg !192
; call debugee::my_fun
  %z = call i64 @_ZN7debugee6my_fun17h04dfe27b7095feedE(i64 1, i64 3), !dbg !193
  store i64 %z, ptr %z.dbg.spill, align 8, !dbg !193
  call void @llvm.dbg.declare(metadata ptr %z.dbg.spill, metadata !189, metadata !DIExpression()), !dbg !194
  ret void, !dbg !195
}

However, if I change my code to:

fn main() {
    let x = {1};
    let y = {3};
    let z = my_fun(x, y);
    let a = 0;
}

fn my_fun(arg1: usize, arg2: usize) -> usize{
    arg1 + arg2
}

I can see all four expected variables in the dwarfdump output.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.