authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-08 12:48:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-08 14:58:53-07:00
log7cea8f063f710d5fb2fb10723c3e6485b3e2b31d
treef2bbec48794e0bb6b66cef27cd4eb6d4dbafad6c
parentba566eed76bbfd57c6f4b410435067f3a6d7fd5d

LLVM: add debug info for parameters


1 files changed, 24 insertions(+), 7 deletions(-)

src/codegen/llvm.zig+24-7
...@@ -5117,31 +5117,48 @@ pub const FuncGen = struct {...@@ -5117,31 +5117,48 @@ pub const FuncGen = struct {
5117 self.arg_index += 1;5117 self.arg_index += 1;
51185118
5119 const inst_ty = self.air.typeOfIndex(inst);5119 const inst_ty = self.air.typeOfIndex(inst);
5120 const result = r: {5120 const result: struct { ptr: *const llvm.Value, operand: *const llvm.Value } = r: {
5121 if (isByRef(inst_ty)) {5121 if (isByRef(inst_ty)) {
5122 break :r arg_val;5122 break :r .{ .ptr = arg_val, .operand = arg_val };
5123 } else {5123 } else {
5124 const ptr_val = self.buildAlloca(try self.dg.llvmType(inst_ty));5124 const ptr_val = self.buildAlloca(try self.dg.llvmType(inst_ty));
5125 _ = self.builder.buildStore(arg_val, ptr_val);5125 _ = self.builder.buildStore(arg_val, ptr_val);
5126 break :r arg_val;5126 break :r .{ .ptr = ptr_val, .operand = arg_val };
5127 }5127 }
5128 };5128 };
51295129
5130 if (self.dg.object.di_builder) |dib| {5130 if (self.dg.object.di_builder) |dib| {
5131 const src_index = self.getSrcArgIndex(self.arg_index - 1);
5131 const func = self.dg.decl.getFunction().?;5132 const func = self.dg.decl.getFunction().?;
5132 _ = dib.createParameterVariable(5133 const lbrace_line = func.owner_decl.src_line + func.lbrace_line + 1;
5134 const lbrace_col = func.lbrace_column + 1;
5135 const di_local_var = dib.createParameterVariable(
5133 self.di_scope.?,5136 self.di_scope.?,
5134 func.getParamName(self.arg_index - 1).ptr, // TODO test 0 bit args5137 func.getParamName(src_index).ptr, // TODO test 0 bit args
5135 self.di_file.?,5138 self.di_file.?,
5136 func.owner_decl.src_line + func.lbrace_line + 1,5139 lbrace_line,
5137 try self.dg.lowerDebugType(inst_ty),5140 try self.dg.lowerDebugType(inst_ty),
5138 true, // always preserve5141 true, // always preserve
5139 0, // flags5142 0, // flags
5140 self.arg_index, // includes +1 because 0 is return type5143 self.arg_index, // includes +1 because 0 is return type
5141 );5144 );
5145
5146 const debug_loc = llvm.getDebugLoc(lbrace_line, lbrace_col, self.di_scope.?);
5147 const insert_block = self.builder.getInsertBlock();
5148 _ = dib.insertDeclareAtEnd(result.ptr, di_local_var, debug_loc, insert_block);
5142 }5149 }
51435150
5144 return result;5151 return result.operand;
5152 }
5153
5154 fn getSrcArgIndex(self: *FuncGen, runtime_index: u32) u32 {
5155 const fn_info = self.dg.decl.ty.fnInfo();
5156 var i: u32 = 0;
5157 for (fn_info.param_types) |param_ty, src_index| {
5158 if (!param_ty.hasRuntimeBits()) continue;
5159 if (i == runtime_index) return @intCast(u32, src_index);
5160 i += 1;
5161 } else unreachable;
5145 }5162 }
51465163
5147 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {5164 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {