目前有的的板子一般没有串口线,只有USB线。这样一来,查看log信息一般都用 logcat 命令 ,默认情况下,logcat 命令
打印的一般都是使用程序的信息。如果打印内核信息,可以通过以下方法:
(1)在adb shell下输入dmesg 命令可以查看; (2 )在 adb shell 下, cat proc/kmsg; 以上方式只能看到部分内核信息;如果查看更全面的log信息,可以通过以下方式; (3)通过修改 /system/core/logcat.cpp 文件的readLogLines函数,使信息显示完全。 static void readLogLines(int logfd) { // --start--Added by wls char buffer[256]={0}; // ---end --- while (1) { unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1] __attribute__((aligned(4))); struct logger_entry *entry = (struct logger_entry *) buf; int ret; ret = read(logfd, entry, LOGGER_ENTRY_MAX_LEN); if (ret < 0) { if (errno == EINTR) continue; if (errno == EAGAIN) break; perror("logcat read"); exit(EXIT_FAILURE); } else if (!ret) { fprintf(stderr, "read: Unexpected EOF!\n"); exit(EXIT_FAILURE); } /* NOTE: driver guarantees we read exactly one full entry */ entry->msg[entry->len] = '\0'; if (g_printBinary) { printBinary(entry); } else { (void) processBuffer(entry); } /*------start ----Added by WLS----------- */ if((ret=klogctl(9,buffer,sizeof(buffer)))>0) { if((ret = klogctl(2,buffer,sizeof(buffer)))>0) { entry ->tid = 0; entry ->pid = getpid(); /*priority*/ entry ->msg[0] = ANDROID_LOG_INFO; /*tag*/ strcpy(entry->msg+1,KERNEL_TAG); /*message*/ strncpy(entry->msg+1+sizeof(KERNEL_TAG),buffer,ret); entry->len = 1+sizeof(KERNEL_TAG)+ret+1; entry->msg[entry->len] = '\0'; if(g_printBinary){ printBinary(entry); }else{ (void)processBuffer(entry); } } } /* ------end ---Added by WLS-----------*/ } } * **注意在文件开头,加上宏定义 #define KERNEL_TAG "kernel" 关于 logcat 几个常用命令: logcat & : 在后台运行 logcat -f 或者 > >> 输出到文件 logcat -s 设置过滤器,得到想要的log信息 ;如 logcat -s TAG: I (W or E) ........... 如有更多更好的方法,请补充! |
使用 logcat 命令打印内核信息
最新推荐文章于 2023-03-16 15:23:56 发布