From df1027c8629f88d51f0087fe405e00cb09bec052 Mon Sep 17 00:00:00 2001 From: rentangyu Date: Mon, 30 Jun 2025 16:05:22 +0800 Subject: [PATCH] =?UTF-8?q?[Bug]:=E5=BC=82=E6=AD=A5=E6=A0=88=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue:https://gitee.com/openharmony/ability_ability_runtime/issues/ICIU8L Signed-off-by: rentangyu --- .../src/uncaught_exception_callback.cpp | 18 ++++++++++-------- .../uncaught_exception_callback_test.cpp | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp b/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp index 914d90c686..66324e9ce8 100644 --- a/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp +++ b/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp @@ -78,7 +78,6 @@ void NapiUncaughtExceptionCallback::operator()(panda::TryCatch& trycatch) } } - void NapiUncaughtExceptionCallback::CallbackTask(napi_value& obj) { std::string errorMsg = GetNativeStrFromJsTaggedObj(obj, "message"); @@ -103,6 +102,11 @@ void NapiUncaughtExceptionCallback::CallbackTask(napi_value& obj) } if (errorStack.find(BACKTRACE) != std::string::npos) { summary += "Stacktrace:\n" + GetFuncNameAndBuildId(errorStack); + std::string submitterStack = GetSubmitterStackLocal(); + if (!submitterStack.empty()) { + summary.append("========SubmitterStacktrace========\n"); + summary.append(submitterStack); + } } else { summary += "Stacktrace:\n" + errorStack; } @@ -112,11 +116,6 @@ void NapiUncaughtExceptionCallback::CallbackTask(napi_value& obj) summary.append(str); } #endif // SUPPORT_GRAPHICS - std::string submitterStack = GetSubmitterStackLocal(); - if (!submitterStack.empty()) { - summary.append("========SubmitterStacktrace========\n"); - summary.append(submitterStack); - } if (uncaughtTask_) { uncaughtTask_(summary, errorObj); } @@ -183,16 +182,19 @@ std::string NapiUncaughtExceptionCallback::GetSubmitterStackLocal() } sbmitterStack = reinterpret_cast(dlsym(handle, "DfxGetSubmitterStackLocal")); if (sbmitterStack == nullptr) { - TAG_LOGE(AAFwkTag::JSENV, "dlsym libasync_stack failed"); + TAG_LOGE(AAFwkTag::JSENV, "dlsym libasync_stack failed, %{public}s", dlerror()); + dlclose(handle); return ""; } const size_t bufferSize = 64 * 1024; char stackTrace[bufferSize] = {0}; int result = sbmitterStack(stackTrace, bufferSize); if (result == 0) { + dlclose(handle); return stackTrace; } else { - TAG_LOGE(AAFwkTag::JSENV, "submitterStack interface failed"); + TAG_LOGE(AAFwkTag::JSENV, "submitterStack interface failed, result: %{public}d", result); + dlclose(handle); return ""; } } diff --git a/js_environment/test/unittest/uncaught_exception_callback_test/uncaught_exception_callback_test.cpp b/js_environment/test/unittest/uncaught_exception_callback_test/uncaught_exception_callback_test.cpp index f8b38aa865..d9e641c200 100644 --- a/js_environment/test/unittest/uncaught_exception_callback_test/uncaught_exception_callback_test.cpp +++ b/js_environment/test/unittest/uncaught_exception_callback_test/uncaught_exception_callback_test.cpp @@ -327,6 +327,7 @@ HWTEST_F(NapiUncaughtExceptionCallbackTest, GetFuncNameAndBuildIdTest_0100, Test { GTEST_LOG_(INFO) << "GetFuncNameAndBuildIdTest_0100 start"; std::ostringstream stack; + stack << "Cannot get SourceMap info, dump raw stack:\n"; Backtrace(stack); std::string stackinfo = NapiUncaughtExceptionCallback::GetFuncNameAndBuildId(stack.str()); ASSERT_EQ(stackinfo.find("GetFuncNameAndBuildIdTest") != std::string::npos, true); @@ -363,6 +364,7 @@ HWTEST_F(NapiUncaughtExceptionCallbackTest, GetSubmitterStackLocal_0100, TestSiz { GTEST_LOG_(INFO) << "GetSubmitterStackLocal_0100 start"; setenv("HAP_DEBUGGABLE", "true", 1); + ASSERT_EQ(NapiUncaughtExceptionCallback::GetSubmitterStackLocal(), ""); uv_timer_t timerHandle; uv_work_t work; uv_loop_t* loop = uv_default_loop();