authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-07 12:58:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-07 12:58:09-07:00
log049e9e581933921f2aaa1e60a8082c49fac236b2
treebdc84257f732f49e27ed5aceb795ab0b8dea96df
parent94ed9f622ad4c53a8a28b0e60697edfd409b314f

add debug info for loop variables

closes #112

1 files changed, 15 insertions(+), 8 deletions(-)

src/codegen.cpp+15-8
......@@ -2152,6 +2152,15 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) {
21522152 return nullptr;
21532153}
21542154
2155static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {
2156 BlockContext *block_context = var->block_context;
2157 AstNode *source_node = block_context->node;
2158 LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(source_node->line + 1, source_node->column + 1,
2159 block_context->di_scope);
2160 LLVMZigInsertDeclareAtEnd(g->dbuilder, var->value_ref, var->di_loc_var, debug_loc,
2161 LLVMGetInsertBlock(g->builder));
2162}
2163
21552164static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
21562165 assert(node->type == NodeTypeForExpr);
21572166 assert(node->data.for_expr.array_expr);
......@@ -2175,6 +2184,9 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
21752184 LLVMValueRef array_val = gen_array_base_ptr(g, node->data.for_expr.array_expr);
21762185 add_debug_source_node(g, node);
21772186 LLVMBuildStore(g->builder, LLVMConstNull(index_var->type->type_ref), index_ptr);
2187
2188 gen_var_debug_decl(g, index_var);
2189
21782190 LLVMValueRef len_val;
21792191 TypeTableEntry *child_type;
21802192 if (array_type->id == TypeTableEntryIdArray) {
......@@ -2203,6 +2215,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
22032215 LLVMValueRef elem_val = handle_is_ptr(child_type) ? elem_ptr : LLVMBuildLoad(g->builder, elem_ptr, "");
22042216 gen_assign_raw(g, node, BinOpTypeAssign, elem_var->value_ref, elem_val,
22052217 elem_var->type, child_type);
2218 gen_var_debug_decl(g, elem_var);
22062219 g->break_block_stack.append(end_block);
22072220 g->continue_block_stack.append(continue_block);
22082221 gen_expr(g, node->data.for_expr.body);
......@@ -2335,10 +2348,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
23352348 }
23362349 }
23372350
2338 LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(source_node->line + 1, source_node->column + 1,
2339 source_node->block_context->di_scope);
2340 LLVMZigInsertDeclareAtEnd(g->dbuilder, variable->value_ref, variable->di_loc_var, debug_loc,
2341 LLVMGetInsertBlock(g->builder));
2351 gen_var_debug_decl(g, variable);
23422352 return nullptr;
23432353}
23442354
......@@ -3107,10 +3117,7 @@ static void do_code_gen(CodeGen *g) {
31073117 VariableTableEntry *variable = param_decl->data.param_decl.variable;
31083118 assert(variable);
31093119
3110 LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(param_decl->line + 1, param_decl->column + 1,
3111 fn_def_node->data.fn_def.block_context->di_scope);
3112 LLVMZigInsertDeclareAtEnd(g->dbuilder, variable->value_ref, variable->di_loc_var, debug_loc,
3113 entry_block);
3120 gen_var_debug_decl(g, variable);
31143121 }
31153122
31163123 // allocate structs which are the result of casts