DWARF not being generated for local variable, though MD looks right(?)

I'm running into a problem with generating debugging information that I'm not sure how to debug; I'd be happy to have some suggestions about where to start digging in.

In short, I believe that I'm correctly generating debug info (with DIBuilder, which has so far been quite nice!), and a scan of the meta-data in the IR looks generally right. However, if I run dwarfdump on my object file, I'm not seeing any DIE information for the local variables. I'm wondering what might be going wrong along the way.

More specifically, given a program that is equivalent to the following in C:

float foo() {
  float y = 1234;
  return y;
}

My compiler generates the following IR (pay no attention to the ___ at the end of "foo"..):

define i32 @foo___(<4 x i32>) nounwind readnone alwaysinline {
entry:
  tail call void @llvm.dbg.value(metadata !6, i64 0, metadata !4), !dbg !7
  ret i32 1234
}

declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone

!llvm.dbg.sp = !{!0}
!llvm.dbg.lv.foo___ = !{!4}

!0 = metadata !{i32 589870, i32 0, metadata !1, metadata !"foo", metadata !"foo", metadata !"foo___", metadata !1, i32 4, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 0, i1 true, i32 (<4 x i32>)* @foo___, null, null} ; [ DW_TAG_subprogram ]
!1 = metadata !{i32 589865, metadata !"a.c", metadata !"/Users/mmp/foo/", metadata !2} ; [ DW_TAG_file_type ]
!2 = metadata !{i32 589841, i32 0, i32 12, metadata !"a.c", metadata !"/Users/mmp/foo", metadata !"foo", i1 true, i1 true, metadata !"-g", i32 0} ; [ DW_TAG_compile_unit ]
!3 = metadata !{i32 589860, metadata !2, metadata !"int32", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
!4 = metadata !{i32 590080, metadata !5, metadata !"y", metadata !1, i32 5, metadata !3, i32 0} ; [ DW_TAG_auto_variable ]
!5 = metadata !{i32 589835, metadata !0, i32 4, i32 0, metadata !1, i32 0} ; [ DW_TAG_lexical_block ]
!6 = metadata !{i32 1234}
!7 = metadata !{i32 5, i32 0, metadata !5, null}

However, if I run dwarfdump on the object file, there's nothing there for the variable 'y' (see below). Note that I am able to get correct DWARF output for global variables, so presumably the rest of my infrastructure isn't totally broken.

Any guidance about how best to proceed would be greatly appreciated!

Thanks,
-matt

Here there is not any instruction (ignoring dbg intrinsics) with line number information. If you add !dbg !7 at the end of ‘ret’ then it’ll work.

Hi Devang,

Why does type/variable information depend on line information?

cheers,
--renato

You need line number information to map source code to instructions. Otherwise, you'll have a function and variable info in debug info but a debugger won't know which instructions belong to given function and what's the range of a variable.

That can be worked out from the debug_info and debug_loc without
requiring debug_line info. (not the instruction vs. function, but all
the rest).

Not that debuggers do know that, and not that it would be useful for
debugging... But I don't see a strong point to intentionally omit
them.

Just a thought...

cheers,
--renato