在Android平台上,如何在C++里面打印Backtrace。
在Android.mk文件中加入动态库依赖
LOCAL_SHARED_LIBRARIES += libutilscallstack
在C++文件中加入头文件
#include <log/log.h>
#include <utils/CallStack.h>
在想调用Callstack的函数中加入如下代码
android::CallStack callstack;
callstack.update();
callstack.log("Deepinout", ANDROID_LOG_INFO, "Camera");
- Deepinout是TAG
- Camera是backtrace的前缀
示例
加入上面的改动后,在Log中搜索Deepinout
就看看到Backtrace了
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#00 pc 0000000000018db8 /vendor/lib64/libcamximageformatutils.so (CamX::ImageFormatUtils::InitializeFormatParams(CamX::ImageFormat*, CamX::FormatParamInfo*) (.cfi)+80)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#01 pc 00000000007c7fe0 /vendor/lib64/hw/camera.qcom.so (CamX::ChiBufferManagerCreate(char const*, CHIBufferManagerCreateData*) (.cfi)+1040)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#02 pc 00000000002d1cbc /vendor/lib64/hw/com.qti.chi.override.so (CHIBufferManager::Initialize(char const*, CHIBufferManagerCreateData*, int)+420)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#03 pc 00000000002d1978 /vendor/lib64/hw/com.qti.chi.override.so (CHIBufferManager::Create(char const*, CHIBufferManagerCreateData*, int) (.cfi)+256)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#04 pc 00000000001b18b8 /vendor/lib64/hw/com.qti.chi.override.so (CHITargetBufferManager::Initialize(ChiTargetBufferManagerCreateData*)+1776)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#05 pc 00000000001b1044 /vendor/lib64/hw/com.qti.chi.override.so (CHITargetBufferManager::Create(ChiTargetBufferManagerCreateData*) (.cfi)+92)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#06 pc 000000000010f398 /vendor/lib64/hw/com.qti.chi.override.so (ChiFeature2Base::CreateTargetBufferManagers()+3040)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#07 pc 000000000013a77c /vendor/lib64/hw/com.qti.chi.override.so (ChiFeature2Base::FinalizeInitialization(std::__1::vector<ChiFeatureFinalizedBufferOption, std::__1::allocator<ChiFeatureFinalizedBufferOption> > const&, std::__1::vector<ChiFeatureFinalizedBufferOption, std::__1::allocator<ChiFeatureFinalizedBufferOption> >&)+732)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#08 pc 0000000000159e18 /vendor/lib64/hw/com.qti.chi.override.so (ChiFeaturePoolManager::FinalizeFeatureInstances(FeaturePoolInputData const&, ChiFeature2VectorizedGraph const&, std::__1::vector<ChiFeature2Base*, std::__1::allocator<ChiFeature2Base*> >&)+9960)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#09 pc 0000000000175440 /vendor/lib64/hw/com.qti.chi.override.so (ChiFeature2GraphManager::Initialize(FeatureGraphManagerConfig*)+13928)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#10 pc 0000000000171c54 /vendor/lib64/hw/com.qti.chi.override.so (ChiFeature2GraphManager::Create(FeatureGraphManagerConfig*)+164)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#11 pc 00000000001aea88 /vendor/lib64/hw/com.qti.chi.override.so (Feature2Wrapper::CreateFeatureGraphManager()+912)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#12 pc 00000000001ad248 /vendor/lib64/hw/com.qti.chi.override.so (Feature2Wrapper::PostUsecaseCreated()+104)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#13 pc 000000000028026c /vendor/lib64/hw/com.qti.chi.override.so (AdvancedCameraUsecase::Initialize(LogicalCameraInfo*, camera3_stream_configuration*, UsecaseId)+18372)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#14 pc 000000000027ba3c /vendor/lib64/hw/com.qti.chi.override.so (AdvancedCameraUsecase::Create(LogicalCameraInfo*, camera3_stream_configuration*, UsecaseId)+852)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#15 pc 00000000002d0490 /vendor/lib64/hw/com.qti.chi.override.so (UsecaseFactory::CreateUsecaseObject(LogicalCameraInfo*, UsecaseId, camera3_stream_configuration*)+104)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#16 pc 00000000001fcfb8 /vendor/lib64/hw/com.qti.chi.override.so (ExtensionModule::InitializeOverrideSession(unsigned int, camera3_device const*, chi_hal_ops const*, camera3_stream_configuration*, int*, void**)+9816)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#17 pc 00000000001e8b58 /vendor/lib64/hw/com.qti.chi.override.so (chi_initialize_override_session(unsigned int, camera3_device const*, chi_hal_ops const*, camera3_stream_configuration*, int*, void**) (.cfi)+72)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#18 pc 00000000003504cc /vendor/lib64/hw/camera.qcom.so (CamX::HALDevice::ConfigureStreams(CamX::Camera3StreamConfig*)+1716)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#19 pc 0000000000335be4 /vendor/lib64/hw/camera.qcom.so (CamX::configure_streams(camera3_device const*, camera3_stream_configuration*) (.cfi)+2780)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#20 pc 000000000001c2cc /vendor/lib64/camera.device@3.4-impl.so (android::hardware::camera::device::V3_4::implementation::CameraDeviceSession::configureStreams_3_4_Impl(android::hardware::camera::device::V3_4::StreamConfiguration const&, std::__1::function<void (android::hardware::camera::common::V1_0::Status, android::hardware::camera::device::V3_4::HalStreamConfiguration const&)>, unsigned int, bool)+716)
09-10 14:08:36.948 29379 29407 I Deepinout : Camera#21 pc 00000000000215d8 /vendor/lib64/camera.device@3.5-impl.so (android::hardware::camera::device::V3_5::implementation::CameraDeviceSession::configureStreams_3_5(android::hardware::camera::device::V3_5::StreamConfiguration const&, std::__1::function<void (android::hardware::camera::common::V1_0::Status, android::hardware::camera::device::V3_4::HalStreamConfiguration const&)>)+228)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#22 pc 0000000000020d54 /vendor/lib64/camera.device@3.5-impl.so (android::hardware::camera::device::V3_5::implementation::CameraDeviceSession::TrampolineSessionInterface_3_5::configureStreams_3_5(android::hardware::camera::device::V3_5::StreamConfiguration const&, std::__1::function<void (android::hardware::camera::common::V1_0::Status, android::hardware::camera::device::V3_4::HalStreamConfiguration const&)>)+192)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#23 pc 0000000000031e08 /apex/com.android.vndk.v30/lib64/android.hardware.camera.device@3.5.so (android::hardware::camera::device::V3_5::BnHwCameraDeviceSession::_hidl_configureStreams_3_5(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+372)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#24 pc 0000000000032c78 /apex/com.android.vndk.v30/lib64/android.hardware.camera.device@3.5.so (android::hardware::camera::device::V3_5::BnHwCameraDeviceSession::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+1552)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#25 pc 00000000000942d8 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+68)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#26 pc 0000000000098270 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1076)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#27 pc 00000000000994b8 /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#28 pc 00000000000a855c /apex/com.android.vndk.v30/lib64/libhidlbase.so (android::hardware::PoolThread::threadLoop()+24)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#29 pc 00000000000154d0 /apex/com.android.vndk.v30/lib64/libutils.so (android::Thread::_threadLoop(void*)+260)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#30 pc 0000000000014d94 /apex/com.android.vndk.v30/lib64/libutils.so (thread_data_t::trampoline(thread_data_t const*)+412)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#31 pc 00000000000afd4c /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64)
09-10 14:08:36.949 29379 29407 I Deepinout : Camera#32 pc 0000000000050288 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64