!674 Modify and supplement the stack column printing code of DFX module

Merge pull request !674 from 史凯/master
This commit is contained in:
openharmony_ci 2022-03-06 04:26:05 +00:00 committed by Gitee
commit 93572851af
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 69 additions and 12 deletions

View File

@ -111,6 +111,7 @@ config("ark_jsruntime_public_config") {
include_dirs = [
"//ark/js_runtime",
"$ark_root",
"//third_party/libunwind/include",
]
}
@ -145,6 +146,7 @@ source_set("libark_js_intl_static") {
"$ark_root/runtime:arkruntime_header_deps",
"//third_party/icu/icu4c:shared_icui18n",
"//third_party/icu/icu4c:shared_icuuc",
"//third_party/libunwind:libunwind",
sdk_libc_secshared_dep,
]
}
@ -548,6 +550,7 @@ source_set("libark_jsruntime_test_static") {
"$ark_root/runtime:arkruntime_header_deps",
"//third_party/icu/icu4c:shared_icui18n",
"//third_party/icu/icu4c:shared_icuuc",
"//third_party/libunwind:libunwind",
sdk_libc_secshared_dep,
]

View File

@ -14,8 +14,10 @@
*/
#include "ecmascript/base/error_helper.h"
#include <libunwind.h>
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/base/error_type.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
@ -182,7 +184,7 @@ CString ErrorHelper::DecodeFunctionName(const CString &name)
JSHandle<EcmaString> ErrorHelper::BuildEcmaStackTrace(JSThread *thread)
{
CString data = BuildNativeEcmaStackTrace(thread);
CString data = BuildNativeAndJsStackTrace(thread);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
LOG(DEBUG, ECMASCRIPT) << data;
return factory->NewFromString(data);
@ -199,9 +201,7 @@ CString ErrorHelper::BuildNativeEcmaStackTrace(JSThread *thread)
continue;
}
auto method = frameHandler.GetMethod();
if (method->IsNative()) {
data += INTRINSIC_METHOD_NAME;
} else {
if (!method->IsNative()) {
data.append(" at ");
data += DecodeFunctionName(method->ParseFunctionName());
data.append(" (");
@ -231,4 +231,44 @@ CString ErrorHelper::BuildNativeEcmaStackTrace(JSThread *thread)
return data;
}
CString ErrorHelper::BuildNativeStackTrace(JSThread *thread)
{
unw_cursor_t cursor;
unw_context_t context;
CString data;
unw_getcontext(&context);
unw_init_local(&cursor, &context);
int radix = 16; // 16: Hexadecimal
while (unw_step(&cursor) > 0) {
unw_word_t offset;
unw_word_t pc;
unw_get_reg(&cursor, UNW_REG_IP, &pc);
if (pc == 0) {
break;
}
data += NumberHelper::IntegerToString(pc, radix);
data.append(":");
char sym[256]; // 256: Maximum length of stack column information
if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
data.append("(");
data += sym;
data.append("+");
data += NumberHelper::IntegerToString(offset, radix);
data.append(")\n");
} else {
data.append("ERROR: filed to get stack frame instruction");
}
}
return data;
}
CString ErrorHelper::BuildNativeAndJsStackTrace(JSThread *thread)
{
CString data = BuildNativeEcmaStackTrace(thread);
CString tempStr = BuildNativeStackTrace(thread);
data += tempStr;
return data;
}
} // namespace panda::ecmascript::base

View File

@ -16,6 +16,11 @@
#ifndef ECMASCRIPT_BASE_ERROR_HELPER_H
#define ECMASCRIPT_BASE_ERROR_HELPER_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextern-c-compat"
#endif
#include "ecmascript/base/error_type.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/js_handle.h"
@ -32,8 +37,14 @@ public:
static JSTaggedValue ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, const ErrorType &errorType);
static CString BuildNativeEcmaStackTrace(JSThread *thread);
static CString BuildNativeAndJsStackTrace(JSThread *thread);
static CString BuildNativeStackTrace(JSThread *thread);
private:
static CString DecodeFunctionName(const CString &name);
static JSHandle<EcmaString> BuildEcmaStackTrace(JSThread *thread);
static JSHandle<JSTaggedValue> GetErrorName(JSThread *thread, const JSHandle<JSTaggedValue> &name,

View File

@ -120,7 +120,7 @@ JSTaggedValue NumberHelper::DoubleToString(JSThread *thread, double number, int
result += DecimalsToString(&numberInteger, numberFraction, radix, delta);
}
result = IntergerToString(numberInteger, radix) + result;
result = IntegerToString(numberInteger, radix) + result;
if (negative) {
result = "-" + result;
@ -270,7 +270,7 @@ char NumberHelper::Carry(char current, int radix)
return CHARS[digit];
}
CString NumberHelper::IntergerToString(double number, int radix)
CString NumberHelper::IntegerToString(double number, int radix)
{
ASSERT(radix >= MIN_RADIX && radix <= MAX_RADIX);
CString result;

View File

@ -89,11 +89,11 @@ public:
static JSTaggedValue DoubleToPrecision(JSThread *thread, double number, int digit);
static JSTaggedValue StringToDoubleWithRadix(const uint8_t *start, const uint8_t *end, int radix);
static CString IntToString(int number);
static CString IntegerToString(double number, int radix);
private:
static char Carry(char current, int radix);
static double Strtod(const char *str, int exponent, uint8_t radix);
static CString IntergerToString(double number, int radix);
static CString DecimalsToString(double *numberInteger, double fraction, int radix, double delta);
static bool IsNonspace(uint16_t c);
static bool GotoNonspace(uint8_t **ptr, const uint8_t *end);

View File

@ -46,11 +46,14 @@ void DFXJSNApi::DumpHeapSnapShot(EcmaVM *vm, int dumpFormat, const std::string
}
}
std::string DFXJSNApi::BuildNativeAndJsBackStackTrace(EcmaVM *vm)
bool DFXJSNApi::BuildNativeAndJsBackStackTrace(EcmaVM *vm, std::string &stackTraceStr)
{
CString trace = ecmascript::base::ErrorHelper::BuildNativeEcmaStackTrace(vm->GetJSThread());
std::string result = CstringConvertToStdString(trace);
return result;
CString trace = ecmascript::base::ErrorHelper::BuildNativeAndJsStackTrace(vm->GetJSThread());
stackTraceStr = CstringConvertToStdString(trace);
if (stackTraceStr == "") {
return false;
}
return true;
}
bool DFXJSNApi::StartHeapTracking(EcmaVM *vm, double timeInterval, bool isVmMode)

View File

@ -34,7 +34,7 @@ using EcmaVM = ecmascript::EcmaVM;
class PUBLIC_API DFXJSNApi {
public:
static void DumpHeapSnapShot(EcmaVM *vm, int dumpFormat, const std::string &path, bool isVmMode = true);
static std::string BuildNativeAndJsBackStackTrace(EcmaVM *vm);
static bool BuildNativeAndJsBackStackTrace(EcmaVM *vm, std::string &stackTraceStr);
static bool StartHeapTracking(EcmaVM *vm, double timeInterval, bool isVmMode = true);
static bool StopHeapTracking(EcmaVM *vm, int dumpFormat, const std::string &filePath);
static void PrintStatisticResult(const EcmaVM *vm);