From 503c9694c89b0541380918b3832b1c771f0a4cdd Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 29 Feb 2024 15:03:49 +0900 Subject: [PATCH] lldb_function_to_function_dbi: Fix a null dereference (#3189) C++ allows unnamed arguments. In the debug info, they are represented as DW_TAG_formal_parameter w/o DW_AT_name. variable.GetName() here returns NULL for them. cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3187 --- core/iwasm/compilation/debug/dwarf_extractor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/iwasm/compilation/debug/dwarf_extractor.cpp b/core/iwasm/compilation/debug/dwarf_extractor.cpp index d322aefe5..2804735cb 100644 --- a/core/iwasm/compilation/debug/dwarf_extractor.cpp +++ b/core/iwasm/compilation/debug/dwarf_extractor.cpp @@ -387,9 +387,10 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx, LLVMMetadataRef ParamLocation = LLVMDIBuilderCreateDebugLocation( comp_ctx->context, dec.GetLine(), dec.GetColumn(), FunctionMetadata, NULL); + const char *varname = variable.GetName(); LLVMMetadataRef ParamVar = LLVMDIBuilderCreateParameterVariable( - DIB, FunctionMetadata, variable.GetName(), - strlen(variable.GetName()), 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);