authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-07 23:09:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-07 23:09:48-07:00
log113f0c9450398655717ea8bb5196a9df88f15000
tree0c7aeee019b61f7a95129e56debd5c0f4a55738f
parent9c9ea935191190471c1b2fd30c8cffde74421456

add local variables to debug info


3 files changed, 33 insertions(+), 4 deletions(-)

src/codegen.cpp+10-4
......@@ -528,7 +528,15 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) {
528528 return nullptr;
529529 } else {
530530 add_debug_source_node(g, node);
531 return LLVMBuildStore(g->builder, value, variable->value_ref);
531 variable->value_ref = LLVMBuildAlloca(g->builder,
532 variable->type->type_ref, buf_ptr(&variable->name));
533 LLVMValueRef store_instr = LLVMBuildStore(g->builder, value, variable->value_ref);
534
535 LLVMZigDILocation *debug_loc = LLVMZigGetDebugLoc(node->line + 1, node->column + 1,
536 g->cur_block_context->di_scope);
537 LLVMZigInsertDeclare(g->dbuilder, variable->value_ref, variable->di_loc_var,
538 debug_loc, store_instr);
539 return nullptr;
532540 }
533541 }
534542 case NodeTypeCastExpr:
......@@ -577,6 +585,7 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) {
577585 if (variable->type == g->builtin_types.entry_void) {
578586 return nullptr;
579587 } else if (variable->is_ptr) {
588 add_debug_source_node(g, node);
580589 return LLVMBuildLoad(g->builder, variable->value_ref, "");
581590 } else {
582591 return variable->value_ref;
......@@ -770,9 +779,6 @@ static void do_code_gen(CodeGen *g) {
770779 } else {
771780 tag = LLVMZigTag_DW_auto_variable();
772781 arg_no = 0;
773
774 add_debug_source_node(g, var->decl_node);
775 var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name));
776782 }
777783
778784 var->di_loc_var = LLVMZigCreateLocalVariable(g->dbuilder, tag,
src/zig_llvm.cpp+18
......@@ -304,6 +304,24 @@ void LLVMZigRestoreInsertPoint(LLVMBuilderRef builder, LLVMZigInsertionPoint *ip
304304 unwrap(builder)->restoreIP(*ip);
305305}
306306
307
308LLVMValueRef LLVMZigInsertDeclare(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage,
309 LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMValueRef insert_before_instr)
310{
311 Instruction *result = reinterpret_cast<DIBuilder*>(dibuilder)->insertDeclare(
312 unwrap(storage),
313 reinterpret_cast<DILocalVariable *>(var_info),
314 reinterpret_cast<DIBuilder*>(dibuilder)->createExpression(),
315 reinterpret_cast<DILocation*>(debug_loc),
316 static_cast<Instruction*>(unwrap(insert_before_instr)));
317 return wrap(result);
318}
319
320LLVMZigDILocation *LLVMZigGetDebugLoc(unsigned line, unsigned col, LLVMZigDIScope *scope) {
321 DebugLoc debug_loc = DebugLoc::get(line, col, reinterpret_cast<DIScope*>(scope), nullptr);
322 return reinterpret_cast<LLVMZigDILocation*>(debug_loc.get());
323}
324
307325//------------------------------------
308326
309327enum FloatAbi {
src/zig_llvm.hpp+5
......@@ -23,6 +23,7 @@ struct LLVMZigDILexicalBlock;
2323struct LLVMZigDISubprogram;
2424struct LLVMZigDISubroutineType;
2525struct LLVMZigDILocalVariable;
26struct LLVMZigDILocation;
2627struct LLVMZigInsertionPoint;
2728
2829void LLVMZigInitializeLoopStrengthReducePass(LLVMPassRegistryRef R);
......@@ -91,6 +92,10 @@ void LLVMZigDIBuilderFinalize(LLVMZigDIBuilder *dibuilder);
9192LLVMZigInsertionPoint *LLVMZigSaveInsertPoint(LLVMBuilderRef builder);
9293void LLVMZigRestoreInsertPoint(LLVMBuilderRef builder, LLVMZigInsertionPoint *point);
9394
95LLVMValueRef LLVMZigInsertDeclare(LLVMZigDIBuilder *dibuilder, LLVMValueRef storage,
96 LLVMZigDILocalVariable *var_info, LLVMZigDILocation *debug_loc, LLVMValueRef insert_before_instr);
97LLVMZigDILocation *LLVMZigGetDebugLoc(unsigned line, unsigned col, LLVMZigDIScope *scope);
98
9499
95100/*
96101 * This stuff is not LLVM API but it depends on the LLVM C++ API so we put it here.