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
赞
收藏 0
回答 1
待解决
相关问题
多线程调用 OH_Drawing_CreateFontCollection 崩溃
941浏览 • 1回复 待解决
HarmonyOS hiappevent崩溃监听接口无法拿到external_log日志
41浏览 • 1回复 待解决
HarmonyOS 视频硬解码调用OH_VideoDecoder_PushInputData崩溃
48浏览 • 1回复 待解决
4.1升级至5.0后,调用OH_NativeXComponent_GetXComponentSize崩溃
182浏览 • 1回复 待解决
未联网状态下,调用getNetCapabilitiesSync接口,程序崩溃
392浏览 • 1回复 待解决
C++中使用 “hilog/log.h” OH_LOG_Print打印日志不显示
699浏览 • 1回复 待解决
HarmonyOS API调用崩溃问题
467浏览 • 1回复 待解决
HarmonyOS OH_LOG_Print,日志不显示,只显示为<private>
819浏览 • 1回复 待解决
HarmonyOS 崩溃监控addWatcher接口耗时
65浏览 • 1回复 待解决
HarmonyOS NAPI日志不能打印,OH_LOG_INFO和printf都不行
178浏览 • 1回复 待解决
HarmonyOS OH_AVScreenCapture_StartScreenCapture调用失败
532浏览 • 1回复 待解决
hilog OH_LOG_IsLoggable 方法什么情况下会返回 false?
758浏览 • 2回复 待解决
HarmonyOS OH_AVScreenCapture_StartScreenRecording接口权限问题咨询
497浏览 • 1回复 待解决
OpenSL ES音频录制示例调用崩溃
1934浏览 • 1回复 待解决
OH_NativeImage_UpdateSurfaceImage接口错误码
1716浏览 • 1回复 待解决
HarmonyOS调用napi_call_function方法时崩溃
672浏览 • 1回复 待解决
Sensor Native调用OH_Sensor_DestroySubscriber无效
321浏览 • 1回复 待解决
Watcher接口如何订阅到OS的崩溃事件?
628浏览 • 1回复 待解决
HarmonyOS 使用音视频合成调用调用OH_AVMuxer_WriteSampleBuffer(),写入封装数据
29浏览 • 1回复 待解决
HarmonyOS如何调用http/https接口?
10405浏览 • 3回复 已解决
使用OH_NetStack_VerifyCertification接口如何校验叶证书
323浏览 • 1回复 待解决
OH_AVCodecAsyncCallback有可能在调用destory之后还被调用吗
1700浏览 • 1回复 待解决
把MyHiLog里面的OH_LOG_INFO这行去掉,回调里面不能再打印hilog,不然会死循环。