HarmonyOS 调用OH_LOG_SetCallback接口崩溃

根据下面的文档,使用OH_LOG_SetCallback注册回调函数,崩溃。https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/hilog-guidelines-ndk-V5#日志回调接口使用示例

demo代码:

napi_init.cpp:
#include "napi/native_api.h"
#include "hilog/log.h"

#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0x0000
#define LOG_TAG "xxx"

void MyHiLog(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, const char *msg)
{
  OH_LOG_INFO(LOG_APP, "xxx, MyHiLog in");
}

static napi_value registerLog(napi_env env, napi_callback_info info)
{
  OH_LOG_INFO(LOG_APP, "xxx, registerLog in");

  // 注册回调接口
  OH_LOG_SetCallback(MyHiLog);

  return nullptr;
}

EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
  napi_property_descriptor desc[] = {
  { "registerLog", nullptr, registerLog, nullptr, nullptr, nullptr, napi_default, nullptr }
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports;
}
EXTERN_C_END
static napi_module demoModule = {
  .nm_version = 1,
  .nm_flags = 0,
  .nm_filename = nullptr,
  .nm_register_func = Init,
  .nm_modname = "entry",
  .nm_priv = ((void*)0),
  .reserved = { 0 },
};

extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
{
  napi_module_register(&demoModule);
}

崩溃日志:

Reason:Signal:SIGSEGV(SEGV_ACCERR)@0x0000005cda3a71c0  current thread stack low address = 0x0000005cda3a8000, probably caused by stack-buffer-overflow
Fault thread info:
  Tid:4727, Name:OS_FFRT_3_2
#00 pc 0000000000013170 /system/lib64/chipset-pub-sdk/libhilog.so(HiLogIsLoggable+8)(19bb584fd565e0815d8d1e2f55e64f30)
#01 pc 0018005b39b11824 Not mapped
#02 pc 00000000000122c8 /system/lib64/chipset-pub-sdk/libhilog.so(HiLogPrintArgs+280)(19bb584fd565e0815d8d1e2f55e64f30)
#03 pc 00000000000021ec /system/lib64/ndk/libhilog_ndk.z.so(OH_LOG_Print.cfi+112)(bcc637728132e4332dd658262187b271)
#04 pc 0000000000001b50 /data/storage/el1/bundle/libs/arm64/libentry.so(MyHiLog(LogType, LogLevel, unsigned int, char const*, char const*)+60)(9d3e11f5f59a6b131b4e204c68a31ce5f8b25d97)
#05 pc 0000000000011888 /system/lib64/chipset-pub-sdk/libhilog.so(HiLogPrintVerify(LogType, LogLevel, unsigned int, char const*, char const*, std::__va_list)+416)(19bb584fd565e0815d8d1e2f55e64f30)
#06 pc 00000000000122c8 /system/lib64/chipset-pub-sdk/libhilog.so(HiLogPrintArgs+280)(19bb584fd565e0815d8d1e2f55e64f30)
#07 pc 00000000000021ec /system/lib64/ndk/libhilog_ndk.z.so(OH_LOG_Print.cfi+112)(bcc637728132e4332dd658262187b271)
HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Excelsior_abit

把MyHiLog里面的OH_LOG_INFO这行去掉,回调里面不能再打印hilog,不然会死循环。

分享
微博
QQ
微信
回复
1天前
相关问题
HarmonyOS API调用崩溃问题
467浏览 • 1回复 待解决
HarmonyOS 崩溃监控addWatcher接口耗时
65浏览 • 1回复 待解决
OpenSL ES音频录制示例调用崩溃
1934浏览 • 1回复 待解决
OH_NativeImage_UpdateSurfaceImage接口错误码
1716浏览 • 1回复 待解决
HarmonyOS调用napi_call_function方法时崩溃
672浏览 • 1回复 待解决
Watcher接口如何订阅到OS的崩溃事件?
628浏览 • 1回复 待解决
HarmonyOS如何调用http/https接口?
10405浏览 • 3回复 已解决