fix(dfx): Add print backtrace in x86_64

Closes #I5PVET

Change-Id: I70e960bc087d817976083f297faf535e99a04b29
Signed-off-by: yingguofeng@huawei.com <yingguofeng@huawei.com>
This commit is contained in:
yingguofeng@huawei.com 2022-09-06 12:55:08 +08:00
parent cbbb74b5a5
commit 85dee48f91
2 changed files with 66 additions and 0 deletions

View File

@ -342,6 +342,13 @@ config("ecma_test_config") {
"$js_root:ark_jsruntime_common_config",
]
if (enable_leak_check) {
defines = [
"ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK",
"ECMASCRIPT_ENABLE_GLOBAL_LEAK_CHECK",
]
}
ldflags = [ "-Wl,-rpath=\$ORIGIN/" ]
}
@ -725,6 +732,16 @@ source_set("libark_jsruntime_test_set") {
deps += [ "$js_root/ecmascript/compiler:libark_mock_stub_set" ]
}
if (enable_leak_check) {
if (is_linux && (current_cpu == "x86" || current_cpu == "x64")) {
sources += [ "ecmascript/dfx/native_dfx/linux/backtrace.cpp" ]
}
defines = [
"ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK",
"ECMASCRIPT_ENABLE_GLOBAL_LEAK_CHECK",
]
}
public_configs = [
"$js_root:ark_jsruntime_common_config",
"$js_root:ark_jsruntime_public_config",

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/dfx/native_dfx/backtrace.h"
#include <execinfo.h>
#include <unistd.h>
#include "ecmascript/log_wrapper.h"
#include "mem/mem.h"
namespace panda::ecmascript {
static const int MAX_STACK_SIZE = 256;
static const int FRAMES_LEN = 16;
void PrintBacktrace(uintptr_t value)
{
void *stack[MAX_STACK_SIZE];
char **stackList = nullptr;
int framesLen = backtrace(stack, MAX_STACK_SIZE);
stackList = backtrace_symbols(stack, framesLen);
if (stackList == nullptr) {
return;
}
LOG_ECMA(INFO) << "=====================Backtrace(" << std::hex << value <<")========================";
for (int i = 0; i < FRAMES_LEN; ++i)
{
if (stackList[i] == nullptr) {
break;
}
LOG_ECMA(INFO) << stackList[i];
}
free(stackList);
}
} // namespace panda::ecmascript