From 7c5e617e90955043c3417048cb7ab1134ddd665c Mon Sep 17 00:00:00 2001 From: ychenfo Date: Thu, 14 Apr 2022 00:51:48 +0800 Subject: [PATCH] nac3core: add location debug info --- nac3core/src/codegen/mod.rs | 3 ++- nac3core/src/codegen/stmt.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/nac3core/src/codegen/mod.rs b/nac3core/src/codegen/mod.rs index 33cbe3db0..ef6d633ff 100644 --- a/nac3core/src/codegen/mod.rs +++ b/nac3core/src/codegen/mod.rs @@ -557,6 +557,7 @@ pub fn gen_func_impl< context.create_type_attribute(Attribute::get_named_enum_kind_id("sret"), ret_type.unwrap().as_any_type_enum())); } + { let ditype = debug_info_builder.dibuilder.create_basic_type( "_", @@ -572,7 +573,7 @@ pub fn gen_func_impl< ); let func_scope: DISubprogram<'_> = debug_info_builder.dibuilder.create_function( /* scope */ debug_info_builder.compile_unit.as_debug_info_scope(), - /* func name */ "main", + /* func name */ symbol, /* linkage_name */ None, /* file */ debug_info_builder.compile_unit.get_file(), /* line_no */ 0, diff --git a/nac3core/src/codegen/stmt.rs b/nac3core/src/codegen/stmt.rs index 9209440d1..5e51c11c5 100644 --- a/nac3core/src/codegen/stmt.rs +++ b/nac3core/src/codegen/stmt.rs @@ -12,6 +12,7 @@ use crate::{ use inkwell::{ attributes::{Attribute, AttributeLoc}, basic_block::BasicBlock, + debug_info::AsDIScope, types::BasicTypeEnum, values::{BasicValue, BasicValueEnum, FunctionValue, PointerValue}, IntPredicate::EQ, @@ -989,6 +990,24 @@ pub fn gen_stmt<'ctx, 'a, G: CodeGenerator>( stmt: &Stmt>, ) -> Result<(), String> { ctx.current_loc = stmt.location; + + let current_fn = ctx.builder.get_insert_block().unwrap().get_parent().unwrap(); + let lexical_block = ctx.debug_info_builder.dibuilder.create_lexical_block( + /* scope */ current_fn.get_subprogram().unwrap().as_debug_info_scope(), + /* file */ ctx.debug_info_builder.compile_unit.get_file(), + /* line_no */ ctx.current_loc.row as u32, + /* column_no */ ctx.current_loc.column as u32, + ); + + let loc = ctx.debug_info_builder.dibuilder.create_debug_location( + ctx.ctx, + /* line */ ctx.current_loc.row as u32, + /* column_no */ ctx.current_loc.column as u32, + /* current_scope */ lexical_block.as_debug_info_scope(), + /* inlined_at */ None + ); + ctx.builder.set_current_debug_location(ctx.ctx, loc); + match &stmt.node { StmtKind::Pass { .. } => {} StmtKind::Expr { value, .. } => {