[PATCH] D71599: [LLVM] Support to emit extern variables debuginfo with "-fstandalone-debug"

Jaydeep Chauhan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 10:42:47 PST 2019


Jac1494 updated this revision to Diff 234749.
Jac1494 added a comment.
Herald added a subscriber: ormris.

Test case Added


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71599/new/

https://reviews.llvm.org/D71599

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/test/DebugInfo/Generic/debug-info-extern-variable-declaration.ll


Index: llvm/test/DebugInfo/Generic/debug-info-extern-variable-declaration.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/Generic/debug-info-extern-variable-declaration.ll
@@ -0,0 +1,56 @@
+; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -v -debug-info - | FileCheck %s
+; Check extern variable debuginfo , declaration attribute
+
+; CHECK: DW_TAG_variable 
+; CHECK:   DW_AT_name {{.*}} "i"
+; CHECK:   DW_AT_declaration
+; CHECK-NOT:  DW_AT_location
+
+; CHECK: DW_TAG_variable
+; CHECK:   DW_AT_name {{.*}} "j"
+; CHECK:   DW_AT_declaration
+; CHECK-NOT:  DW_AT_location
+
+
+; ModuleID = 'debug-info-extern-variable-declaration.c'
+source_filename = "debug-info-extern-variable-declaration.c"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at i = external dso_local global i32, align 4, !dbg !0
+ at j = external dso_local global i32, align 4, !dbg !6
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @foo() #0 !dbg !13 {
+entry:
+  %0 = load i32, i32* @i, align 4, !dbg !16
+  %1 = load i32, i32* @j, align 4, !dbg !17
+  %add = add nsw i32 %0, %1, !dbg !18
+  ret i32 %add, !dbg !19
+}
+
+attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!9, !10, !11}
+!llvm.ident = !{!12}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "i", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: false)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git bbcf1c3496ce2bd1ed87e8fb15ad896e279633ce)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "debug-info-extern-variable-declaration.c", directory: "/home/bft/Jaydeep/llvm-project/build_debug_fix/bin")
+!4 = !{}
+!5 = !{!0, !6}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "j", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: false)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{i32 7, !"Dwarf Version", i32 4}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{i32 1, !"wchar_size", i32 4}
+!12 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git bbcf1c3496ce2bd1ed87e8fb15ad896e279633ce)"}
+!13 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !14, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4)
+!14 = !DISubroutineType(types: !15)
+!15 = !{!8}
+!16 = !DILocation(line: 4, column: 10, scope: !13)
+!17 = !DILocation(line: 4, column: 12, scope: !13)
+!18 = !DILocation(line: 4, column: 11, scope: !13)
+!19 = !DILocation(line: 4, column: 3, scope: !13)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -171,7 +171,11 @@
   if (!GV->isDefinition())
     addFlag(*VariableDIE, dwarf::DW_AT_declaration);
   else
+  {
+    // Add location.
+    addLocationAttribute(VariableDIE, GV, GlobalExprs);
     addGlobalName(GV->getName(), *VariableDIE, DeclContext);
+  }
 
   if (uint32_t AlignInBytes = GV->getAlignInBytes())
     addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
@@ -180,9 +184,6 @@
   if (MDTuple *TP = GV->getTemplateParams())
     addTemplateParams(*VariableDIE, DINodeArray(TP));
 
-  // Add location.
-  addLocationAttribute(VariableDIE, GV, GlobalExprs);
-
   return VariableDIE;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71599.234749.patch
Type: text/x-patch
Size: 4295 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191219/99a94146/attachment-0001.bin>


More information about the llvm-commits mailing list