[LLVMdev] DW_AT_location not getting generated for local variables

Joe Groff arcata at gmail.com
Mon Jan 2 11:55:06 PST 2012


I found the problem. The llvm.dbg.declare call must have a !dbg tag,
otherwise the location info is not generated. Changing the invocation
in my original example to "call void @llvm.dbg.declare(metadata !{i32*
%"bar:Int32"}, metadata !13), !dbg !16" causes MC to generate the
local location as expected.

-Joe

On Thu, Dec 29, 2011 at 12:41 PM, Joe Groff <arcata at gmail.com> wrote:
> I figured out my previous problem with DIBuilder. However, now I can't seem
> to get the compiler to emit location information for local variables. Here's
> how my IR looks:
>
> ---
> define i32 @"\01_main"() {
> init:
>   %exception1 = alloca i8*
>   %0 = alloca i32
>   %"bar:Int32" = alloca i32
>   %1 = alloca i32
>   %2 = alloca i32*
>   br label %code
>
> code:                                             ; preds = %init
>   call void @llvm.dbg.declare(metadata !{i32* %"bar:Int32"}, metadata !13)
>   store i32 1, i32* %"bar:Int32", !dbg !16
>   store i32 1, i32* %1, !dbg !17
>   %3 = load i32* %"bar:Int32", !dbg !17
>   %4 = load i32* %1, !dbg !17
>   %5 = add i32 %3, %4, !dbg !17
>   store i32 %5, i32* %"bar:Int32", !dbg !17
>   store i32* %"bar:Int32", i32** %2, !dbg !18
>   %6 = load i32** %2, !dbg !18
>   %7 = load i32* %6, !dbg !18
>   store i32 %7, i32* %0, !dbg !18
>   br label %return, !dbg !18
>
> return:                                           ; preds = %code
>   %8 = load i32* %0
>   ret i32 %8
>
> exception:                                        ; No predecessors!
>   unreachable
> }
>
> declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
>
> !llvm.dbg.cu = !{!0}
>
> !0 = metadata !{i32 720913, i32 0, i32 49572, metadata !"foo.clay", metadata
> !"", metadata !"clay compiler 0.1git", i1 true, i1 false, metadata !"", i32
> 0, metadata !1, metadata !1, metadata !3, metadata !1} ; [
> DW_TAG_compile_unit ]
> !1 = metadata !{metadata !2}
> !2 = metadata !{i32 0}
> !3 = metadata !{metadata !4}
> !4 = metadata !{metadata !5}
> !5 = metadata !{i32 720942, i32 0, metadata !6, metadata !"foo", metadata
> !"foo", metadata !"\01_main", metadata !7, i32 1, metadata !8, i1 false, i1
> true, i32 0, i32 0, i32 0, i32 0, i1 false, i32 ()* @"\01_main", null, null,
> metadata !11} ; [ DW_TAG_subprogram ]
> !6 = metadata !{i32 720953, null, metadata !"__main__", metadata !7, i32 1}
> ; [ DW_TAG_namespace ]
> !7 = metadata !{i32 720937, metadata !"foo.clay", metadata !"", null} ; [
> DW_TAG_file_type ]
> !8 = metadata !{i32 720917, i32 0, metadata !"", i32 0, i32 0, i64 0, i64 0,
> i32 0, i32 0, i32 0, metadata !9, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]
> !9 = metadata !{metadata !10}
> !10 = metadata !{i32 720932, null, metadata !"Int32", null, i32 0, i64 32,
> i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
> !11 = metadata !{metadata !12}
> !12 = metadata !{metadata !13}
> !13 = metadata !{i32 721152, metadata !14, metadata !"bar", metadata !7, i32
> 2, metadata !10, i32 0, i32 0} ; [ DW_TAG_auto_variable ]
> !14 = metadata !{i32 720907, metadata !15, i32 1, i32 1, metadata !7, i32 1}
> ; [ DW_TAG_lexical_block ]
> !15 = metadata !{i32 720907, metadata !5, i32 1, i32 1, metadata !7, i32 0}
> ; [ DW_TAG_lexical_block ]
> !16 = metadata !{i32 2, i32 2, metadata !14, null}
> !17 = metadata !{i32 3, i32 3, metadata !14, null}
> !18 = metadata !{i32 4, i32 4, metadata !14, null}
> ---
>
> And this is what dwarfdump on the compiled object file shows. The
> TAG_variable entry for 'bar' is missing its AT_location.
>
> ---
> ----------------------------------------------------------------------
>  File: foo.o (x86_64)
> ----------------------------------------------------------------------
> .debug_info contents:
>
> 0x00000000: Compile Unit: length = 0x000000a9  version = 0x0002  abbr_offset
> = 0x00000000  addr_size = 0x08  (next CU at 0x000000ad)
>
> 0x0000000b: TAG_compile_unit [1] *
>              AT_producer( "clay compiler 0.1git" )
>              AT_language( Unknown DW_LANG constant: 0xc1a4 )
>              AT_name( "foo.clay" )
>              AT_entry_pc( 0x0000000000000000 )
>              AT_stmt_list( 0x00000000 )
>
> 0x00000038:     TAG_namespace [2] *
>                  AT_sibling( {0x0000005c} )
>                  AT_name( "__main__" )
>                  AT_decl_file(
> "/Users/joe/Documents/Code/others/clay/foo.clay" )
>                  AT_decl_line( 1 )
>
> 0x00000048:         TAG_subprogram [3]
>                      AT_MIPS_linkage_name( "_main" )
>                      AT_name( "foo" )
>                      AT_decl_file(
> "/Users/joe/Documents/Code/others/clay/foo.clay" )
>                      AT_decl_line( 1 )
>                      AT_type( {0x0000005c} ( Int32 ) )
>                      AT_external( 0x01 )
>                      AT_declaration( 0x01 )
>
> 0x0000005b:         NULL
>
> 0x0000005c:     TAG_base_type [4]
>                  AT_name( "Int32" )
>                  AT_encoding( DW_ATE_signed )
>                  AT_byte_size( 0x04 )
>
> 0x00000065:     TAG_subprogram [5] *
>                  AT_specification( {0x00000048} ( "_main" ) )
>                  AT_low_pc( 0x0000000000000020 )
>                  AT_high_pc( 0x0000000000000051 )
>                  AT_frame_base( rbp )
>
> 0x0000007c:         TAG_lexical_block [6] *
>                      AT_low_pc( 0x0000000000000028 )
>                      AT_high_pc( 0x000000000000004c )
>
> 0x0000008d:             TAG_lexical_block [6] *
>                          AT_low_pc( 0x0000000000000028 )
>                          AT_high_pc( 0x000000000000004c )
>
> 0x0000009e:                 TAG_variable [7]
>                              AT_name( "bar" )
>                              AT_decl_file(
> "/Users/joe/Documents/Code/others/clay/foo.clay" )
>                              AT_decl_line( 2 )
>                              AT_type( {0x0000005c} ( Int32 ) )
>
> 0x000000a9:                 NULL
>
> 0x000000aa:             NULL
>
> 0x000000ab:         NULL
>
> 0x000000ac:     NULL
> ---
>
> Am I using llvm.dbg.declare correctly? Is there something missing in my
> metadata?
>
> -Joe




More information about the llvm-dev mailing list