Android基础:cpp打印backtrace

在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)

参考:https://www.baidu.com/link?url=8Y4zcA_5EdyLUVB6jafQuH4vk3s68wrPchfLO2LoJBcX8LFLIJFvs1maMvysmFagFt2vYv0GOljgh1f0pzz5ra&wd=&eqid=971b8f3a0006778b000000065abb5cb5

    原文作者:九九叔
    原文地址: https://www.jianshu.com/p/83f0b1c3fe14
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞