转载时请注明出处和作者
作者 :李先静
在默认情况下,adb logcat只能显示应用程序的调试信息,我把logcat.cpp修改了一下,让它同时可以打印内核调试信息:
system/core/logcat/logcat.cpp
static void readLogLines(int logfd)
{
char buffer[256] = {0};
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);
}
/*读入内核调试信息*/
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);
}
}
}
}
}
这里没有把内核调试信息的级别转换成Androind的LOG级别,全部使用了ANDROID_LOG_INFO级别,进程ID用了当前的进程ID。对我们来说已经够用了,有需要的朋友可以继续完善。
让adb logcat打印内核调试信息
原创
©著作权归作者所有:来自51CTO博客作者ZLG李先静的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:加快Android单模块编译
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
日志打印
日志打印
日志打印 Spring日志 日志框架选择与转换 -
adb shell logcat
使用 logcat 命令 查看和跟踪系统日志缓冲区的命令logcat的一般用法是:[adb] logcat [<option>] ... [<filter-spec>] ... 下文介绍过滤器和命令选项,详细
字符串 过滤器 缓冲区 优先级 adb shell logcat 跟踪 -
adb shell 命令详解,android, adb logcatadb shell 命令详解 android adb 搜索 删除文件
-
Logcat打印调试信息
Logcat打印调试信息
android bug调试 错误信息 -
dos保存adb logcat读取的Android信息
由于dos下用logcat直接看Android系统信息不方便,眼花缭乱,眼神真心不好使,于是觉得dos下面应该有办法能够将logcat信息保存下来,于是找到这个重定向的方式。
android系统 解决方法 android 重定向 android手机