From 6b713800ff03fdbb1d770d1e00af0e76041f3c03 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Tue, 29 Oct 2013 05:49:41 +0000 Subject: [PATCH] Debug Info: instead of calling addToContextOwner which constructs the context after the DIE creation, we construct the context first. This touches creation of namespaces and global variables. The purpose is to handle all DIE creations similarly: constructs the context first, then creates the DIE and immediately adds the DIE to its parent. We use createAndAddDIE to wrap around "new DIE(". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193589 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 24 +++++++++++++------ test/DebugInfo/X86/2010-08-10-DbgConstant.ll | 4 ++-- .../X86/2011-09-26-GlobalVarContext.ll | 8 +++---- test/DebugInfo/X86/DW_TAG_friend.ll | 6 ++--- test/DebugInfo/X86/empty-array.ll | 17 ++++++------- test/DebugInfo/X86/enum-class.ll | 4 ++-- test/DebugInfo/X86/fission-cu.ll | 18 +++++++------- test/DebugInfo/X86/gnu-public-names.ll | 6 ++--- .../X86/nondefault-subrange-array.ll | 19 ++++++++------- test/DebugInfo/X86/objc-fwd-decl.ll | 2 +- test/DebugInfo/X86/stringpool.ll | 8 +++---- test/DebugInfo/X86/struct-loc.ll | 2 +- test/DebugInfo/template-recursive-void.ll | 2 +- 13 files changed, 66 insertions(+), 54 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 8528ab7edf5..6c36cd28f50 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -1327,11 +1327,19 @@ CompileUnit::constructTemplateValueParameterDIE(DIE &Buffer, /// getOrCreateNameSpace - Create a DIE for DINameSpace. DIE *CompileUnit::getOrCreateNameSpace(DINameSpace NS) { + // Construct the context before querying for the existence of the DIE in case + // such construction creates the DIE. + DIE *ContextDIE = getOrCreateContextDIE(NS.getContext()); + if (!ContextDIE) + // If the context is null, DIE should belong to the CU we call construct + // function on. + ContextDIE = CUDie.get(); + DIE *NDie = getDIE(NS); if (NDie) return NDie; - NDie = new DIE(dwarf::DW_TAG_namespace); - insertDIE(NS, NDie); + NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS); + if (!NS.getName().empty()) { addString(NDie, dwarf::DW_AT_name, NS.getName()); addAccelNamespace(NS.getName(), NDie); @@ -1339,7 +1347,6 @@ DIE *CompileUnit::getOrCreateNameSpace(DINameSpace NS) { } else addAccelNamespace("(anonymous namespace)", NDie); addSourceLine(NDie, NS); - addToContextOwner(NDie, NS.getContext()); return NDie; } @@ -1506,9 +1513,14 @@ void CompileUnit::createGlobalVariableDIE(const MDNode *N) { // If this is not a static data member definition, create the variable // DIE and add the initial set of attributes to it. if (!VariableDIE) { - VariableDIE = new DIE(GV.getTag()); + // Construct the context before querying for the existence of the DIE in + // case such construction creates the DIE. + DIE *ContextDIE = getOrCreateContextDIE(GVContext); + if (!ContextDIE) + ContextDIE = CUDie.get(); + // Add to map. - insertDIE(N, VariableDIE); + VariableDIE = createAndAddDIE(GV.getTag(), *ContextDIE, N); // Add name and type. addString(VariableDIE, dwarf::DW_AT_name, GV.getDisplayName()); @@ -1520,8 +1532,6 @@ void CompileUnit::createGlobalVariableDIE(const MDNode *N) { // Add line number info. addSourceLine(VariableDIE, GV); - // Add to context owner. - addToContextOwner(VariableDIE, GVContext); } // Add location. diff --git a/test/DebugInfo/X86/2010-08-10-DbgConstant.ll b/test/DebugInfo/X86/2010-08-10-DbgConstant.ll index 84842f92d2a..667094154a0 100644 --- a/test/DebugInfo/X86/2010-08-10-DbgConstant.ll +++ b/test/DebugInfo/X86/2010-08-10-DbgConstant.ll @@ -1,7 +1,7 @@ ; RUN: llc -mtriple=i686-linux -O0 -filetype=obj -o %t %s ; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s -; CHECK: DW_TAG_constant [4] -; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000002c] = "ro") +; CHECK: DW_TAG_constant +; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x{{[0-9a-f]*}}] = "ro") define void @foo() nounwind ssp { entry: diff --git a/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll b/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll index 6cd56a57c1f..73dbca33e07 100644 --- a/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll +++ b/test/DebugInfo/X86/2011-09-26-GlobalVarContext.ll @@ -37,13 +37,13 @@ declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone !19 = metadata !{i32 5, i32 5, metadata !16, null} !20 = metadata !{metadata !"test.c", metadata !"/work/llvm/vanilla/test/DebugInfo"} -; CHECK: DW_TAG_variable [3] -; CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000043] = "GLB") +; CHECK: DW_TAG_variable +; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x{{[0-9a-f]*}}] = "GLB") ; CHECK: DW_AT_decl_file [DW_FORM_data1] (0x01) ; CHECK: DW_AT_decl_line [DW_FORM_data1] (0x01) -; CHECK: DW_TAG_variable [6] -; CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000004d] = "LOC") +; CHECK: DW_TAG_variable +; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x{{[0-9a-f]*}}] = "LOC") ; CHECK: DW_AT_decl_file [DW_FORM_data1] (0x01) ; CHECK: DW_AT_decl_line [DW_FORM_data1] (0x04) diff --git a/test/DebugInfo/X86/DW_TAG_friend.ll b/test/DebugInfo/X86/DW_TAG_friend.ll index a059fd150d3..040f36f8aec 100644 --- a/test/DebugInfo/X86/DW_TAG_friend.ll +++ b/test/DebugInfo/X86/DW_TAG_friend.ll @@ -3,10 +3,10 @@ ; Check that the friend tag is there and is followed by a DW_AT_friend that has a reference back. -; CHECK: [[BACK:0x[0-9a-f]*]]: DW_TAG_class_type [4] +; CHECK: [[BACK:0x[0-9a-f]*]]: DW_TAG_class_type ; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[{{.*}}] = "A") -; CHECK: DW_TAG_friend [9] -; CHECK-NEXT: DW_AT_friend [DW_FORM_ref4] (cu + 0x0032 => {[[BACK]]}) +; CHECK: DW_TAG_friend +; CHECK-NEXT: DW_AT_friend [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BACK]]}) %class.A = type { i32 } diff --git a/test/DebugInfo/X86/empty-array.ll b/test/DebugInfo/X86/empty-array.ll index c0a422be901..64ad768c294 100644 --- a/test/DebugInfo/X86/empty-array.ll +++ b/test/DebugInfo/X86/empty-array.ll @@ -6,21 +6,22 @@ @a = global %class.A zeroinitializer, align 4 -; CHECK: 0x0000002d: DW_TAG_base_type [3] +; CHECK: [[BASETYPE:0x[0-9a-f]*]]: DW_TAG_base_type +; CHECK: [[BASE2:0x[0-9a-f]*]]: DW_TAG_base_type ; CHECK-NEXT: DW_AT_name ; CHECK-NEXT: DW_AT_byte_size [DW_FORM_data1] (0x04) ; CHECK-NEXT: DW_AT_encoding [DW_FORM_data1] (0x05) -; CHECK: 0x00000034: DW_TAG_array_type [4] * -; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x0026 => {0x00000026}) +; CHECK: [[ARRAY:0x[0-9a-f]*]]: DW_TAG_array_type [{{.*}}] * +; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASETYPE]]}) -; CHECK: 0x00000039: DW_TAG_subrange_type [5] -; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x002d => {0x0000002d}) +; CHECK: DW_TAG_subrange_type +; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE2]]}) ; CHECK-NOT: DW_AT_upper_bound -; CHECK: DW_TAG_member [8] -; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000003f] = "x") -; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x0034 => {0x00000034}) +; CHECK: DW_TAG_member +; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x{{[0-9a-f]*}}] = "x") +; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[ARRAY]]}) !llvm.dbg.cu = !{!0} diff --git a/test/DebugInfo/X86/enum-class.ll b/test/DebugInfo/X86/enum-class.ll index 96aefe228be..2472fe633e0 100644 --- a/test/DebugInfo/X86/enum-class.ll +++ b/test/DebugInfo/X86/enum-class.ll @@ -28,12 +28,12 @@ !21 = metadata !{i32 786484, i32 0, null, metadata !"c", metadata !"c", metadata !"", metadata !4, i32 6, metadata !12, i32 0, i32 1, i32* @c, null} ; [ DW_TAG_variable ] !22 = metadata !{metadata !"foo.cpp", metadata !"/Users/echristo/tmp"} -; CHECK: DW_TAG_enumeration_type [3] +; CHECK: DW_TAG_enumeration_type [{{.*}}] ; CHECK: DW_AT_type [DW_FORM_ref4] ; CHECK: DW_AT_enum_class [DW_FORM_flag_present] (true) ; CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[{{.*}}] = "A") -; CHECK: DW_TAG_enumeration_type [3] * +; CHECK: DW_TAG_enumeration_type [{{.*}}] * ; CHECK: DW_AT_type [DW_FORM_ref4] ; CHECK: DW_AT_enum_class [DW_FORM_flag_present] (true) ; CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[{{.*}}] = "B") diff --git a/test/DebugInfo/X86/fission-cu.ll b/test/DebugInfo/X86/fission-cu.ll index 7aeefab8aa1..8feb54a8c36 100644 --- a/test/DebugInfo/X86/fission-cu.ll +++ b/test/DebugInfo/X86/fission-cu.ll @@ -54,12 +54,7 @@ ; CHECK-NOT: DW_AT_comp_dir ; CHECK: DW_AT_GNU_dwo_id DW_FORM_data8 -; CHECK: [2] DW_TAG_base_type DW_CHILDREN_no -; CHECK: DW_AT_name DW_FORM_GNU_str_index -; CHECK: DW_AT_encoding DW_FORM_data1 -; CHECK: DW_AT_byte_size DW_FORM_data1 - -; CHECK: [3] DW_TAG_variable DW_CHILDREN_no +; CHECK: [2] DW_TAG_variable DW_CHILDREN_no ; CHECK: DW_AT_name DW_FORM_GNU_str_index ; CHECK: DW_AT_type DW_FORM_ref4 ; CHECK: DW_AT_external DW_FORM_flag_present @@ -67,6 +62,11 @@ ; CHECK: DW_AT_decl_line DW_FORM_data1 ; CHECK: DW_AT_location DW_FORM_block1 +; CHECK: [3] DW_TAG_base_type DW_CHILDREN_no +; CHECK: DW_AT_name DW_FORM_GNU_str_index +; CHECK: DW_AT_encoding DW_FORM_data1 +; CHECK: DW_AT_byte_size DW_FORM_data1 + ; Check that the rest of the compile units have information. ; CHECK: .debug_info.dwo contents: ; CHECK: DW_TAG_compile_unit @@ -77,15 +77,15 @@ ; CHECK-NOT: DW_AT_stmt_list ; CHECK-NOT: DW_AT_comp_dir ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x0000000000000000) -; CHECK: DW_TAG_base_type -; CHECK: DW_AT_name [DW_FORM_GNU_str_index] ( indexed (00000003) string = "int") ; CHECK: DW_TAG_variable ; CHECK: DW_AT_name [DW_FORM_GNU_str_index] ( indexed (00000002) string = "a") -; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x0018 => {0x00000018}) +; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[TYPE:0x[0-9a-f]*]]}) ; CHECK: DW_AT_external [DW_FORM_flag_present] (true) ; CHECK: DW_AT_decl_file [DW_FORM_data1] (0x01) ; CHECK: DW_AT_decl_line [DW_FORM_data1] (0x01) ; CHECK: DW_AT_location [DW_FORM_block1] (<0x02> fb 00 ) +; CHECK: [[TYPE]]: DW_TAG_base_type +; CHECK: DW_AT_name [DW_FORM_GNU_str_index] ( indexed (00000003) string = "int") ; CHECK: .debug_str.dwo contents: diff --git a/test/DebugInfo/X86/gnu-public-names.ll b/test/DebugInfo/X86/gnu-public-names.ll index 50da878e651..bc701add75f 100644 --- a/test/DebugInfo/X86/gnu-public-names.ll +++ b/test/DebugInfo/X86/gnu-public-names.ll @@ -77,12 +77,12 @@ ; CHECK: [[GLOB_NS_VAR_DECL:[0-9a-f]+]]: DW_TAG_variable ; CHECK-NEXT: DW_AT_name {{.*}} "global_namespace_variable" -; CHECK: [[D:[0-9a-f]+]]: DW_TAG_structure_type -; CHECK-NEXT: DW_AT_name {{.*}} "D" - ; CHECK: [[D_VAR_DECL:[0-9a-f]+]]: DW_TAG_variable ; CHECK-NEXT: DW_AT_name {{.*}} "d" +; CHECK: [[D:[0-9a-f]+]]: DW_TAG_structure_type +; CHECK-NEXT: DW_AT_name {{.*}} "D" + ; CHECK: [[GLOB_NS_FUNC:[0-9a-f]+]]: DW_TAG_subprogram ; CHECK-NEXT: DW_AT_MIPS_linkage_name ; CHECK-NEXT: DW_AT_name {{.*}} "global_namespace_function" diff --git a/test/DebugInfo/X86/nondefault-subrange-array.ll b/test/DebugInfo/X86/nondefault-subrange-array.ll index 44d35a222a9..12934ced47f 100644 --- a/test/DebugInfo/X86/nondefault-subrange-array.ll +++ b/test/DebugInfo/X86/nondefault-subrange-array.ll @@ -8,22 +8,23 @@ ; Check that we can handle non-default array bounds. In this case, the array ; goes from [-3, 38]. -; CHECK: 0x0000002d: DW_TAG_base_type [3] -; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000041] = "int") +; CHECK: [[BASE:0x[0-9a-f]*]]: DW_TAG_base_type +; CHECK: [[BASE2:0x[0-9a-f]*]]: DW_TAG_base_type +; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x{{[0-9a-f]*}}] = "int") ; CHECK-NEXT: DW_AT_byte_size [DW_FORM_data1] (0x04) ; CHECK-NEXT: DW_AT_encoding [DW_FORM_data1] (0x05) -; CHECK: 0x00000034: DW_TAG_array_type [4] * -; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x0026 => {0x00000026}) +; CHECK: [[ARRAY:0x[0-9a-f]*]]: DW_TAG_array_type [{{.*}}] * +; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE]]}) -; CHECK: 0x00000039: DW_TAG_subrange_type [5] -; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x002d => {0x0000002d}) +; CHECK: DW_TAG_subrange_type +; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE2]]}) ; CHECK-NEXT: DW_AT_lower_bound [DW_FORM_data8] (0xfffffffffffffffd) ; CHECK-NEXT: DW_AT_upper_bound [DW_FORM_data1] (0x26) -; CHECK: 0x00000055: DW_TAG_member [8] -; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000003f] = "x") -; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x0034 => {0x00000034}) +; CHECK: DW_TAG_member +; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x{{[0-9a-f]*}}] = "x") +; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[ARRAY]]}) !llvm.dbg.cu = !{!0} diff --git a/test/DebugInfo/X86/objc-fwd-decl.ll b/test/DebugInfo/X86/objc-fwd-decl.ll index 1fa25abc353..29b4696b056 100644 --- a/test/DebugInfo/X86/objc-fwd-decl.ll +++ b/test/DebugInfo/X86/objc-fwd-decl.ll @@ -1,7 +1,7 @@ ; RUN: llc -mtriple=x86_64-macosx %s -o %t -filetype=obj ; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s -; CHECK: 0x00000027: DW_TAG_structure_type +; CHECK: DW_TAG_structure_type ; CHECK: DW_AT_declaration ; CHECK: DW_AT_APPLE_runtime_class diff --git a/test/DebugInfo/X86/stringpool.ll b/test/DebugInfo/X86/stringpool.ll index c8cba739565..81ab8e6edb1 100644 --- a/test/DebugInfo/X86/stringpool.ll +++ b/test/DebugInfo/X86/stringpool.ll @@ -21,7 +21,7 @@ ; Verify that we refer to 'yyyy' with a relocation. ; LINUX: .long .Linfo_string3 # DW_AT_name -; LINUX-NEXT: .long 38 # DW_AT_type +; LINUX-NEXT: .long {{[0-9]+}} # DW_AT_type ; LINUX-NEXT: # DW_AT_external ; LINUX-NEXT: .byte 1 # DW_AT_decl_file ; LINUX-NEXT: .byte 1 # DW_AT_decl_line @@ -30,9 +30,9 @@ ; LINUX-NEXT: .quad yyyy ; Verify that we refer to 'yyyy' without a relocation. -; DARWIN: Lset5 = Linfo_string3-Linfo_string ## DW_AT_name -; DARWIN-NEXT: .long Lset5 -; DARWIN-NEXT: .long 38 ## DW_AT_type +; DARWIN: Lset[[ID:[0-9]+]] = Linfo_string3-Linfo_string ## DW_AT_name +; DARWIN-NEXT: .long Lset[[ID]] +; DARWIN-NEXT: .long {{[0-9]+}} ## DW_AT_type ; DARWIN-NEXT: ## DW_AT_external ; DARWIN-NEXT: .byte 1 ## DW_AT_decl_file ; DARWIN-NEXT: .byte 1 ## DW_AT_decl_line diff --git a/test/DebugInfo/X86/struct-loc.ll b/test/DebugInfo/X86/struct-loc.ll index 7b424d6e7fb..079276d5f34 100644 --- a/test/DebugInfo/X86/struct-loc.ll +++ b/test/DebugInfo/X86/struct-loc.ll @@ -2,7 +2,7 @@ ; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s ; Make sure that structures have a decl file and decl line attached. -; CHECK: DW_TAG_structure_type [3] +; CHECK: DW_TAG_structure_type ; CHECK: DW_AT_decl_file ; CHECK: DW_AT_decl_line ; CHECK: DW_TAG_member diff --git a/test/DebugInfo/template-recursive-void.ll b/test/DebugInfo/template-recursive-void.ll index ba4508680f7..3ffb80bdbe4 100644 --- a/test/DebugInfo/template-recursive-void.ll +++ b/test/DebugInfo/template-recursive-void.ll @@ -13,7 +13,7 @@ ; class bar : public foo { }; ; bar filters; -; CHECK: DW_TAG_template_type_parameter [10] +; CHECK: DW_TAG_template_type_parameter [{{.*}}] ; CHECK-NEXT: DW_AT_name{{.*}}"T" ; CHECK-NOT: DW_AT_type ; CHECK: NULL