Index: llvm/trunk/bindings/go/llvm/DIBuilderBindings.h =================================================================== --- llvm/trunk/bindings/go/llvm/DIBuilderBindings.h +++ llvm/trunk/bindings/go/llvm/DIBuilderBindings.h @@ -28,22 +28,6 @@ typedef struct LLVMOpaqueDIBuilder *LLVMDIBuilderRef; -LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef D, - LLVMMetadataRef Scope, - LLVMMetadataRef File, - unsigned Line, unsigned Column); - -LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef D, - LLVMMetadataRef Scope, - LLVMMetadataRef File, - unsigned Discriminator); - -LLVMMetadataRef LLVMDIBuilderCreateFunction( - LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name, - const char *LinkageName, LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition, - unsigned ScopeLine, unsigned Flags, int IsOptimized); - LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( LLVMDIBuilderRef D, LLVMMetadataRef Scope, const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve, Index: llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp =================================================================== --- llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp +++ llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp @@ -19,39 +19,6 @@ using namespace llvm; -LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Dref, - LLVMMetadataRef Scope, - LLVMMetadataRef File, - unsigned Line, - unsigned Column) { - DIBuilder *D = unwrap(Dref); - auto *LB = D->createLexicalBlock(unwrap(Scope), - unwrap(File), Line, Column); - return wrap(LB); -} - -LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref, - LLVMMetadataRef Scope, - LLVMMetadataRef File, - unsigned Discriminator) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createLexicalBlockFile(unwrap(Scope), - unwrap(File), Discriminator)); -} - -LLVMMetadataRef LLVMDIBuilderCreateFunction( - LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, - const char *LinkageName, LLVMMetadataRef File, unsigned Line, - LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition, - unsigned ScopeLine, unsigned Flags, int IsOptimized) { - DIBuilder *D = unwrap(Dref); - return wrap(D->createFunction( - unwrap(Scope), Name, LinkageName, - File ? unwrap(File) : nullptr, Line, - unwrap(CompositeType), IsLocalToUnit, IsDefinition, - ScopeLine, static_cast(Flags), IsOptimized)); -} - LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve, Index: llvm/trunk/bindings/go/llvm/IRBindings.h =================================================================== --- llvm/trunk/bindings/go/llvm/IRBindings.h +++ llvm/trunk/bindings/go/llvm/IRBindings.h @@ -53,8 +53,6 @@ struct LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref); -void LLVMSetSubprogram(LLVMValueRef Fn, LLVMMetadataRef SP); - #ifdef __cplusplus } Index: llvm/trunk/bindings/go/llvm/IRBindings.cpp =================================================================== --- llvm/trunk/bindings/go/llvm/IRBindings.cpp +++ llvm/trunk/bindings/go/llvm/IRBindings.cpp @@ -84,6 +84,3 @@ return md; } -void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) { - unwrap(Func)->setSubprogram(unwrap(SP)); -} Index: llvm/trunk/bindings/go/llvm/dibuilder.go =================================================================== --- llvm/trunk/bindings/go/llvm/dibuilder.go +++ llvm/trunk/bindings/go/llvm/dibuilder.go @@ -207,16 +207,16 @@ result := C.LLVMDIBuilderCreateFunction( d.ref, diScope.C, - name, - linkageName, + name, C.size_t(len(f.Name)), + linkageName, C.size_t(len(f.LinkageName)), f.File.C, C.unsigned(f.Line), f.Type.C, - boolToCInt(f.LocalToUnit), - boolToCInt(f.IsDefinition), + C.LLVMBool(boolToCInt(f.LocalToUnit)), + C.LLVMBool(boolToCInt(f.IsDefinition)), C.unsigned(f.ScopeLine), - C.unsigned(f.Flags), - boolToCInt(f.Optimized), + C.LLVMDIFlags(f.Flags), + C.LLVMBool(boolToCInt(f.Optimized)), ) return Metadata{C: result} } @@ -390,7 +390,7 @@ C.unsigned(0), // Optional Objective-C runtime version. t.VTableHolder.C, uniqueID, - C.uint64_t(len(t.UniqueID)), + C.size_t(len(t.UniqueID)), ) return Metadata{C: result} } Index: llvm/trunk/include/llvm-c/DebugInfo.h =================================================================== --- llvm/trunk/include/llvm-c/DebugInfo.h +++ llvm/trunk/include/llvm-c/DebugInfo.h @@ -218,6 +218,56 @@ size_t DirectoryLen); /** + * Create a new descriptor for the specified subprogram. + * \param Builder The \c DIBuilder. + * \param Scope Function scope. + * \param Name Function name. + * \param NameLen Length of enumeration name. + * \param LinkageName Mangled function name. + * \param LinkageNameLen Length of linkage name. + * \param File File where this variable is defined. + * \param LineNo Line number. + * \param Ty Function type. + * \param IsLocalToUnit True if this function is not externally visible. + * \param IsDefinition True if this is a function definition. + * \param ScopeLine Set to the beginning of the scope this starts + * \param Flags E.g.: \c LLVMDIFlagLValueReference. These flags are + * used to emit dwarf attributes. + * \param IsOptimized True if optimization is ON. + */ +LLVMMetadataRef LLVMDIBuilderCreateFunction( + LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + size_t NameLen, const char *LinkageName, size_t LinkageNameLen, + LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, + LLVMBool IsLocalToUnit, LLVMBool IsDefinition, + unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized); + +/** + * Create a descriptor for a lexical block with the specified parent context. + * \param Builder The \c DIBuilder. + * \param Scope Parent lexical block. + * \param File Source file. + * \param Line The line in the source file. + * \param Column The column in the source file. + */ +LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock( + LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, + LLVMMetadataRef File, unsigned Line, unsigned Column); + +/** + * Create a descriptor for a lexical block with a new file attached. + * \param Builder The \c DIBuilder. + * \param Scope Lexical block. + * \param File Source file. + * \param Discriminator DWARF path discriminator value. + */ +LLVMMetadataRef +LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, + LLVMMetadataRef Scope, + LLVMMetadataRef File, + unsigned Discriminator); + +/** * Creates a new DebugLocation that describes a source location. * \param Line The line in the source file. * \param Column The column in the source file. @@ -560,6 +610,20 @@ LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type); +/** + * Get the metadata of the subprogram attached to a function. + * + * @see llvm::Function::getSubprogram() + */ +LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func); + +/** + * Set the subprogram attached to a function. + * + * @see llvm::Function::setSubprogram() + */ +void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP); + #ifdef __cplusplus } /* end extern "C" */ #endif Index: llvm/trunk/lib/IR/DebugInfo.cpp =================================================================== --- llvm/trunk/lib/IR/DebugInfo.cpp +++ llvm/trunk/lib/IR/DebugInfo.cpp @@ -754,6 +754,38 @@ StringRef(Directory, DirectoryLen))); } +LLVMMetadataRef LLVMDIBuilderCreateFunction( + LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + size_t NameLen, const char *LinkageName, size_t LinkageNameLen, + LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, + LLVMBool IsLocalToUnit, LLVMBool IsDefinition, + unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) { + return wrap(unwrap(Builder)->createFunction( + unwrapDI(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen}, + unwrapDI(File), LineNo, unwrapDI(Ty), + IsLocalToUnit, IsDefinition, ScopeLine, map_from_llvmDIFlags(Flags), + IsOptimized, nullptr, nullptr, nullptr)); +} + + +LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock( + LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, + LLVMMetadataRef File, unsigned Line, unsigned Col) { + return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI(Scope), + unwrapDI(File), + Line, Col)); +} + +LLVMMetadataRef +LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, + LLVMMetadataRef Scope, + LLVMMetadataRef File, + unsigned Discriminator) { + return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI(Scope), + unwrapDI(File), + Discriminator)); +} + LLVMMetadataRef LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, unsigned Column, LLVMMetadataRef Scope, @@ -942,3 +974,11 @@ return wrap(unwrap(Builder)->createSubroutineType( Elts, map_from_llvmDIFlags(Flags))); } + +LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func) { + return wrap(unwrap(Func)->getSubprogram()); +} + +void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) { + unwrap(Func)->setSubprogram(unwrap(SP)); +} Index: llvm/trunk/test/Bindings/llvm-c/debug_info.ll =================================================================== --- llvm/trunk/test/Bindings/llvm-c/debug_info.ll +++ llvm/trunk/test/Bindings/llvm-c/debug_info.ll @@ -3,12 +3,22 @@ ; CHECK: ; ModuleID = 'debuginfo.c' ; CHECK-NEXT: source_filename = "debuginfo.c" +; CHECK: declare !dbg !7 i64 @foo(i64, i64) + +; CHECK: declare !dbg !10 i64 @foo_inner_scope(i64, i64) + ; CHECK: !llvm.dbg.cu = !{!0} -; CHECK-NEXT: !FooType = !{!2} +; CHECK-NEXT: !FooType = !{!3} -; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false) +; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false) ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".") -; CHECK-NEXT: !2 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !3, size: 192, dwarfAddressSpace: 0) -; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", file: !1, size: 192, elements: !4, runtimeLang: DW_LANG_C89, identifier: "MyStruct") -; CHECK-NEXT: !4 = !{!5, !5, !5} -; CHECK-NEXT: !5 = !DIBasicType(name: "Int64", size: 64) \ No newline at end of file +; CHECK-NEXT: !2 = !{} +; CHECK-NEXT: !3 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 192, dwarfAddressSpace: 0) +; CHECK-NEXT: !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", file: !1, size: 192, elements: !5, runtimeLang: DW_LANG_C89, identifier: "MyStruct") +; CHECK-NEXT: !5 = !{!6, !6, !6} +; CHECK-NEXT: !6 = !DIBasicType(name: "Int64", size: 64) +; CHECK-NEXT: !7 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !8, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !2) +; CHECK-NEXT: !8 = !DISubroutineType(types: !9) +; CHECK-NEXT: !9 = !{!6, !6} +; CHECK-NEXT: !10 = distinct !DISubprogram(name: "foo_inner_scope", linkageName: "foo_inner_scope", scope: !11, file: !1, line: 42, type: !8, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !2) +; CHECK-NEXT: !11 = distinct !DILexicalBlock(scope: !7, file: !1, line: 42) Index: llvm/trunk/tools/llvm-c-test/debuginfo.c =================================================================== --- llvm/trunk/tools/llvm-c-test/debuginfo.c +++ llvm/trunk/tools/llvm-c-test/debuginfo.c @@ -44,6 +44,34 @@ LLVMAddNamedMetadataOperand(M, "FooType", LLVMMetadataAsValue(LLVMGetModuleContext(M), StructDbgPtrTy)); + + LLVMTypeRef FooParamTys[] = { LLVMInt64Type(), LLVMInt64Type() }; + LLVMTypeRef FooFuncTy = LLVMFunctionType(LLVMInt64Type(), FooParamTys, 2, 0); + LLVMValueRef FooFunction = LLVMAddFunction(M, "foo", FooFuncTy); + + LLVMMetadataRef ParamTypes[] = {Int64Ty, Int64Ty}; + LLVMMetadataRef FunctionTy = + LLVMDIBuilderCreateSubroutineType(DIB, File, ParamTypes, 2, 0); + LLVMMetadataRef FunctionMetadata = + LLVMDIBuilderCreateFunction(DIB, File, "foo", 3, "foo", 3, + File, 42, FunctionTy, true, true, + 42, 0, false); + LLVMSetSubprogram(FooFunction, FunctionMetadata); + + LLVMMetadataRef FooLexicalBlock = + LLVMDIBuilderCreateLexicalBlock(DIB, FunctionMetadata, File, 42, 0); + + LLVMValueRef InnerFooFunction = + LLVMAddFunction(M, "foo_inner_scope", FooFuncTy); + LLVMMetadataRef InnerFunctionMetadata = + LLVMDIBuilderCreateFunction(DIB, FooLexicalBlock, "foo_inner_scope", 15, + "foo_inner_scope", 15, + File, 42, FunctionTy, true, true, + 42, 0, false); + LLVMSetSubprogram(InnerFooFunction, InnerFunctionMetadata); + + LLVMDIBuilderFinalize(DIB); + char *MStr = LLVMPrintModuleToString(M); puts(MStr); LLVMDisposeMessage(MStr);