您的位置:首页 > 移动开发 > Android开发

adb logcat打印内核调试信息

2012-08-07 15:16 555 查看
在调试内核的时候,如果用串口总要费县到串口,如果能直接用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(); 
                
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息