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) {...@@ -2152,6 +2152,15 @@ static LLVMValueRef gen_while_expr(CodeGen *g, AstNode *node) {
2152 return nullptr;2152 return nullptr;
2153}2153}
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
2155static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {2164static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
2156 assert(node->type == NodeTypeForExpr);2165 assert(node->type == NodeTypeForExpr);
2157 assert(node->data.for_expr.array_expr);2166 assert(node->data.for_expr.array_expr);
...@@ -2175,6 +2184,9 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {...@@ -2175,6 +2184,9 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
2175 LLVMValueRef array_val = gen_array_base_ptr(g, node->data.for_expr.array_expr);2184 LLVMValueRef array_val = gen_array_base_ptr(g, node->data.for_expr.array_expr);
2176 add_debug_source_node(g, node);2185 add_debug_source_node(g, node);
2177 LLVMBuildStore(g->builder, LLVMConstNull(index_var->type->type_ref), index_ptr);2186 LLVMBuildStore(g->builder, LLVMConstNull(index_var->type->type_ref), index_ptr);
2187
2188 gen_var_debug_decl(g, index_var);
2189
2178 LLVMValueRef len_val;2190 LLVMValueRef len_val;
2179 TypeTableEntry *child_type;2191 TypeTableEntry *child_type;
2180 if (array_type->id == TypeTableEntryIdArray) {2192 if (array_type->id == TypeTableEntryIdArray) {
...@@ -2203,6 +2215,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {...@@ -2203,6 +2215,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
2203 LLVMValueRef elem_val = handle_is_ptr(child_type) ? elem_ptr : LLVMBuildLoad(g->builder, elem_ptr, "");2215 LLVMValueRef elem_val = handle_is_ptr(child_type) ? elem_ptr : LLVMBuildLoad(g->builder, elem_ptr, "");
2204 gen_assign_raw(g, node, BinOpTypeAssign, elem_var->value_ref, elem_val,2216 gen_assign_raw(g, node, BinOpTypeAssign, elem_var->value_ref, elem_val,
2205 elem_var->type, child_type);2217 elem_var->type, child_type);
2218 gen_var_debug_decl(g, elem_var);
2206 g->break_block_stack.append(end_block);2219 g->break_block_stack.append(end_block);
2207 g->continue_block_stack.append(continue_block);2220 g->continue_block_stack.append(continue_block);
2208 gen_expr(g, node->data.for_expr.body);2221 gen_expr(g, node->data.for_expr.body);
...@@ -2335,10 +2348,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa...@@ -2335,10 +2348,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
2335 }2348 }
2336 }2349 }
23372350
2338 LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(source_node->line + 1, source_node->column + 1,2351 gen_var_debug_decl(g, variable);
2339 source_node->block_context->di_scope);
2340 LLVMZigInsertDeclareAtEnd(g->dbuilder, variable->value_ref, variable->di_loc_var, debug_loc,
2341 LLVMGetInsertBlock(g->builder));
2342 return nullptr;2352 return nullptr;
2343}2353}
23442354
...@@ -3107,10 +3117,7 @@ static void do_code_gen(CodeGen *g) {...@@ -3107,10 +3117,7 @@ static void do_code_gen(CodeGen *g) {
3107 VariableTableEntry *variable = param_decl->data.param_decl.variable;3117 VariableTableEntry *variable = param_decl->data.param_decl.variable;
3108 assert(variable);3118 assert(variable);
31093119
3110 LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(param_decl->line + 1, param_decl->column + 1,3120 gen_var_debug_decl(g, variable);
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);
3114 }3121 }
31153122
3116 // allocate structs which are the result of casts3123 // allocate structs which are the result of casts