Android9源码输出linux内核pr_debug调试信息
默认编译出来的linux内核要info以上的信息才会显示,要修改下代码才能让pr_debug的内容能输出到dmesg。
以修改网络协议栈中的pr_debug内容为例:
$ cd AndroidP/
在Makefile中增加编译选项DEBUG(当然直接在.c文件的开头部分定义也可以#define DEBUG,就是得每个文件去修改):
$ vi kernel-4.9/net/Makefile
subdir-ccflags-y += -Werror -DDEBUG
这样整个net目录下的.c文件中的pr_debug内容都可以打印了。
然后重新编译kernel;
$ source build/envsetup.sh
$ lunch xxxx
$ mmm showcommands kernel-4.9/:kernel
$ make bootimage
输出在:out/target/product/xxxx/boot.img
然后把boot.img烧录进设备,重启后即可通过dmesg查看:
dos> adb root
dos> adb shell
# dmesg -w
[11991.723617] (1)[15:ksoftirqd/1]tuple ffffffeaa15ca658: 6 127.0.0.1:22342 -> 127.0.0.1:38674
[11991.723631] (1)[15:ksoftirqd/1]seq=686264045 ack=1519905798+(0) sack=1519905798+(0) win=512 end=686265245
[11991.723637] (1)[15:ksoftirqd/1]tcp_in_window: sender end=686264045 maxend=686729453 maxwin=131072 scale=8 receiver end=1519905798 maxend=1520036870 maxwin=465408 scale=8
[11991.723640] (1)[15:ksoftirqd/1]tcp_in_window:
[11991.723643] (1)[15:ksoftirqd/1]tuple ffffffeaa15ca658: 6 127.0.0.1:22342 -> 127.0.0.1:38674
[11991.723652] (1)[15:ksoftirqd/1]seq=686264045 ack=1519905798+(0) sack=1519905798+(0) win=512 end=686265245
[11991.723657] (1)[15:ksoftirqd/1]tcp_in_window: sender end=686264045 maxend=686729453 maxwin=131072 scale=8 receiver end=1519905798 maxend=1520036870 maxwin=465408 scale=8
[11991.723661] (1)[15:ksoftirqd/1]tcp_in_window: I=1 II=1 III=1 IV=1
[11991.723667] (1)[15:ksoftirqd/1]tcp_in_window: res=1 sender end=686265245 maxend=686729453 maxwin=131072 receiver end=1519905798 maxend=1520036870 maxwin=465408
[11991.723671] (1)[15:ksoftirqd/1]tcp_conntracks:
[11991.723673] (1)[15:ksoftirqd/1]tuple ffffffeaa15ca658: 6 127.0.0.1:22342 -> 127.0.0.1:38674
[11991.723681] (1)[15:ksoftirqd/1]syn=0 ack=1 fin=0 rst=0 old=3 new=3
[11991.723631] (1)[15:ksoftirqd/1]seq=686264045 ack=1519905798+(0) sack=1519905798+(0) win=512 end=686265245
[11991.723637] (1)[15:ksoftirqd/1]tcp_in_window: sender end=686264045 maxend=686729453 maxwin=131072 scale=8 receiver end=1519905798 maxend=1520036870 maxwin=465408 scale=8
[11991.723640] (1)[15:ksoftirqd/1]tcp_in_window:
[11991.723643] (1)[15:ksoftirqd/1]tuple ffffffeaa15ca658: 6 127.0.0.1:22342 -> 127.0.0.1:38674
[11991.723652] (1)[15:ksoftirqd/1]seq=686264045 ack=1519905798+(0) sack=1519905798+(0) win=512 end=686265245
[11991.723657] (1)[15:ksoftirqd/1]tcp_in_window: sender end=686264045 maxend=686729453 maxwin=131072 scale=8 receiver end=1519905798 maxend=1520036870 maxwin=465408 scale=8
[11991.723661] (1)[15:ksoftirqd/1]tcp_in_window: I=1 II=1 III=1 IV=1
[11991.723667] (1)[15:ksoftirqd/1]tcp_in_window: res=1 sender end=686265245 maxend=686729453 maxwin=131072 receiver end=1519905798 maxend=1520036870 maxwin=465408
[11991.723671] (1)[15:ksoftirqd/1]tcp_conntracks:
[11991.723673] (1)[15:ksoftirqd/1]tuple ffffffeaa15ca658: 6 127.0.0.1:22342 -> 127.0.0.1:38674
[11991.723681] (1)[15:ksoftirqd/1]syn=0 ack=1 fin=0 rst=0 old=3 new=3
可以发现输出会非常多。