zoukankan      html  css  js  c++  java
  • 让adb logcat打印内核调试信息


    让adb logcat打印内核调试信息
    Wednesday, October 14th, 2009 | Author: admin | ? Edit ?


    转载时请注明出处和作者联系方式
    文章出处:http://www.limodev.cn/blog
    作者联系方式:李先静 <xianjimli at hotmail dot com>

    在默认情况下,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。对我们来说已经够用了,有需要的朋友可以继续完善。

  • 相关阅读:
    linux系统基本目录的介绍
    vue 组件之间的通信-父组件给子组件传递数据
    postgresql数据库查询特定日期的数据
    使用HttpRequest调用第三方接口
    postgresql数据库中的 rownum
    mybatis框架,执行插入语句的时候,如果没有字段传过来就赋值为空 进行判断
    postgresql数据库left join将主表中的数据查询出多条的解决办法
    前后端交互 -精度丢失问题解决
    vue找页面
    mysql语法 join on 表示什么
  • 原文地址:https://www.cnblogs.com/zhangyunlin/p/6167473.html
Copyright © 2011-2022 走看看