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,11 +334,14 @@ 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;
if (!cplusplus) {
num_param_types = num_function_args + 1;
ParamTypes[0] = lldb_type_to_type_dbi(comp_ctx, return_type); 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);
@ -349,6 +361,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
ParamTypes[function_arg_idx + 1] = NULL; ParamTypes[function_arg_idx + 1] = NULL;
} }
} }
}
auto compile_unit = sc.GetCompileUnit(); auto compile_unit = sc.GetCompileUnit();
auto file_spec = compile_unit.GetFileSpec(); auto file_spec = compile_unit.GetFileSpec();
@ -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,19 +418,29 @@ 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);
if (!cplusplus) {
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);
}
for (uint32_t function_arg_idx = 0; for (uint32_t function_arg_idx = 0;
function_arg_idx < variable_list.GetSize(); ++function_arg_idx) { function_arg_idx < variable_list.GetSize(); ++function_arg_idx) {
SBValue variable(variable_list.GetValueAtIndex(function_arg_idx)); SBValue variable(variable_list.GetValueAtIndex(function_arg_idx));
if (variable.IsValid() && ParamTypes[function_arg_idx + 1] != NULL) { if (variable.IsValid()
&& ParamTypes[function_arg_idx + 1] != NULL) {
SBDeclaration dec(variable.GetDeclaration()); SBDeclaration dec(variable.GetDeclaration());
auto valtype = variable.GetType(); auto valtype = variable.GetType();
LLVMMetadataRef ParamLocation = LLVMDIBuilderCreateDebugLocation( LLVMMetadataRef ParamLocation =
LLVMDIBuilderCreateDebugLocation(
comp_ctx->context, dec.GetLine(), dec.GetColumn(), comp_ctx->context, dec.GetLine(), dec.GetColumn(),
FunctionMetadata, NULL); FunctionMetadata, NULL);
const char *varname = variable.GetName(); const char *varname = variable.GetName();
LLVMMetadataRef ParamVar = LLVMDIBuilderCreateParameterVariable( LLVMMetadataRef ParamVar = LLVMDIBuilderCreateParameterVariable(
DIB, FunctionMetadata, varname, varname ? strlen(varname) : 0, DIB, FunctionMetadata, varname,
function_arg_idx + 1 + 1, varname ? strlen(varname) : 0, function_arg_idx + 1 + 1,
File, // starts form 1, and 1 is exenv, File, // starts form 1, and 1 is exenv,
dec.GetLine(), ParamTypes[function_arg_idx + 1], true, dec.GetLine(), ParamTypes[function_arg_idx + 1], true,
LLVMDIFlagZero); LLVMDIFlagZero);
@ -435,6 +451,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
block_curr); block_curr);
} }
} }
}
return FunctionMetadata; return FunctionMetadata;
} }