adb查看内核LOG信息
来源:互联网 发布:mac如何隐藏文件 编辑:程序博客网 时间:2024/05/09 18:51
在调试内核的时候,如果用串口总要费县到串口,如果能直接用adb logcat 命令就好了,插上USB就可以了,也省去了飞线的步骤:
如何才能实现呢,经过搜索找到了如下的方法:
更改logcat.cpp文件:
第一步:添加头文件 #include <sys/klog.h> //add
第二步:添加宏 #define KERNEL_TAG "Kernel"
第三部:修改readLogLines函数
在函数中添加红色部分函数就可以了,其他不变
static void readLogLines(log_device_t* devices)
{
log_device_t* dev;
int max = 0;
int ret;
int queued_lines = 0;
bool sleep = true;
char buffer[256] = {0}; //add by zhaofei
int result;
fd_set readset;
for (dev=devices; dev; dev = dev->next) {
if (dev->fd > max) {
max = dev->fd;
}
}
while (1) {
do {
timeval timeout = { 0, 5000 }; // If we oversleep it's ok, i.e. ignore EINTR.
FD_ZERO(&readset);
for (dev=devices; dev; dev = dev->next) {
FD_SET(dev->fd, &readset);
}
result = select(max + 1, &readset, NULL, NULL, sleep ? NULL : &timeout);
} while (result == -1 && errno == EINTR);
if (result >= 0) {
for (dev=devices; dev; dev = dev->next) {
if (FD_ISSET(dev->fd, &readset)) {
queued_entry_t* entry = new queued_entry_t();
ret = read(dev->fd, entry->buf, LOGGER_ENTRY_MAX_LEN);
if (ret < 0) {
if (errno == EINTR) {
delete entry;
goto next;
}
if (errno == EAGAIN) {
delete entry;
break;
}
perror("logcat read");
exit(EXIT_FAILURE);
}
else if (!ret) {
fprintf(stderr, "read: Unexpected EOF!\n");
exit(EXIT_FAILURE);
}
entry->entry.msg[entry->entry.len] = '\0';
dev->enqueue(entry);
++queued_lines;
#if 1 //read kernel log
if((ret = klogctl(9, buffer, sizeof(buffer))) > 0) {
if((ret = klogctl(2, buffer, sizeof(buffer))) > 0) {
entry->entry.tid = 0;
entry->entry.pid = getpid();
entry->entry.msg[0] = ANDROID_LOG_INFO;
strcpy(entry->entry.msg+1, KERNEL_TAG);
strncpy(entry->entry.msg+1+sizeof(KERNEL_TAG), buffer, ret);
entry->entry.len = 1 + sizeof(KERNEL_TAG) + ret + 1;
entry->entry.msg[entry->entry.len] = '/0';
printNextEntry(dev);
}
}
#endif
}
}
if (result == 0) {
// we did our short timeout trick and there's nothing new
// print everything we have and wait for more data
sleep = true;
while (true) {
chooseFirst(devices, &dev);
if (dev == NULL) {
break;
}
if (g_tail_lines == 0 || queued_lines <= g_tail_lines) {
printNextEntry(dev);
} else {
skipNextEntry(dev);
}
--queued_lines;
}
// the caller requested to just dump the log and exit
if (g_nonblock) {
exit(0);
}
} else {
// print all that aren't the last in their list
sleep = false;
while (g_tail_lines == 0 || queued_lines > g_tail_lines) {
chooseFirst(devices, &dev);
if (dev == NULL || dev->queue->next == NULL) {
break;
}
if (g_tail_lines == 0) {
printNextEntry(dev);
} else {
skipNextEntry(dev);
}
--queued_lines;
}
}
}
next:
;
}
}
第四步:连接USB 进入调试模式,打开终端 输入命令 adb logcat
此时在内核中用函数PRINTK输出的TRACE就能打印出来了,
如何治显示内核部分的LOG呢,可以用命令
adb logcat -s Kernel
-s参数说明只显示包含LOG_TAG 为Kernel的,这样就只显示内核LOG了
如何才能实现呢,经过搜索找到了如下的方法:
更改logcat.cpp文件:
第一步:添加头文件 #include <sys/klog.h> //add
第二步:添加宏 #define KERNEL_TAG "Kernel"
第三部:修改readLogLines函数
在函数中添加红色部分函数就可以了,其他不变
static void readLogLines(log_device_t* devices)
{
log_device_t* dev;
int max = 0;
int ret;
int queued_lines = 0;
bool sleep = true;
char buffer[256] = {0}; //add by zhaofei
int result;
fd_set readset;
for (dev=devices; dev; dev = dev->next) {
if (dev->fd > max) {
max = dev->fd;
}
}
while (1) {
do {
timeval timeout = { 0, 5000 }; // If we oversleep it's ok, i.e. ignore EINTR.
FD_ZERO(&readset);
for (dev=devices; dev; dev = dev->next) {
FD_SET(dev->fd, &readset);
}
result = select(max + 1, &readset, NULL, NULL, sleep ? NULL : &timeout);
} while (result == -1 && errno == EINTR);
if (result >= 0) {
for (dev=devices; dev; dev = dev->next) {
if (FD_ISSET(dev->fd, &readset)) {
queued_entry_t* entry = new queued_entry_t();
ret = read(dev->fd, entry->buf, LOGGER_ENTRY_MAX_LEN);
if (ret < 0) {
if (errno == EINTR) {
delete entry;
goto next;
}
if (errno == EAGAIN) {
delete entry;
break;
}
perror("logcat read");
exit(EXIT_FAILURE);
}
else if (!ret) {
fprintf(stderr, "read: Unexpected EOF!\n");
exit(EXIT_FAILURE);
}
entry->entry.msg[entry->entry.len] = '\0';
dev->enqueue(entry);
++queued_lines;
#if 1 //read kernel log
if((ret = klogctl(9, buffer, sizeof(buffer))) > 0) {
if((ret = klogctl(2, buffer, sizeof(buffer))) > 0) {
entry->entry.tid = 0;
entry->entry.pid = getpid();
entry->entry.msg[0] = ANDROID_LOG_INFO;
strcpy(entry->entry.msg+1, KERNEL_TAG);
strncpy(entry->entry.msg+1+sizeof(KERNEL_TAG), buffer, ret);
entry->entry.len = 1 + sizeof(KERNEL_TAG) + ret + 1;
entry->entry.msg[entry->entry.len] = '/0';
printNextEntry(dev);
}
}
#endif
}
}
if (result == 0) {
// we did our short timeout trick and there's nothing new
// print everything we have and wait for more data
sleep = true;
while (true) {
chooseFirst(devices, &dev);
if (dev == NULL) {
break;
}
if (g_tail_lines == 0 || queued_lines <= g_tail_lines) {
printNextEntry(dev);
} else {
skipNextEntry(dev);
}
--queued_lines;
}
// the caller requested to just dump the log and exit
if (g_nonblock) {
exit(0);
}
} else {
// print all that aren't the last in their list
sleep = false;
while (g_tail_lines == 0 || queued_lines > g_tail_lines) {
chooseFirst(devices, &dev);
if (dev == NULL || dev->queue->next == NULL) {
break;
}
if (g_tail_lines == 0) {
printNextEntry(dev);
} else {
skipNextEntry(dev);
}
--queued_lines;
}
}
}
next:
;
}
}
第四步:连接USB 进入调试模式,打开终端 输入命令 adb logcat
此时在内核中用函数PRINTK输出的TRACE就能打印出来了,
如何治显示内核部分的LOG呢,可以用命令
adb logcat -s Kernel
-s参数说明只显示包含LOG_TAG 为Kernel的,这样就只显示内核LOG了
阅读全文
0 0
- adb查看内核LOG信息
- adb查看内核LOG信息
- adb查看内核LOG信息
- adb 查看log信息中的 Tag 信息
- adb 查看log
- adb获取log信息
- adb logcat命令查看 log
- adb shell 查看信息
- 没有USB线连接PC的情况下,通过WIFI ADB的方式查看LOG信息
- vxworks下log信息查看
- Log 信息记录与查看
- Log 信息记录与查看
- 查看linux内核信息
- 查看SAP内核信息
- android adb log 查看分析工具
- linux adb 控制内核打印log
- adb 打印指定进程的log信息
- 查看当前操作系统内核信息
- Java泛型详解,通俗易懂
- 汉语词性对照表[北大标准/中科院标准]
- ubuntu打印设置
- 你还需要什么来管理自己的数据?
- 简述Spring容器与SpringMVC的容器的联系与区别
- adb查看内核LOG信息
- 基于Unity3D平台的三维虚拟城市研究与应用
- 181. Employees Earning More Than Their Managers--自连接
- document.location和window.location有什么区别
- 内存管理(Linux内核源码分析)
- 密码学笔记2 数论之趣
- Java简介
- R
- 泛型限制基础