diff --git a/ecmascript/base/error_helper.cpp b/ecmascript/base/error_helper.cpp index ceae1d0d45..67dffbd091 100644 --- a/ecmascript/base/error_helper.cpp +++ b/ecmascript/base/error_helper.cpp @@ -254,10 +254,6 @@ JSHandle ErrorHelper::BuildEcmaStackTrace(JSThread *thread, std::str if (sourceMapcb != nullptr && !data.empty()) { data = sourceMapcb(data.c_str()); } - auto nativeStackcb = ecmaVm->GetNativeStackCallback(); - if (nativeStackcb != nullptr && data.empty()) { - data = nativeStackcb(); - } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); return factory->NewFromStdString(data); diff --git a/ecmascript/dfx/stackinfo/js_stackinfo.cpp b/ecmascript/dfx/stackinfo/js_stackinfo.cpp index 881c282ae7..caf40e6745 100644 --- a/ecmascript/dfx/stackinfo/js_stackinfo.cpp +++ b/ecmascript/dfx/stackinfo/js_stackinfo.cpp @@ -26,6 +26,9 @@ #if defined(PANDA_TARGET_OHOS) #include "ecmascript/extractortool/src/extractor.h" #endif +#if defined(ENABLE_EXCEPTION_BACKTRACE) +#include "ecmascript/platform/backtrace.h" +#endif namespace panda::ecmascript { std::string JsStackInfo::BuildMethodTrace(Method *method, uint32_t pcOffset, bool enableStackSourceFile) @@ -125,6 +128,13 @@ std::string JsStackInfo::BuildJsStackTrace(JSThread *thread, bool needNative) data.append(" at native method (").append(strm.str()).append(")\n"); } } + if (data.empty()) { +#if defined(ENABLE_EXCEPTION_BACKTRACE) + std::ostringstream stack; + Backtrace(stack); + data = stack.str(); +#endif + } return data; } diff --git a/ecmascript/dfx/stackinfo/tests/js_stackinfo_test.cpp b/ecmascript/dfx/stackinfo/tests/js_stackinfo_test.cpp index 524feb6141..2bdccdbe48 100644 --- a/ecmascript/dfx/stackinfo/tests/js_stackinfo_test.cpp +++ b/ecmascript/dfx/stackinfo/tests/js_stackinfo_test.cpp @@ -49,12 +49,6 @@ public: JSThread *thread {nullptr}; }; -HWTEST_F_L0(JsStackInfoTest, BuildJsStackTrace) -{ - std::string stack = JsStackInfo::BuildJsStackTrace(thread, false); - ASSERT_TRUE(!stack.empty()); -} - HWTEST_F_L0(JsStackInfoTest, FrameCheckTest) { uintptr_t frame[22]; diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index c4d366eb01..9b5eea8eff 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -95,7 +95,6 @@ class Jit; using NativePtrGetter = void* (*)(void* info); using SourceMapCallback = std::function; using SourceMapTranslateCallback = std::function; -using NativeStackCallback = std::function; using ResolveBufferCallback = std::function; using UnloadNativeModuleCallback = std::function; using RequestAotCallback = @@ -311,16 +310,6 @@ public: return sourceMapTranslateCallback_; } - void SetNativeStackCallback(NativeStackCallback cb) - { - nativeStackCallback_ = cb; - } - - NativeStackCallback GetNativeStackCallback() const - { - return nativeStackCallback_; - } - size_t GetNativePointerListSize() { return nativePointerList_.size(); @@ -694,7 +683,6 @@ private: NativePtrGetter nativePtrGetter_ {nullptr}; SourceMapCallback sourceMapCallback_ {nullptr}; SourceMapTranslateCallback sourceMapTranslateCallback_ {nullptr}; - NativeStackCallback nativeStackCallback_ {nullptr}; void *loop_ {nullptr}; // resolve path to get abc's buffer diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index cb5c59a17e..757bb7a471 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -96,7 +96,6 @@ using JSTaggedType = uint64_t; using ConcurrentCallback = void (*)(Local result, bool success, void *taskInfo, void *data); using SourceMapCallback = std::function; using SourceMapTranslateCallback = std::function; -using NativeStackCallback = std::function; using DeviceDisconnectCallback = std::function; #define ECMA_DISALLOW_COPY(className) \ @@ -1327,7 +1326,6 @@ public: static void SetNativePtrGetter(EcmaVM *vm, void* cb); static void SetSourceMapCallback(EcmaVM *vm, SourceMapCallback cb); static void SetSourceMapTranslateCallback(EcmaVM *vm, SourceMapTranslateCallback cb); - static void SetNativeStackCallback(EcmaVM *vm, NativeStackCallback cb); static void SetHostEnqueueJob(const EcmaVM* vm, Local cb); static EcmaVM* CreateEcmaVM(const ecmascript::JSRuntimeOptions &options); static void PreFork(EcmaVM *vm); diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index ff28561516..e6af132442 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -2991,11 +2991,6 @@ void JSNApi::SetSourceMapTranslateCallback(EcmaVM *vm, SourceMapTranslateCallbac vm->SetSourceMapTranslateCallback(callback); } -void JSNApi::SetNativeStackCallback(EcmaVM *vm, NativeStackCallback callback) -{ - vm->SetNativeStackCallback(callback); -} - void JSNApi::SetSourceMapCallback(EcmaVM *vm, SourceMapCallback callback) { vm->SetSourceMapCallback(callback); diff --git a/ecmascript/platform/backtrace.h b/ecmascript/platform/backtrace.h index ebc9ccbd5d..2c497a78ff 100644 --- a/ecmascript/platform/backtrace.h +++ b/ecmascript/platform/backtrace.h @@ -20,6 +20,6 @@ #include namespace panda::ecmascript { -void Backtrace(std::ostringstream &stack, bool enableCache = false, bool jsStack = false); +void Backtrace(std::ostringstream &stack, bool enableCache = false); } // namespace panda::ecmascript #endif // ECMASCRIPT_PLATFORM_BACKTRACE_H diff --git a/ecmascript/platform/unix/linux/backtrace.cpp b/ecmascript/platform/unix/linux/backtrace.cpp index 6ef197be37..3ef946656f 100644 --- a/ecmascript/platform/unix/linux/backtrace.cpp +++ b/ecmascript/platform/unix/linux/backtrace.cpp @@ -24,8 +24,7 @@ namespace panda::ecmascript { static const int MAX_STACK_SIZE = 256; static const int FRAMES_LEN = 16; -void Backtrace(std::ostringstream &stack, [[maybe_unused]] bool enableCache, - [[maybe_unused]] bool jsStack) +void Backtrace(std::ostringstream &stack, [[maybe_unused]] bool enableCache) { void *buffer[MAX_STACK_SIZE]; char **stackList = nullptr; diff --git a/ecmascript/platform/unix/mac/backtrace.cpp b/ecmascript/platform/unix/mac/backtrace.cpp index 78f54a70aa..7a3a4b287d 100644 --- a/ecmascript/platform/unix/mac/backtrace.cpp +++ b/ecmascript/platform/unix/mac/backtrace.cpp @@ -17,8 +17,7 @@ #include "ecmascript/log_wrapper.h" namespace panda::ecmascript { -void Backtrace([[maybe_unused]] std::ostringstream &stack, [[maybe_unused]] bool enableCache, - [[maybe_unused]] bool jsStack) +void Backtrace([[maybe_unused]] std::ostringstream &stack, [[maybe_unused]] bool enableCache) { LOG_ECMA(INFO) << "Print backtrace in macos not support"; } diff --git a/ecmascript/platform/unix/ohos/backtrace.cpp b/ecmascript/platform/unix/ohos/backtrace.cpp index 77fad8c488..ef5f37a7bd 100644 --- a/ecmascript/platform/unix/ohos/backtrace.cpp +++ b/ecmascript/platform/unix/ohos/backtrace.cpp @@ -29,8 +29,6 @@ namespace panda::ecmascript { static const std::string LIB_UNWIND_SO_NAME = "libunwind.so"; static const std::string LIB_UNWIND_Z_SO_NAME = "libunwind.z.so"; -static const std::string LIB_ARK_JSRUNTIME_SO_NAME = "libark_jsruntime.so"; -static const std::string LIB_ACE_NAPI_Z_SO_NAME = "libace_napi.z.so"; static const int MAX_STACK_SIZE = 16; static const int LOG_BUF_LEN = 1024; @@ -38,7 +36,7 @@ using UnwBackTraceFunc = int (*)(void**, int); static std::map stackInfoCache; -void Backtrace(std::ostringstream &stack, bool enableCache, bool jsStack) +void Backtrace(std::ostringstream &stack, bool enableCache) { static UnwBackTraceFunc unwBackTrace = nullptr; if (!unwBackTrace) { @@ -60,10 +58,7 @@ void Backtrace(std::ostringstream &stack, bool enableCache, bool jsStack) void *buffer[MAX_STACK_SIZE] = { nullptr }; int level = unwBackTrace(reinterpret_cast(&buffer), MAX_STACK_SIZE); stack << "=====================Backtrace========================"; - bool flag = true; - int index = 0; for (int i = 1; i < level; i++) { - index++; Dl_info info; auto iter = stackInfoCache.find(buffer[i]); if (enableCache && iter != stackInfoCache.end()) { @@ -77,26 +72,12 @@ void Backtrace(std::ostringstream &stack, bool enableCache, bool jsStack) } } const char *file = info.dli_fname ? info.dli_fname : ""; - if (jsStack) { - std::string str = file; - auto splitPos = str.rfind("/"); - if (splitPos != std::string::npos) { - str = str.substr(splitPos + 1); - } - if ((str.compare(LIB_ARK_JSRUNTIME_SO_NAME) == 0 || - str.compare(LIB_ACE_NAPI_Z_SO_NAME) == 0) && flag) { - index--; - continue; - } else { - flag = false; - } - } uint64_t offset = info.dli_fbase ? ToUintPtr(buffer[i]) - ToUintPtr(info.dli_fbase) : 0; char buf[LOG_BUF_LEN] = {0}; char frameFormatWithMapName[] = "#%02zu pc %016" PRIx64 " %s"; int ret = 0; ret = static_cast(snprintf_s(buf, sizeof(buf), sizeof(buf) - 1, frameFormatWithMapName, \ - index, offset, file)); + i, offset, file)); if (ret <= 0) { LOG_ECMA(ERROR) << "Backtrace snprintf_s failed"; return; diff --git a/ecmascript/platform/windows/backtrace.cpp b/ecmascript/platform/windows/backtrace.cpp index b4f2ee2281..e3742223b7 100644 --- a/ecmascript/platform/windows/backtrace.cpp +++ b/ecmascript/platform/windows/backtrace.cpp @@ -17,8 +17,7 @@ #include "ecmascript/log_wrapper.h" namespace panda::ecmascript { -void Backtrace([[maybe_unused]] std::ostringstream &stack, [[maybe_unused]] bool enableCache, - [[maybe_unused]] bool jsStack) +void Backtrace([[maybe_unused]] std::ostringstream &stack, [[maybe_unused]] bool enableCache) { LOG_ECMA(INFO) << "Print backtrace in windows not support"; }