mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-02 19:22:33 +00:00
Correct debug information logic for procedure parameters
This commit is contained in:
@@ -232,6 +232,7 @@ struct lbTargetList {
|
||||
|
||||
enum lbProcedureFlag : u32 {
|
||||
lbProcedureFlag_WithoutMemcpyPass = 1<<0,
|
||||
lbProcedureFlag_DebugAllocaCopy = 1<<1,
|
||||
};
|
||||
|
||||
struct lbCopyElisionHint {
|
||||
|
||||
@@ -965,6 +965,77 @@ void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T
|
||||
LLVMDIBuilderInsertDeclareBefore(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, instr);
|
||||
}
|
||||
|
||||
|
||||
void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token, unsigned arg_number) {
|
||||
if (p->debug_info == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (type == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (type == t_invalid) {
|
||||
return;
|
||||
}
|
||||
if (p->body == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
lbModule *m = p->module;
|
||||
String const &name = token.string;
|
||||
if (name == "" || name == "_") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (lb_get_llvm_metadata(m, ptr) != nullptr) {
|
||||
// Already been set
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
AstFile *file = p->body->file();
|
||||
|
||||
LLVMMetadataRef llvm_scope = lb_get_current_debug_scope(p);
|
||||
LLVMMetadataRef llvm_file = lb_get_llvm_metadata(m, file);
|
||||
GB_ASSERT(llvm_scope != nullptr);
|
||||
if (llvm_file == nullptr) {
|
||||
llvm_file = LLVMDIScopeGetFile(llvm_scope);
|
||||
}
|
||||
|
||||
if (llvm_file == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
LLVMDIFlags flags = LLVMDIFlagZero;
|
||||
LLVMBool always_preserve = build_context.optimization_level == 0;
|
||||
|
||||
LLVMMetadataRef debug_type = lb_debug_type(m, type);
|
||||
|
||||
LLVMMetadataRef var_info = LLVMDIBuilderCreateParameterVariable(
|
||||
m->debug_builder, llvm_scope,
|
||||
cast(char const *)name.text, cast(size_t)name.len,
|
||||
arg_number,
|
||||
llvm_file, token.pos.line,
|
||||
debug_type,
|
||||
always_preserve, flags
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) {
|
||||
if (!p->debug_info || !p->body) {
|
||||
return;
|
||||
|
||||
@@ -473,6 +473,8 @@ void lb_begin_procedure_body(lbProcedure *p) {
|
||||
}
|
||||
|
||||
lbArgType *arg_type = &ft->args[param_index];
|
||||
defer (param_index += 1);
|
||||
|
||||
if (arg_type->kind == lbArg_Ignore) {
|
||||
continue;
|
||||
} else if (arg_type->kind == lbArg_Direct) {
|
||||
@@ -487,20 +489,19 @@ void lb_begin_procedure_body(lbProcedure *p) {
|
||||
param.type = e->type;
|
||||
|
||||
lbValue ptr = lb_address_from_load_or_generate_local(p, param);
|
||||
GB_ASSERT(LLVMIsAAllocaInst(ptr.value));
|
||||
lb_add_entity(p->module, e, ptr);
|
||||
// lb_add_debug_local_variable(p, ptr.value, e->type, e->token);
|
||||
lb_add_debug_param_variable(p, ptr.value, e->type, e->token, param_index+1);
|
||||
}
|
||||
} else if (arg_type->kind == lbArg_Indirect) {
|
||||
if (e->token.string.len != 0 && !is_blank_ident(e->token.string)) {
|
||||
lbValue ptr = {};
|
||||
ptr.value = LLVMGetParam(p->value, param_offset+param_index);
|
||||
ptr.type = alloc_type_pointer(e->type);
|
||||
|
||||
lb_add_entity(p->module, e, ptr);
|
||||
// lb_add_debug_local_variable(p, ptr.value, e->type, e->token);
|
||||
lb_add_debug_param_variable(p, ptr.value, e->type, e->token, param_index+1);
|
||||
}
|
||||
}
|
||||
param_index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user