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:
@ -9,6 +9,10 @@
|
||||
#include "../aot/aot_runtime.h"
|
||||
#include "../aot/aot_intrinsic.h"
|
||||
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
#include "debug/dwarf_extractor.h"
|
||||
#endif
|
||||
|
||||
LLVMTypeRef
|
||||
wasm_type_to_llvm_type(AOTLLVMTypes *llvm_types, uint8 wasm_type)
|
||||
{
|
||||
@ -634,6 +638,10 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
|
||||
func, aot_func_type)))
|
||||
goto fail;
|
||||
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
func_ctx->debug_func = dwarf_gen_func_info(comp_ctx, func_ctx);
|
||||
#endif
|
||||
|
||||
aot_block_stack_push(&func_ctx->block_stack, aot_block);
|
||||
|
||||
/* Add local variables */
|
||||
@ -1462,6 +1470,29 @@ aot_create_comp_context(AOTCompData *comp_data,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
if (!(comp_ctx->debug_builder = LLVMCreateDIBuilder(comp_ctx->module))) {
|
||||
aot_set_last_error("create LLVM Debug Infor builder failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
LLVMAddModuleFlag(
|
||||
comp_ctx->module, LLVMModuleFlagBehaviorWarning, "Debug Info Version",
|
||||
strlen("Debug Info Version"),
|
||||
LLVMValueAsMetadata(LLVMConstInt(LLVMInt32Type(), 3, false)));
|
||||
|
||||
comp_ctx->debug_file = dwarf_gen_file_info(comp_ctx);
|
||||
if (!comp_ctx->debug_file) {
|
||||
aot_set_last_error("dwarf generate file info failed");
|
||||
goto fail;
|
||||
}
|
||||
comp_ctx->debug_comp_unit = dwarf_gen_comp_unit_info(comp_ctx);
|
||||
if (!comp_ctx->debug_comp_unit) {
|
||||
aot_set_last_error("dwarf generate compile unit info failed");
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (option->enable_bulk_memory)
|
||||
comp_ctx->enable_bulk_memory = true;
|
||||
|
||||
@ -2213,6 +2244,7 @@ aot_checked_addr_list_destroy(AOTFuncContext *func_ctx)
|
||||
|
||||
bool
|
||||
aot_build_zero_function_ret(AOTCompContext *comp_ctx,
|
||||
AOTFuncContext *func_ctx,
|
||||
AOTFuncType *func_type)
|
||||
{
|
||||
LLVMValueRef ret = NULL;
|
||||
@ -2251,6 +2283,10 @@ aot_build_zero_function_ret(AOTCompContext *comp_ctx,
|
||||
aot_set_last_error("llvm build ret failed.");
|
||||
return false;
|
||||
}
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
LLVMMetadataRef return_location = dwarf_gen_func_ret_location(comp_ctx, func_ctx);
|
||||
LLVMInstructionSetDebugLoc(ret, return_location);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user