在cpp打印backtrace对于了解繁杂的系统很有用。例如Android什么时候获取到ServiceManager的。我们可以打下backtrace看看。
在frameworks/native/libs/binder/ProcessState.cpp
sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/)
{
CallStack stack("Fuck"); //添加这句
return getStrongProxyForHandle(0);
}
结果如下,可以看到trace啦!
01-17 13:05:08.626 1993 1993 D Fuck : #00 pc 0000000000075fd4 /system/lib64/libbinder.so (android::ProcessState::getContextObject(android::sp<android::IBinder> const&)+112)
01-17 13:05:08.626 1993 1993 D Fuck : #01 pc 0000000000058464 /system/lib64/libbinder.so (android::defaultServiceManager()+136)
01-17 13:05:08.626 1993 1993 D Fuck : #02 pc 000000000003ad9c /system/lib64/libaudioclient.so (android::AudioSystem::get_audio_flinger()+104)
01-17 13:05:08.626 1993 1993 D Fuck : #03 pc 000000000003c3fc /system/lib64/libaudioclient.so (android::AudioSystem::getParameters(int, android::String8 const&)+96)
01-17 13:05:08.626 1993 1993 D Fuck : #04 pc 000000000014be68 /system/lib64/libandroid_runtime.so
01-17 13:05:08.626 1993 1993 D Fuck : #05 pc 0000000000519ffc /system/framework/arm64/boot-framework.oat (offset 0x656000)