Android.bp文件里添加:
shared_libs: [
...
"libutilscallstack",
]
代码里添加:android::CallStack stack("Debug info");即可。打印效果如下:
04-30 02:53:49.037 530 904 D Debug info: #00 pc 00000000001a8c6c /system/lib64/libcameraservice.so (android::Camera3Device::HalInterface::configureStreams(camera_metadata const*, android::camera3::camera_stream_configuration*, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> > const&)+2420)
04-30 02:53:49.037 530 904 D Debug info: #01 pc 00000000001a63b0 /system/lib64/libcameraservice.so (android::Camera3Device::configureStreamsLocked(int, android::CameraMetadata const&, bool)+3164)
04-30 02:53:49.037 530 904 D Debug info: #02 pc 00000000001a56f8 /system/lib64/libcameraservice.so (android::Camera3Device::filterParamsAndConfigureLocked(android::CameraMetadata const&, int)+384)
04-30 02:53:49.037 530 904 D Debug info: #03 pc 000000000019586c /system/lib64/libcameraservice.so (android::Camera3Device::configureStreams(android::CameraMetadata const&, int)+228)
04-30 02:53:49.037 530 904 D Debug info: #04 pc 00000000001545c0 /system/lib64/libcameraservice.so (android::CameraDeviceClient::endConfigure(int, android::CameraMetadata const&, long, std::__1::vector<int, std::__1::allocator<int> >*)+792)
04-30 02:53:49.037 530 904 D Debug info: #05 pc 0000000000046f8c /system/lib64/libcamera_client.so (android::hardware::camera2::BnCameraDeviceUser::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+2068)
04-30 02:53:49.037 530 904 D Debug info: #06 pc 000000000003c810 /system/lib64/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+248)
04-30 02:53:49.037 530 904 D Debug info: #07 pc 0000000000046068 /system/lib64/libbinder.so (android::IPCThreadState::executeCommand(int)+1024)
04-30 02:53:49.037 530 904 D Debug info: #08 pc 0000000000045ba0 /system/lib64/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+160)
04-30 02:53:49.037 530 904 D Debug info: #09 pc 0000000000046410 /system/lib64/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+68)
04-30 02:53:49.037 530 904 D Debug info: #10 pc 000000000006c2b4 /system/lib64/libbinder.so (android::PoolThread::threadLoop()+24)
04-30 02:53:49.037 530 904 D Debug info: #11 pc 0000000000012094 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+260)
04-30 02:53:49.037 530 904 D Debug info: #12 pc 0000000000011964 /system/lib64/libutils.so (thread_data_t::trampoline(thread_data_t const*)+404)
04-30 02:53:49.037 530 904 D Debug info: #13 pc 00000000000b1810 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+264)
04-30 02:53:49.037 530 904 D Debug info: #14 pc 00000000000512f0 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)
Android12 亲测有效