llvm.org GIT mirror llvm / bffba31
[LLVM-C] DIBuilder Bindings For Variable Expressions Summary: Add DIBuilder bindings for (global) variable expressions, variable value expressions, and debug value intrinsic insertion. Reviewers: harlanhaskins, deadalnix, whitequark Reviewed By: whitequark Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45979 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330661 91177308-0d34-0410-b5e6-96231b3b80d8 Robert Widmann 1 year, 4 months ago
7 changed file(s) with 226 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
2727 File ? unwrap(File) : nullptr, Line,
2828 Context ? unwrap(Context) : nullptr));
2929 }
30
31 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
32 LLVMValueRef Val,
33 LLVMMetadataRef VarInfo,
34 LLVMMetadataRef Expr,
35 LLVMBasicBlockRef Block) {
36 // Fail immediately here until the llgo folks update their bindings. The
37 // called function is going to assert out anyway.
38 llvm_unreachable("DIBuilder API change requires a DebugLoc");
39
40 DIBuilder *D = unwrap(Dref);
41 Instruction *Instr = D->insertDbgValueIntrinsic(
42 unwrap(Val), unwrap(VarInfo), unwrap(Expr),
43 /* DebugLoc */ nullptr, unwrap(Block));
44 return wrap(Instr);
45 }
3232 LLVMMetadataRef File, unsigned Line,
3333 LLVMMetadataRef Context);
3434
35 LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef D, LLVMValueRef Val,
36 LLVMMetadataRef VarInfo,
37 LLVMMetadataRef Expr,
38 LLVMBasicBlockRef Block);
39
4035 #ifdef __cplusplus
4136 } // extern "C"
4237 #endif
570570 // InsertValueAtEnd inserts a call to llvm.dbg.value at the end of the
571571 // specified basic block for the given value and associated debug metadata.
572572 func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, bb BasicBlock) Value {
573 result := C.LLVMDIBuilderInsertValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, bb.C)
573 result := C.LLVMDIBuilderInsertDbgValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, nil, bb.C)
574574 return Value{C: result}
575575 }
576576
716716 int64_t *Addr, size_t Length);
717717
718718 /**
719 * Create a new descriptor for the specified variable that does not have an
720 * address, but does have a constant value.
721 * \param Builder The DIBuilder.
722 * \param Value The constant value.
723 */
724 LLVMMetadataRef
725 LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder,
726 int64_t Value);
727
728 /**
729 * Create a new descriptor for the specified variable.
730 * \param Scope Variable scope.
731 * \param Name Name of the variable.
732 * \param NameLen The length of the C string passed to \c Name.
733 * \param Linkage Mangled name of the variable.
734 * \param LinkLen The length of the C string passed to \c Linkage.
735 * \param File File where this variable is defined.
736 * \param LineNo Line number.
737 * \param Ty Variable Type.
738 * \param LocalToUnit Boolean flag indicate whether this variable is
739 * externally visible or not.
740 * \param Expr The location of the global relative to the attached
741 * GlobalVariable.
742 * \param Decl Reference to the corresponding declaration.
743 * \param AlignInBits Variable alignment(or 0 if no alignment attr was
744 * specified)
745 */
746 LLVMMetadataRef
747 LLVMDIBuilderCreateGlobalVariableExpression(LLVMDIBuilderRef Builder,
748 LLVMMetadataRef Scope,
749 const char *Name, size_t NameLen,
750 const char *Linkage, size_t LinkLen,
751 LLVMMetadataRef File,
752 unsigned LineNo,
753 LLVMMetadataRef Ty,
754 LLVMBool LocalToUnit,
755 LLVMMetadataRef Expr,
756 LLVMMetadataRef Decl,
757 uint32_t AlignInBits);
758
759 /**
760 * Create a new descriptor for the specified global variable that is temporary
761 * and meant to be RAUWed.
762 * \param Scope Variable scope.
763 * \param Name Name of the variable.
764 * \param NameLen The length of the C string passed to \c Name.
765 * \param Linkage Mangled name of the variable.
766 * \param LnkLen The length of the C string passed to \c Linkage.
767 * \param File File where this variable is defined.
768 * \param LineNo Line number.
769 * \param Ty Variable Type.
770 * \param LocalToUnit Boolean flag indicate whether this variable is
771 * externally visible or not.
772 * \param Expr The location of the global relative to the attached
773 * GlobalVariable.
774 * \param Decl Reference to the corresponding declaration.
775 * \param AlignInBits Variable alignment(or 0 if no alignment attr was
776 * specified)
777 */
778 LLVMMetadataRef
779 LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder,
780 LLVMMetadataRef Scope,
781 const char *Name, size_t NameLen,
782 const char *Linkage, size_t LnkLen,
783 LLVMMetadataRef File,
784 unsigned LineNo,
785 LLVMMetadataRef Ty,
786 LLVMBool LocalToUnit,
787 LLVMMetadataRef Decl,
788 uint32_t AlignInBits);
789
790 /**
719791 * Insert a new llvm.dbg.declare intrinsic call before the given instruction.
720792 * \param Builder The DIBuilder.
721793 * \param Storage The storage of the variable to declare.
742814 LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
743815 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
744816 LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
817
818 /**
819 * Insert a new llvm.dbg.value intrinsic call before the given instruction.
820 * \param Builder The DIBuilder.
821 * \param Val The value of the variable.
822 * \param VarInfo The variable's debug info descriptor.
823 * \param Expr A complex location expression for the variable.
824 * \param DebugLoc Debug info location.
825 * \param Instr Instruction acting as a location for the new intrinsic.
826 */
827 LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder,
828 LLVMValueRef Val,
829 LLVMMetadataRef VarInfo,
830 LLVMMetadataRef Expr,
831 LLVMMetadataRef DebugLoc,
832 LLVMValueRef Instr);
833
834 /**
835 * Insert a new llvm.dbg.value intrinsic call at the end of the given basic
836 * block. If the basic block has a terminator instruction, the intrinsic is
837 * inserted before that terminator instruction.
838 * \param Builder The DIBuilder.
839 * \param Val The value of the variable.
840 * \param VarInfo The variable's debug info descriptor.
841 * \param Expr A complex location expression for the variable.
842 * \param DebugLoc Debug info location.
843 * \param Block Basic block acting as a location for the new intrinsic.
844 */
845 LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder,
846 LLVMValueRef Val,
847 LLVMMetadataRef VarInfo,
848 LLVMMetadataRef Expr,
849 LLVMMetadataRef DebugLoc,
850 LLVMBasicBlockRef Block);
745851
746852 /**
747853 * Create a new descriptor for a local auto variable.
10411041 Length)));
10421042 }
10431043
1044 LLVMMetadataRef
1045 LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder,
1046 int64_t Value) {
1047 return wrap(unwrap(Builder)->createConstantValueExpression(Value));
1048 }
1049
1050 LLVMMetadataRef
1051 LLVMDIBuilderCreateGlobalVariableExpression(LLVMDIBuilderRef Builder,
1052 LLVMMetadataRef Scope,
1053 const char *Name, size_t NameLen,
1054 const char *Linkage, size_t LinkLen,
1055 LLVMMetadataRef File,
1056 unsigned LineNo,
1057 LLVMMetadataRef Ty,
1058 LLVMBool LocalToUnit,
1059 LLVMMetadataRef Expr,
1060 LLVMMetadataRef Decl,
1061 uint32_t AlignInBits) {
1062 return wrap(unwrap(Builder)->createGlobalVariableExpression(
1063 unwrapDI(Scope), {Name, NameLen}, {Linkage, LinkLen},
1064 unwrapDI(File), LineNo, unwrapDI(Ty),
1065 LocalToUnit, unwrap(Expr),
1066 unwrapDI(Decl), AlignInBits));
1067 }
1068
1069 LLVMMetadataRef
1070 LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder,
1071 LLVMMetadataRef Scope,
1072 const char *Name, size_t NameLen,
1073 const char *Linkage, size_t LnkLen,
1074 LLVMMetadataRef File,
1075 unsigned LineNo,
1076 LLVMMetadataRef Ty,
1077 LLVMBool LocalToUnit,
1078 LLVMMetadataRef Decl,
1079 uint32_t AlignInBits) {
1080 return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl(
1081 unwrapDI(Scope), {Name, NameLen}, {Linkage, LnkLen},
1082 unwrapDI(File), LineNo, unwrapDI(Ty),
1083 LocalToUnit, unwrapDI(Decl), AlignInBits));
1084 }
1085
10441086 LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
10451087 LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
10461088 LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMValueRef Instr) {
10561098 return wrap(unwrap(Builder)->insertDeclare(
10571099 unwrap(Storage), unwrap(VarInfo),
10581100 unwrap(Expr), unwrap(DL),
1101 unwrap(Block)));
1102 }
1103
1104 LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder,
1105 LLVMValueRef Val,
1106 LLVMMetadataRef VarInfo,
1107 LLVMMetadataRef Expr,
1108 LLVMMetadataRef DebugLoc,
1109 LLVMValueRef Instr) {
1110 return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
1111 unwrap(Val), unwrap(VarInfo),
1112 unwrap(Expr), unwrap(DebugLoc),
1113 unwrap(Instr)));
1114 }
1115
1116 LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder,
1117 LLVMValueRef Val,
1118 LLVMMetadataRef VarInfo,
1119 LLVMMetadataRef Expr,
1120 LLVMMetadataRef DebugLoc,
1121 LLVMBasicBlockRef Block) {
1122 return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
1123 unwrap(Val), unwrap(VarInfo),
1124 unwrap(Expr), unwrap(DebugLoc),
10591125 unwrap(Block)));
10601126 }
10611127
22 ; CHECK: ; ModuleID = 'debuginfo.c'
33 ; CHECK-NEXT: source_filename = "debuginfo.c"
44
5 ; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !9 {
5 ; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !12 {
66 ; CHECK-NEXT: entry:
7 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !16, metadata !DIExpression()), !dbg !19
8 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !17, metadata !DIExpression()), !dbg !19
9 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !18, metadata !DIExpression()), !dbg !19
7 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !19, metadata !DIExpression()), !dbg !24
8 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !20, metadata !DIExpression()), !dbg !24
9 ; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !21, metadata !DIExpression()), !dbg !24
10 ; CHECK: vars:
11 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !22, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !25
1012 ; CHECK-NEXT: }
1113
1214 ; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
13
14 ; CHECK: declare !dbg !20 i64 @foo_inner_scope(i64, i64, <10 x i64>)
15 ; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata) #0
1516
1617 ; CHECK: !llvm.dbg.cu = !{!0}
17 ; CHECK: !FooType = !{!3}
18 ; CHECK: !FooType = !{!8}
1819
19 ; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false)
20 ; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, splitDebugInlining: false)
2021 ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
2122 ; CHECK-NEXT: !2 = !{}
22 ; CHECK-NEXT: !3 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 192, dwarfAddressSpace: 0)
23 ; CHECK-NEXT: !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !5, file: !1, size: 192, elements: !7, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
24 ; CHECK-NEXT: !5 = !DINamespace(name: "NameSpace", scope: !6)
23 ; CHECK-NEXT: !3 = !{!4}
24 ; CHECK-NEXT: !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
25 ; CHECK-NEXT: !5 = distinct !DIGlobalVariable(name: "global", scope: !6, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true)
2526 ; CHECK-NEXT: !6 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h")
26 ; CHECK-NEXT: !7 = !{!8, !8, !8}
27 ; CHECK-NEXT: !8 = !DIBasicType(name: "Int64", size: 64)
28 ; CHECK-NEXT: !9 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !10, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !15)
29 ; CHECK-NEXT: !10 = !DISubroutineType(types: !11)
30 ; CHECK-NEXT: !11 = !{!8, !8, !12}
31 ; CHECK-NEXT: !12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 640, flags: DIFlagVector, elements: !13)
32 ; CHECK-NEXT: !13 = !{!14}
33 ; CHECK-NEXT: !14 = !DISubrange(count: 10)
34 ; CHECK-NEXT: !15 = !{!16, !17, !18}
35 ; CHECK-NEXT: !16 = !DILocalVariable(name: "a", arg: 1, scope: !9, file: !1, line: 42, type: !8)
36 ; CHECK-NEXT: !17 = !DILocalVariable(name: "b", arg: 2, scope: !9, file: !1, line: 42, type: !8)
37 ; CHECK-NEXT: !18 = !DILocalVariable(name: "c", arg: 3, scope: !9, file: !1, line: 42, type: !12)
38 ; CHECK-NEXT: !19 = !DILocation(line: 42, scope: !9)
39 ; CHECK-NEXT: !20 = distinct !DISubprogram(name: "foo_inner_scope", linkageName: "foo_inner_scope", scope: !21, file: !1, line: 42, type: !10, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !2)
40 ; CHECK-NEXT: !21 = distinct !DILexicalBlock(scope: !9, file: !1, line: 42)
27 ; CHECK-NEXT: !7 = !DIBasicType(name: "Int64", size: 64)
28 ; CHECK-NEXT: !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 192, dwarfAddressSpace: 0)
29 ; CHECK-NEXT: !9 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !10, file: !1, size: 192, elements: !11, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
30 ; CHECK-NEXT: !10 = !DINamespace(name: "NameSpace", scope: !6)
31 ; CHECK-NEXT: !11 = !{!7, !7, !7}
32 ; CHECK-NEXT: !12 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !13, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !18)
33 ; CHECK-NEXT: !13 = !DISubroutineType(types: !14)
34 ; CHECK-NEXT: !14 = !{!7, !7, !15}
35 ; CHECK-NEXT: !15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 640, flags: DIFlagVector, elements: !16)
36 ; CHECK-NEXT: !16 = !{!17}
37 ; CHECK-NEXT: !17 = !DISubrange(count: 10)
38 ; CHECK-NEXT: !18 = !{!19, !20, !21, !22}
39 ; CHECK-NEXT: !19 = !DILocalVariable(name: "a", arg: 1, scope: !12, file: !1, line: 42, type: !7)
40 ; CHECK-NEXT: !20 = !DILocalVariable(name: "b", arg: 2, scope: !12, file: !1, line: 42, type: !7)
41 ; CHECK-NEXT: !21 = !DILocalVariable(name: "c", arg: 3, scope: !12, file: !1, line: 42, type: !15)
42 ; CHECK-NEXT: !22 = !DILocalVariable(name: "d", scope: !23, file: !1, line: 43, type: !7)
43 ; CHECK-NEXT: !23 = distinct !DILexicalBlock(scope: !12, file: !1, line: 42)
44 ; CHECK-NEXT: !24 = !DILocation(line: 42, scope: !12)
45 ; CHECK-NEXT: !25 = !DILocation(line: 43, scope: !12)
3535 "/test/include/llvm-c-test.h", 27,
3636 "", 0);
3737
38 LLVMMetadataRef Int64Ty =
39 LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);
40 LLVMMetadataRef GlobalVarValueExpr =
41 LLVMDIBuilderCreateConstantValueExpression(DIB, 0);
42 LLVMDIBuilderCreateGlobalVariableExpression(DIB, Module, "global", 6,
43 "", 0, File, 1, Int64Ty,
44 true, GlobalVarValueExpr,
45 NULL, 0);
46
3847 LLVMMetadataRef NameSpace =
3948 LLVMDIBuilderCreateNameSpace(DIB, Module, "NameSpace", 9, false);
40
41 LLVMMetadataRef Int64Ty =
42 LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);
4349
4450 LLVMMetadataRef StructDbgElts[] = {Int64Ty, Int64Ty, Int64Ty};
4551 LLVMMetadataRef StructDbgTy =
108114 LLVMMetadataRef FooLexicalBlock =
109115 LLVMDIBuilderCreateLexicalBlock(DIB, FunctionMetadata, File, 42, 0);
110116
111 LLVMValueRef InnerFooFunction =
112 LLVMAddFunction(M, "foo_inner_scope", FooFuncTy);
113 LLVMMetadataRef InnerFunctionMetadata =
114 LLVMDIBuilderCreateFunction(DIB, FooLexicalBlock, "foo_inner_scope", 15,
115 "foo_inner_scope", 15,
116 File, 42, FunctionTy, true, true,
117 42, 0, false);
118 LLVMSetSubprogram(InnerFooFunction, InnerFunctionMetadata);
117 LLVMBasicBlockRef FooVarBlock = LLVMAppendBasicBlock(FooFunction, "vars");
118 LLVMMetadataRef FooVarsLocation =
119 LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 43, 0,
120 FunctionMetadata, NULL);
121 LLVMMetadataRef FooVar1 =
122 LLVMDIBuilderCreateAutoVariable(DIB, FooLexicalBlock, "d", 1, File,
123 43, Int64Ty, true, 0, 0);
124 LLVMValueRef FooVal1 = LLVMConstInt(LLVMInt64Type(), 0, false);
125 LLVMMetadataRef FooVarValueExpr =
126 LLVMDIBuilderCreateConstantValueExpression(DIB, 0);
127
128 LLVMDIBuilderInsertDbgValueAtEnd(DIB, FooVal1, FooVar1, FooVarValueExpr,
129 FooVarsLocation, FooVarBlock);
119130
120131 LLVMDIBuilderFinalize(DIB);
121132