其他
如何阅读 Android 系统源码之 C/C++ 篇
source build/envsetup.sh
lunch aosp_x86_64-eng #选择一个合适的 Product
export SOONG_GEN_CMAKEFILES=1
export SOONG_GEN_CMAKEFILES_DEBUG=1
make -j16
find . -name "SurfaceFlinger*"
./frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp
./frameworks/native/services/surfaceflinger/SurfaceFlingerProperties.cpp
./frameworks/native/services/surfaceflinger/SurfaceFlinger.h
./frameworks/native/services/surfaceflinger/SurfaceFlingerProperties.h
./frameworks/native/services/surfaceflinger/SurfaceFlingerFactory.h
.......
打印 Log + 打印调用堆栈 使用 CLion 调试
#include "log/log.h"
//直接 define LOG_TAG 会报已定义错误,因为 SurFaceFlinger 模块的 Android.bp 已经定义了 LOG_Tag
//下面这样定义就不会出错了
#ifdef LOG_TAG
#undef LOG_TAG
#define LOG_TAG "yuandaima_sf"
#endif
//打印堆栈的头文件
#include <utils/CallStack.h>
//在 main 函数中打印信息
int main(int, char**) {
//打印日志
ALOGD("surfaceflinger is starting");
//打印堆栈
android::CallStack callStack(LOG_TAG, 1);
//省略后面的代码
//......
}
05-11 09:54:10.291 1531 1531 D yuandaima_sf: surfaceflinger is starting
05-11 09:54:10.296 1531 1531 D yuandaima_sf: #00 pc 00000000000030a1 /system/bin/surfaceflinger (main+65)
05-11 09:54:10.296 1531 1531 D yuandaima_sf: #01 pc 000000000008a985 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+117)
system 1406 1 14116 5532 binder_ioctl 0 S servicemanager
system 1407 1 21764 9772 SyS_epoll_wait 0 S hwservicemanager
system 1408 1 14816 2584 binder_ioctl 0 S vndservicemanage
adb shell gdbserver64 :1235 --attach 1406