博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android LOG使用
阅读量:2383 次
发布时间:2019-05-10

本文共 5783 字,大约阅读时间需要 19 分钟。

1. 场景

想调试zygote的程序,C++写的,需要AVLOG宏打印调试信息。

2. AVLOG

打开AVLOG

在文件system/core/liblog/include/log/log_main.h中:

#ifndef LOG_NDEBUG                                                              #ifdef NDEBUG                                                                   #define LOG_NDEBUG 1                                                            #else                                                                           #define LOG_NDEBUG 0                                                            #endif                                                                          #endif

在文件frameworks/ex/framesequence/jni/utils/log.h定义如下:

/*                                                                                  * Simplified macro to send a verbose log message using the current LOG_TAG.        */                                                                                #ifndef ALOGV                                                                      #if /*                                                                                  * Simplified macro to send a verbose log message using the current LOG_TAG.        */                                                                                #ifndef ALOGV                                                                      #if LOG_NDEBUG                                                                     #define ALOGV(...)   ((void)0)                                                                        #else                                                                              #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))                 #endif                                                                             #endif

如果打开ALOGV,满足两个条件:1. 没有定义ALOGV 2. LOG_NDEBUG为0。

ALOGV没有定义,显然LOG_NDEBUG为0满足进行。

在log_main.h中,LOG_NDEBUG为0,需要满足两个条件:

1)没有定义LOG_NDEBUG。
2)没有定义NDEBUG。

在app_main.cpp添加如下语句:

8 #define LOG_TAG "appproc"                                                         9                                                                                  10 #undef LOG_NDEBUG                                                                11 #undef NDEBUG                                                                    12                                                                                  13 #include 
14 #include
15 #include
16 #include
17 #include

添加10行和11行语句,便可以打开调试信息。

3. 测试

代码调试信息:

190 int main(int argc, char* const argv[])                                                                   191 {                                                                                                        192     //if (!LOG_NDEBUG) {                                                                                 193     if(1) {                                                                                              194       String8 argv_String;                                                                               195       for (int i = 0; i < argc; ++i) {                                                                   196         argv_String.append("\"");                                                                        197         argv_String.append(argv[i]);                                                                     198         argv_String.append("\" ");                                                                       199       }                                                                                                  200       ALOGV("app_process main with argv: %s", argv_String.string());            201     }                                                                                                    202                                                                                                          203     AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv));               204     // Process command line arguments                                                                    205     // ignore argv[0]                                                                                    206     argc--;                                                                                              207     argv++;                                                                                              208     ALOGV("tom app_run=%d", __LINE__);  354     if (zygote) {                                                               355     ALOGV("tom app_run=%d", __LINE__);                                          356         runtime.start("com.android.internal.os.ZygoteInit", args, zygote);      357     } else if (className) {                                                     358     ALOGV("tom app_run=%d", __LINE__);                                          359         runtime.start("com.android.internal.os.RuntimeInit", args, zygote);     360     } else {                                                                    361     ALOGV("tom app_run=%d", __LINE__);                                          362         fprintf(stderr, "Error: no class name or --zygote supplied.\n");        363         app_usage();                                                            364         LOG_ALWAYS_FATAL("app_process: no class name or --zygote supplied.");   365     }                                                                           366 }

通过logcat查看调试信息,因为LOG_TAG是appproc。

123
过滤LOG_TAG=appproc

logcat -s appproc

在这里插入图片描述

转载地址:http://fofab.baihongyu.com/

你可能感兴趣的文章
不vista下安装oracle10g(r2)注意事项
查看>>
文件列表输出到文件
查看>>
Ubuntu(804) SSH远程管理服务器安装配置
查看>>
android源码
查看>>
使用Hadoop的JAVA API远程访问HDFS
查看>>
Linux下任务调度服务crond使用
查看>>
ZeroMQ的订阅发布(publish-subscribe)模式
查看>>
使用redis存储全球IP库
查看>>
Snappy Java API简介
查看>>
C/C++中正则表达式库RE2的使用
查看>>
HBase Java API(1.2.X)使用简介
查看>>
Java:实现比较接口时,应该全面的进行各种情况的比较
查看>>
python3.*下用mob_pbxproj自动化修改配置
查看>>
使用fir打包,测试跳转安装的坑
查看>>
版本号大小判断,适用规则(X.X.X.X........)
查看>>
关于Objective-C方法签名规则的说明
查看>>
libxml2.dylb 添加后找不到<libxml/tree.h> 头文件
查看>>
关于 [[self class] alloc]的理解
查看>>
Eclipse导入Web项目后代码不报错但项目报错(左上角有红叉)解决方案
查看>>
List、Set、数据结构、Collections
查看>>