Android中的Logcat方法查看内核的日志
2010-08-23 16:19
537 查看
步骤如下:
1.在Android的源码中(目标路径为:system/core/logcat/logcat.cpp),将其此logcat.cpp文件中的static void readLogLines(int logfd)函数作出如下修改:
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);
}
}
}
}
}
当然经过此步的修改后,在源码编译中一定会出现问题,会出现什么呢?答案是在编译时找不到相应的类库。那么怎么办呢?
不要着急,第2步会说明。
2.在如上修改的.cpp文件的头文件中加入如下两个头文件:
#include <sys/klog.h>
#define KERNEL_TAG "Kernel"
great! 此时将可以顺利通过编译了哦。
3.即将修改后的源文件进行整体编译一边,方法见源码编译的相关方法。边以后生成的logcat文件放在/android/out/host
/common/obj/JAVA_LIBRARIES/ddmuilib_intermediates/classes/com/android
/ddmuilib/logcat目录下。
4.将上述目录下的logcat文件adb push到你的手机上的/system/bin目录下,然后adb reboot一下手机。之后就可以正常执行logcat了,相应的能够打印出kernel下的相关日志哦。
1.在Android的源码中(目标路径为:system/core/logcat/logcat.cpp),将其此logcat.cpp文件中的static void readLogLines(int logfd)函数作出如下修改:
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);
}
}
}
}
}
当然经过此步的修改后,在源码编译中一定会出现问题,会出现什么呢?答案是在编译时找不到相应的类库。那么怎么办呢?
不要着急,第2步会说明。
2.在如上修改的.cpp文件的头文件中加入如下两个头文件:
#include <sys/klog.h>
#define KERNEL_TAG "Kernel"
great! 此时将可以顺利通过编译了哦。
3.即将修改后的源文件进行整体编译一边,方法见源码编译的相关方法。边以后生成的logcat文件放在/android/out/host
/common/obj/JAVA_LIBRARIES/ddmuilib_intermediates/classes/com/android
/ddmuilib/logcat目录下。
4.将上述目录下的logcat文件adb push到你的手机上的/system/bin目录下,然后adb reboot一下手机。之后就可以正常执行logcat了,相应的能够打印出kernel下的相关日志哦。
相关文章推荐
- Android中的Logcat方法查看内核的日志
- logcat命令使用方法和查看android系统日志缓冲区内容的方法
- logcat命令使用方法和查看android系统日志缓冲区内容的方法
- Android查看logcat的方法
- Android开发之在程序中时时获取logcat日志信息的方法(附demo源码下载)
- Android之如何用cmd方法查看logcat
- 在Android界面上显示和获取Logcat日志输出的方法
- Android 查看 无wifi/usb设备的logcat方法
- 用 logcat 命令来查看 android 系统日志缓冲区的内容
- 用 logcat 命令来查看 android 系统日志缓冲区的内容
- Android开发系列:查看LogCat日志
- 关于小米手机开发中,不能打印、查看logcat日志的解决方法。
- android真机调试 logcat日志不输出或者输出内容较少时解决方法
- Android 日志系统logcat内核代码分析
- 用 logcat 命令来查看 android 系统日志缓冲区的内容
- Logcat__查看Android系统日志
- Android 查看 无wifi/usb设备的logcat方法
- 用 logcat 命令来查看 android 系统日志缓冲区的内容
- android studio代码混淆后,查看服务器端错误日志方法
- 用 logcat 命令来查看 android 系统日志缓冲区的内容