From c757f197903940115c1d42883240ec1fe7ef660c Mon Sep 17 00:00:00 2001 From: William Sengir Date: Sun, 13 Mar 2022 00:28:34 -0700 Subject: stage2: add debug info for globals in the LLVM backend LLVM backend: generate DIGlobalVariable's for non-function globals and rename linkage names when exporting functions and globals. zig_llvm.cpp: add some wrappers to convert a handful of DI classes into DINode's since DIGlobalVariable is not a DIScope like the others. zig_llvm.cpp: add some wrappers to allow replacing the LinkageName of DISubprogram and DIGlobalVariable. zig_llvm.cpp: fix DI class mixup causing nonsense reinterpret_cast. The end result is that GDB is now usable since you now no longer need to manually cast every global nor fully qualify every export. --- src/codegen/llvm/bindings.zig | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/codegen/llvm') diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig index 6afd754d37..c54d226f66 100644 --- a/src/codegen/llvm/bindings.zig +++ b/src/codegen/llvm/bindings.zig @@ -855,7 +855,17 @@ pub const Builder = opaque { extern fn LLVMBuildShuffleVector(*const Builder, V1: *const Value, V2: *const Value, Mask: *const Value, Name: [*:0]const u8) *const Value; }; -pub const DIScope = opaque {}; +pub const MDString = opaque { + pub const get = LLVMMDStringInContext2; + extern fn LLVMMDStringInContext2(C: *const Context, Str: [*]const u8, SLen: usize) *MDString; +}; + +pub const DIScope = opaque { + pub const toNode = ZigLLVMScopeToNode; + extern fn ZigLLVMScopeToNode(scope: *DIScope) *DINode; +}; + +pub const DINode = opaque {}; pub const Metadata = opaque {}; pub const IntPredicate = enum(c_uint) { @@ -1421,28 +1431,52 @@ pub const address_space = struct { pub const DIEnumerator = opaque {}; pub const DILocalVariable = opaque {}; -pub const DIGlobalVariable = opaque {}; pub const DILocation = opaque {}; +pub const DIGlobalVariable = opaque { + pub const toNode = ZigLLVMGlobalVariableToNode; + extern fn ZigLLVMGlobalVariableToNode(global_variable: *DIGlobalVariable) *DINode; + + pub const replaceLinkageName = ZigLLVMGlobalVariableReplaceLinkageName; + extern fn ZigLLVMGlobalVariableReplaceLinkageName(global_variable: *DIGlobalVariable, linkage_name: *MDString) void; +}; pub const DIType = opaque { pub const toScope = ZigLLVMTypeToScope; extern fn ZigLLVMTypeToScope(ty: *DIType) *DIScope; + + pub const toNode = ZigLLVMTypeToNode; + extern fn ZigLLVMTypeToNode(ty: *DIType) *DINode; }; pub const DIFile = opaque { pub const toScope = ZigLLVMFileToScope; extern fn ZigLLVMFileToScope(difile: *DIFile) *DIScope; + + pub const toNode = ZigLLVMFileToNode; + extern fn ZigLLVMFileToNode(difile: *DIFile) *DINode; }; pub const DILexicalBlock = opaque { pub const toScope = ZigLLVMLexicalBlockToScope; extern fn ZigLLVMLexicalBlockToScope(lexical_block: *DILexicalBlock) *DIScope; + + pub const toNode = ZigLLVMLexicalBlockToNode; + extern fn ZigLLVMLexicalBlockToNode(lexical_block: *DILexicalBlock) *DINode; }; pub const DICompileUnit = opaque { pub const toScope = ZigLLVMCompileUnitToScope; extern fn ZigLLVMCompileUnitToScope(compile_unit: *DICompileUnit) *DIScope; + + pub const toNode = ZigLLVMCompileUnitToNode; + extern fn ZigLLVMCompileUnitToNode(compile_unit: *DICompileUnit) *DINode; }; pub const DISubprogram = opaque { pub const toScope = ZigLLVMSubprogramToScope; extern fn ZigLLVMSubprogramToScope(subprogram: *DISubprogram) *DIScope; + + pub const toNode = ZigLLVMSubprogramToNode; + extern fn ZigLLVMSubprogramToNode(subprogram: *DISubprogram) *DINode; + + pub const replaceLinkageName = ZigLLVMSubprogramReplaceLinkageName; + extern fn ZigLLVMSubprogramReplaceLinkageName(subprogram: *DISubprogram, linkage_name: *MDString) void; }; pub const getDebugLoc = ZigLLVMGetDebugLoc; -- cgit v1.2.3