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:
@ -305,6 +305,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
|
||||
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/3163
|
||||
*/
|
||||
LanguageType language_type = function.GetLanguage();
|
||||
bool cplusplus = false;
|
||||
switch (language_type) {
|
||||
case eLanguageTypeC89:
|
||||
case eLanguageTypeC:
|
||||
@ -312,6 +313,14 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
|
||||
case eLanguageTypeC11:
|
||||
case eLanguageTypeC17:
|
||||
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:
|
||||
LOG_WARNING("func %s has unsupported language_type 0x%x",
|
||||
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 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);
|
||||
|
||||
for (uint32_t function_arg_idx = 0; function_arg_idx < num_function_args;
|
||||
++function_arg_idx) {
|
||||
for (uint32_t function_arg_idx = 0;
|
||||
function_arg_idx < num_function_args; ++function_arg_idx) {
|
||||
SBType function_arg_type =
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto compile_unit = sc.GetCompileUnit();
|
||||
auto file_spec = compile_unit.GetFileSpec();
|
||||
@ -366,7 +379,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
|
||||
}
|
||||
|
||||
LLVMMetadataRef FunctionTy = LLVMDIBuilderCreateSubroutineType(
|
||||
DIB, File, ParamTypes, num_function_args + 1, LLVMDIFlagZero);
|
||||
DIB, File, ParamTypes, num_param_types, LLVMDIFlagZero);
|
||||
|
||||
auto line_entry = sc.GetLineEntry();
|
||||
LLVMMetadataRef ReplaceableFunctionMetadata =
|
||||
@ -386,13 +399,6 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
|
||||
|
||||
LLVMMetadataRef ParamExpression =
|
||||
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(
|
||||
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,
|
||||
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;
|
||||
function_arg_idx < variable_list.GetSize(); ++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());
|
||||
auto valtype = variable.GetType();
|
||||
LLVMMetadataRef ParamLocation = LLVMDIBuilderCreateDebugLocation(
|
||||
LLVMMetadataRef ParamLocation =
|
||||
LLVMDIBuilderCreateDebugLocation(
|
||||
comp_ctx->context, dec.GetLine(), dec.GetColumn(),
|
||||
FunctionMetadata, NULL);
|
||||
const char *varname = variable.GetName();
|
||||
LLVMMetadataRef ParamVar = LLVMDIBuilderCreateParameterVariable(
|
||||
DIB, FunctionMetadata, varname, varname ? strlen(varname) : 0,
|
||||
function_arg_idx + 1 + 1,
|
||||
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);
|
||||
@ -435,6 +451,7 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
|
||||
block_curr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FunctionMetadata;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user