From 6c7e5748a8ee80b01b99fe41192d4aac32651849 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 18 Jul 2022 12:49:29 +0100 Subject: Integrate numerous debug fixes from #1877 --- src/llvm_backend_debug.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/llvm_backend_debug.cpp') diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 45a868581..207164c63 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -969,7 +969,7 @@ void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T ); LLVMValueRef storage = ptr; - LLVMBasicBlockRef block = p->decl_block->block; + LLVMBasicBlockRef block = p->curr_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); -- cgit v1.2.3 From fb167d1d0aa5b428dc1f477e8879d68664d155d9 Mon Sep 17 00:00:00 2001 From: Fabian Sperber Date: Mon, 11 Jul 2022 21:03:46 +0200 Subject: Fix loop var (init) becoming hidden while stepping on the for-line - set debug location of jumps between block (similar to clang to the location of 'for') - extend scope range to include all parts of the for-stmt --- src/llvm_backend_debug.cpp | 4 ++++ src/llvm_backend_stmt.cpp | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/llvm_backend_debug.cpp') diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 207164c63..29e074473 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -43,6 +43,10 @@ LLVMMetadataRef lb_debug_location_from_ast(lbProcedure *p, Ast *node) { GB_ASSERT(node != nullptr); return lb_debug_location_from_token_pos(p, ast_token(node).pos); } +LLVMMetadataRef lb_debug_end_location_from_ast(lbProcedure *p, Ast *node) { + GB_ASSERT(node != nullptr); + return lb_debug_location_from_token_pos(p, ast_end_token(node).pos); +} LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) { i64 size = type_size_of(type); // Check size diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index d007ac747..d2b9ac555 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -1744,11 +1744,14 @@ void lb_build_for_stmt(lbProcedure *p, Ast *node) { post = lb_create_block(p, "for.post"); } - lb_emit_jump(p, loop); lb_start_block(p, loop); if (loop != body) { + // right now the condition (all expressions) will not set it's debug location, so we will do it here + if (p->debug_info != nullptr) { + LLVMSetCurrentDebugLocation2(p->builder, lb_debug_location_from_ast(p, fs->cond)); + } lb_build_cond(p, fs->cond, body, done); lb_start_block(p, body); } @@ -1756,10 +1759,12 @@ void lb_build_for_stmt(lbProcedure *p, Ast *node) { lb_push_target_list(p, fs->label, done, post, nullptr); lb_build_stmt(p, fs->body); - lb_close_scope(p, lbDeferExit_Default, nullptr); lb_pop_target_list(p); + if (p->debug_info != nullptr) { + LLVMSetCurrentDebugLocation2(p->builder, lb_debug_end_location_from_ast(p, fs->body)); + } lb_emit_jump(p, post); if (fs->post != nullptr) { @@ -1769,6 +1774,7 @@ void lb_build_for_stmt(lbProcedure *p, Ast *node) { } lb_start_block(p, done); + lb_close_scope(p, lbDeferExit_Default, nullptr); } void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs, lbValue const &value) { -- cgit v1.2.3