|
@@ -958,15 +958,15 @@ void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T
|
|
|
);
|
|
|
|
|
|
LLVMValueRef storage = ptr;
|
|
|
- LLVMValueRef instr = ptr;
|
|
|
+ LLVMBasicBlockRef block = p->decl_block->block;
|
|
|
LLVMMetadataRef llvm_debug_loc = lb_debug_location_from_token_pos(p, token.pos);
|
|
|
LLVMMetadataRef llvm_expr = LLVMDIBuilderCreateExpression(m->debug_builder, nullptr, 0);
|
|
|
lb_set_llvm_metadata(m, ptr, llvm_expr);
|
|
|
- LLVMDIBuilderInsertDeclareBefore(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, instr);
|
|
|
+ LLVMDIBuilderInsertDbgValueAtEnd(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, block);
|
|
|
}
|
|
|
|
|
|
|
|
|
-void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token, unsigned arg_number) {
|
|
|
+void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token, unsigned arg_number, lbBlock *block) {
|
|
|
if (p->debug_info == nullptr) {
|
|
|
return;
|
|
|
}
|
|
@@ -1020,19 +1020,14 @@ void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T
|
|
|
);
|
|
|
|
|
|
LLVMValueRef storage = ptr;
|
|
|
- LLVMValueRef instr = ptr;
|
|
|
- LLVMBasicBlockRef block = p->decl_block->block;
|
|
|
LLVMMetadataRef llvm_debug_loc = lb_debug_location_from_token_pos(p, token.pos);
|
|
|
LLVMMetadataRef llvm_expr = LLVMDIBuilderCreateExpression(m->debug_builder, nullptr, 0);
|
|
|
lb_set_llvm_metadata(m, ptr, llvm_expr);
|
|
|
- if (LLVMIsAAllocaInst(instr)) {
|
|
|
- LLVMDIBuilderInsertDeclareBefore(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, instr);
|
|
|
- } else {
|
|
|
- // NOTE(bill, 2022-02-01): For parameter values, you must insert them at the end of the decl block
|
|
|
- // The reason is that if the parameter is at index 0 and a pointer, there is not such things as an
|
|
|
- // instruction "before" it.
|
|
|
- LLVMDIBuilderInsertDeclareAtEnd(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, block);
|
|
|
- }
|
|
|
+
|
|
|
+ // NOTE(bill, 2022-02-01): For parameter values, you must insert them at the end of the decl block
|
|
|
+ // The reason is that if the parameter is at index 0 and a pointer, there is not such things as an
|
|
|
+ // instruction "before" it.
|
|
|
+ LLVMDIBuilderInsertDbgValueAtEnd(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, block->block);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1055,5 +1050,10 @@ void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) {
|
|
|
token.string = str_lit("context");
|
|
|
token.pos = pos;
|
|
|
|
|
|
- lb_add_debug_local_variable(p, ctx.addr.value, t_context, token);
|
|
|
+ LLVMValueRef ptr = ctx.addr.value;
|
|
|
+ while (LLVMIsABitCastInst(ptr)) {
|
|
|
+ ptr = LLVMGetOperand(ptr, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ lb_add_debug_local_variable(p, ptr, t_context, token);
|
|
|
}
|