Implement source debugging for interpreter and AOT (#769)
Implement source debugging feature for classic interpreter and AOT: - use `cmake -DWAMR_BUILD_DEBUG_INTERP=1` to enable interpreter debugging - use `cmake -DWAMR_BUILD_DEBUG_AOT=1` to enable AOT debugging See doc/source_debugging.md for more details.
This commit is contained in:
@ -8,6 +8,10 @@
|
||||
#include "../aot/aot_runtime.h"
|
||||
#include "../interpreter/wasm_loader.h"
|
||||
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
#include "debug/dwarf_extractor.h"
|
||||
#endif
|
||||
|
||||
static char *block_name_prefix[] = { "block", "loop", "if" };
|
||||
static char *block_name_suffix[] = { "begin", "else", "end" };
|
||||
|
||||
@ -158,14 +162,22 @@ handle_next_reachable_block(AOTCompContext *comp_ctx,
|
||||
uint8 *frame_ip = NULL;
|
||||
uint32 i;
|
||||
AOTFuncType *func_type;
|
||||
LLVMValueRef ret;
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
LLVMMetadataRef return_location;
|
||||
#endif
|
||||
|
||||
aot_checked_addr_list_destroy(func_ctx);
|
||||
|
||||
bh_assert(block);
|
||||
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
return_location = dwarf_gen_location(
|
||||
comp_ctx, func_ctx,
|
||||
(*p_frame_ip - 1) - comp_ctx->comp_data->wasm_module->buf_code
|
||||
);
|
||||
#endif
|
||||
if (block->label_type == LABEL_TYPE_IF
|
||||
&& block->llvm_else_block
|
||||
&& !block->skip_wasm_code_else
|
||||
&& *p_frame_ip <= block->wasm_code_else) {
|
||||
/* Clear value stack and start to translate else branch */
|
||||
aot_value_stack_destroy(&block->value_stack);
|
||||
@ -237,16 +249,23 @@ handle_next_reachable_block(AOTCompContext *comp_ctx,
|
||||
if (block->label_type == LABEL_TYPE_FUNCTION) {
|
||||
if (block->result_count) {
|
||||
/* Return the first return value */
|
||||
if (!LLVMBuildRet(comp_ctx->builder, block->result_phis[0])) {
|
||||
if (!(ret =
|
||||
LLVMBuildRet(comp_ctx->builder, block->result_phis[0]))) {
|
||||
aot_set_last_error("llvm build return failed.");
|
||||
goto fail;
|
||||
}
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
LLVMInstructionSetDebugLoc(ret, return_location);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
if (!LLVMBuildRetVoid(comp_ctx->builder)) {
|
||||
if (!(ret = LLVMBuildRetVoid(comp_ctx->builder))) {
|
||||
aot_set_last_error("llvm build return void failed.");
|
||||
goto fail;
|
||||
}
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
LLVMInstructionSetDebugLoc(ret, return_location);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
aot_block_destroy(block);
|
||||
@ -381,7 +400,7 @@ aot_compile_op_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
memset(block_addr_cache, 0, sizeof(block_addr_cache));
|
||||
|
||||
/* Get block info */
|
||||
if (!(wasm_loader_find_block_addr((BlockAddr*)block_addr_cache,
|
||||
if (!(wasm_loader_find_block_addr(NULL, (BlockAddr*)block_addr_cache,
|
||||
*p_frame_ip, frame_ip_end, (uint8)label_type,
|
||||
&else_addr, &end_addr))) {
|
||||
aot_set_last_error("find block end addr failed.");
|
||||
@ -709,7 +728,7 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||
|
||||
/* Move builder to terminate block */
|
||||
SET_BUILDER_POS(terminate_block);
|
||||
if (!aot_build_zero_function_ret(comp_ctx, aot_func_type)) {
|
||||
if (!aot_build_zero_function_ret(comp_ctx, func_ctx, aot_func_type)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -1070,12 +1089,22 @@ aot_compile_op_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
{
|
||||
AOTBlock *block_func = func_ctx->block_stack.block_list_head;
|
||||
LLVMValueRef value;
|
||||
LLVMValueRef ret;
|
||||
AOTFuncType *func_type;
|
||||
uint32 i, param_index, result_index;
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
LLVMMetadataRef return_location;
|
||||
#endif
|
||||
|
||||
bh_assert(block_func);
|
||||
func_type = func_ctx->aot_func->func_type;
|
||||
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
return_location = dwarf_gen_location(
|
||||
comp_ctx, func_ctx,
|
||||
(*p_frame_ip - 1) - comp_ctx->comp_data->wasm_module->buf_code
|
||||
);
|
||||
#endif
|
||||
if (block_func->result_count) {
|
||||
/* Store extra result values to function parameters */
|
||||
for (i = 0; i < block_func->result_count - 1; i++) {
|
||||
@ -1091,16 +1120,22 @@ aot_compile_op_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
}
|
||||
/* Return the first result value */
|
||||
POP(value, block_func->result_types[0]);
|
||||
if (!LLVMBuildRet(comp_ctx->builder, value)) {
|
||||
if (!(ret = LLVMBuildRet(comp_ctx->builder, value))) {
|
||||
aot_set_last_error("llvm build return failed.");
|
||||
goto fail;
|
||||
}
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
LLVMInstructionSetDebugLoc(ret, return_location);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
if (!LLVMBuildRetVoid(comp_ctx->builder)) {
|
||||
if (!(ret = LLVMBuildRetVoid(comp_ctx->builder))) {
|
||||
aot_set_last_error("llvm build return void failed.");
|
||||
goto fail;
|
||||
}
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
LLVMInstructionSetDebugLoc(ret, return_location);
|
||||
#endif
|
||||
}
|
||||
|
||||
return handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip);
|
||||
|
||||
Reference in New Issue
Block a user