dwarf_extractor.cpp: Enable limited support for C++ (#3540)

While band-aid fixes like this is not plausible IMO,
some people prefer to have some debug info even if it's
partial/limited/broken. This commit partially (re)enables
C++ processing. On the other hand, do not bother to process
variables because it's known incompatible with C++.
This commit is contained in:
YAMAMOTO Takashi
2024-06-18 16:42:56 +09:00
committed by GitHub
parent fa8a80a115
commit 72f74b7b51

View File

@ -305,6 +305,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/3163 * https://github.com/bytecodealliance/wasm-micro-runtime/issues/3163
*/ */
LanguageType language_type = function.GetLanguage(); LanguageType language_type = function.GetLanguage();
bool cplusplus = false;
switch (language_type) { switch (language_type) {
case eLanguageTypeC89: case eLanguageTypeC89:
case eLanguageTypeC: case eLanguageTypeC:
@ -312,6 +313,14 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
case eLanguageTypeC11: case eLanguageTypeC11:
case eLanguageTypeC17: case eLanguageTypeC17:
break; break;
case eLanguageTypeC_plus_plus:
case eLanguageTypeC_plus_plus_03:
case eLanguageTypeC_plus_plus_11:
case eLanguageTypeC_plus_plus_14:
case eLanguageTypeC_plus_plus_17:
case eLanguageTypeC_plus_plus_20:
cplusplus = true;
break;
default: default:
LOG_WARNING("func %s has unsupported language_type 0x%x", LOG_WARNING("func %s has unsupported language_type 0x%x",
function_name, (int)language_type); function_name, (int)language_type);
@ -325,28 +334,32 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
LLVMMetadataRef File = comp_ctx->debug_file; /* a fallback */ LLVMMetadataRef File = comp_ctx->debug_file; /* a fallback */
LLVMMetadataRef ParamTypes[num_function_args + 1]; LLVMMetadataRef ParamTypes[num_function_args + 1];
size_t num_param_types = 0;
ParamTypes[0] = lldb_type_to_type_dbi(comp_ctx, return_type); if (!cplusplus) {
num_param_types = num_function_args + 1;
ParamTypes[0] = lldb_type_to_type_dbi(comp_ctx, return_type);
for (uint32_t function_arg_idx = 0; function_arg_idx < num_function_args; for (uint32_t function_arg_idx = 0;
++function_arg_idx) { function_arg_idx < num_function_args; ++function_arg_idx) {
SBType function_arg_type = SBType function_arg_type =
function_args.GetTypeAtIndex(function_arg_idx); function_args.GetTypeAtIndex(function_arg_idx);
if (function_arg_type.IsValid()) { if (function_arg_type.IsValid()) {
ParamTypes[function_arg_idx + 1] = ParamTypes[function_arg_idx + 1] =
lldb_type_to_type_dbi(comp_ctx, function_arg_type); lldb_type_to_type_dbi(comp_ctx, function_arg_type);
if (ParamTypes[function_arg_idx + 1] == NULL) { if (ParamTypes[function_arg_idx + 1] == NULL) {
LOG_WARNING( LOG_WARNING(
"func %s arg %" PRIu32 "func %s arg %" PRIu32
" has a type not implemented by lldb_type_to_type_dbi", " has a type not implemented by lldb_type_to_type_dbi",
function_name, function_arg_idx);
}
}
else {
LOG_WARNING("func %s arg %" PRIu32 ": GetTypeAtIndex failed",
function_name, function_arg_idx); function_name, function_arg_idx);
ParamTypes[function_arg_idx + 1] = NULL; }
}
else {
LOG_WARNING("func %s arg %" PRIu32 ": GetTypeAtIndex failed",
function_name, function_arg_idx);
ParamTypes[function_arg_idx + 1] = NULL;
}
} }
} }
@ -366,7 +379,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
} }
LLVMMetadataRef FunctionTy = LLVMDIBuilderCreateSubroutineType( LLVMMetadataRef FunctionTy = LLVMDIBuilderCreateSubroutineType(
DIB, File, ParamTypes, num_function_args + 1, LLVMDIFlagZero); DIB, File, ParamTypes, num_param_types, LLVMDIFlagZero);
auto line_entry = sc.GetLineEntry(); auto line_entry = sc.GetLineEntry();
LLVMMetadataRef ReplaceableFunctionMetadata = LLVMMetadataRef ReplaceableFunctionMetadata =
@ -386,13 +399,6 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
LLVMMetadataRef ParamExpression = LLVMMetadataRef ParamExpression =
LLVMDIBuilderCreateExpression(DIB, NULL, 0); LLVMDIBuilderCreateExpression(DIB, NULL, 0);
auto variable_list =
function.GetBlock().GetVariables(extractor->target, true, false, false);
if (num_function_args != variable_list.GetSize()) {
LOG_ERROR(
"function args number mismatch!:value number=%d, function args=%d",
variable_list.GetSize(), num_function_args);
}
LLVMMetadataRef ParamLocation = LLVMDIBuilderCreateDebugLocation( LLVMMetadataRef ParamLocation = LLVMDIBuilderCreateDebugLocation(
comp_ctx->context, line_entry.GetLine(), 0, FunctionMetadata, NULL); comp_ctx->context, line_entry.GetLine(), 0, FunctionMetadata, NULL);
@ -412,27 +418,38 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
LLVMDIBuilderInsertDbgValueAtEnd(DIB, Param, ParamVar, ParamExpression, LLVMDIBuilderInsertDbgValueAtEnd(DIB, Param, ParamVar, ParamExpression,
ParamLocation, block_curr); ParamLocation, block_curr);
for (uint32_t function_arg_idx = 0; if (!cplusplus) {
function_arg_idx < variable_list.GetSize(); ++function_arg_idx) { auto variable_list = function.GetBlock().GetVariables(
SBValue variable(variable_list.GetValueAtIndex(function_arg_idx)); extractor->target, true, false, false);
if (variable.IsValid() && ParamTypes[function_arg_idx + 1] != NULL) { if (num_function_args != variable_list.GetSize()) {
SBDeclaration dec(variable.GetDeclaration()); LOG_ERROR("function args number mismatch!:value number=%d, "
auto valtype = variable.GetType(); "function args=%d",
LLVMMetadataRef ParamLocation = LLVMDIBuilderCreateDebugLocation( variable_list.GetSize(), num_function_args);
comp_ctx->context, dec.GetLine(), dec.GetColumn(), }
FunctionMetadata, NULL); for (uint32_t function_arg_idx = 0;
const char *varname = variable.GetName(); function_arg_idx < variable_list.GetSize(); ++function_arg_idx) {
LLVMMetadataRef ParamVar = LLVMDIBuilderCreateParameterVariable( SBValue variable(variable_list.GetValueAtIndex(function_arg_idx));
DIB, FunctionMetadata, varname, varname ? strlen(varname) : 0, if (variable.IsValid()
function_arg_idx + 1 + 1, && ParamTypes[function_arg_idx + 1] != NULL) {
File, // starts form 1, and 1 is exenv, SBDeclaration dec(variable.GetDeclaration());
dec.GetLine(), ParamTypes[function_arg_idx + 1], true, auto valtype = variable.GetType();
LLVMDIFlagZero); LLVMMetadataRef ParamLocation =
LLVMValueRef Param = LLVMDIBuilderCreateDebugLocation(
LLVMGetParam(func_ctx->func, function_arg_idx + 1); comp_ctx->context, dec.GetLine(), dec.GetColumn(),
LLVMDIBuilderInsertDbgValueAtEnd(DIB, Param, ParamVar, FunctionMetadata, NULL);
ParamExpression, ParamLocation, const char *varname = variable.GetName();
block_curr); LLVMMetadataRef ParamVar = LLVMDIBuilderCreateParameterVariable(
DIB, FunctionMetadata, varname,
varname ? strlen(varname) : 0, function_arg_idx + 1 + 1,
File, // starts form 1, and 1 is exenv,
dec.GetLine(), ParamTypes[function_arg_idx + 1], true,
LLVMDIFlagZero);
LLVMValueRef Param =
LLVMGetParam(func_ctx->func, function_arg_idx + 1);
LLVMDIBuilderInsertDbgValueAtEnd(DIB, Param, ParamVar,
ParamExpression, ParamLocation,
block_curr);
}
} }
} }