[PATCH] D72206: [bindings/go] Implement API for adding debug info to global variables
Ayke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 4 09:46:33 PST 2020
aykevl created this revision.
aykevl added reviewers: whitequark, pcc.
Herald added a reviewer: deadalnix.
Herald added subscribers: hiraditya, aprantl.
Herald added a project: LLVM.
I implemented what seems like the most generic API possible. For example, there is also `GlobalVariable->addDebugInfo` but that is basically just a helper for `GlobalObject->addMetadata`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72206
Files:
llvm/bindings/go/llvm/dibuilder.go
llvm/include/llvm-c/Core.h
llvm/lib/IR/Core.cpp
Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ llvm/lib/IR/Core.cpp
@@ -888,6 +888,12 @@
unwrap<Instruction>(Inst)->setMetadata(KindID, N);
}
+void LLVMGlobalObjectAddMetadata(LLVMValueRef Global, unsigned KindID, LLVMMetadataRef MD) {
+ MDNode *N = MD ? unwrap<MDNode>(MD) : nullptr;
+ GlobalObject *O = unwrap<GlobalObject>(Global);
+ O->addMetadata(KindID, *N);
+}
+
struct LLVMOpaqueValueMetadataEntry {
unsigned Kind;
LLVMMetadataRef Metadata;
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -3064,6 +3064,11 @@
*/
void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
+/**
+ * Add metadata to a global object.
+ */
+void LLVMGlobalObjectAddMetadata(LLVMValueRef Global, unsigned KindID, LLVMMetadataRef MD);
+
/**
* Returns the metadata associated with an instruction value, but filters out
* all the debug locations.
Index: llvm/bindings/go/llvm/dibuilder.go
===================================================================
--- llvm/bindings/go/llvm/dibuilder.go
+++ llvm/bindings/go/llvm/dibuilder.go
@@ -221,6 +221,43 @@
return Metadata{C: result}
}
+// DIGlobalVariableExpression holds the values for creating global variable
+// debug metadata.
+type DIGlobalVariableExpression struct {
+ Name string // Name of the variable.
+ LinkageName string // Mangled name of the variable
+ File Metadata // File where this variable is defined.
+ Line int // Line number.
+ Type Metadata // Variable Type.
+ LocalToUnit bool // Flag indicating whether this variable is externally visible or not.
+ Expr Metadata // The location of the global relative to the attached GlobalVariable.
+ Decl Metadata // Reference to the corresponding declaration.
+ AlignInBits uint32 // Variable alignment(or 0 if no alignment attr was specified).
+}
+
+// CreateGlobalVariableExpression creates a new descriptor for the specified
+// global variable.
+func (d *DIBuilder) CreateGlobalVariableExpression(diScope Metadata, g DIGlobalVariableExpression) Metadata {
+ name := C.CString(g.Name)
+ defer C.free(unsafe.Pointer(name))
+ linkageName := C.CString(g.LinkageName)
+ defer C.free(unsafe.Pointer(linkageName))
+ result := C.LLVMDIBuilderCreateGlobalVariableExpression(
+ d.ref, // Builder
+ diScope.C, // Scope
+ name, C.size_t(len(g.Name)), // Name, NameLen
+ linkageName, C.size_t(len(g.LinkageName)), // Linkage, LinkLen
+ g.File.C, // File
+ C.unsigned(g.Line), // LineNo
+ g.Type.C, // Ty
+ C.LLVMBool(boolToCInt(g.LocalToUnit)), // LocalToUnit
+ g.Expr.C, // Expr
+ g.Decl.C, // Decl
+ C.uint32_t(g.AlignInBits), // AlignInBits
+ )
+ return Metadata{C: result}
+}
+
// DIAutoVariable holds the values for creating auto variable debug metadata.
type DIAutoVariable struct {
Name string
@@ -590,6 +627,11 @@
return
}
+// AddMetadata adds a metadata entry of the given kind to a global object.
+func (v Value) AddMetadata(kind int, md Metadata) {
+ C.LLVMGlobalObjectAddMetadata(v.C, C.unsigned(kind), md.C)
+}
+
func boolToCInt(v bool) C.int {
if v {
return 1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72206.236184.patch
Type: text/x-patch
Size: 3485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200104/96c13bee/attachment-0001.bin>
More information about the llvm-commits
mailing list