测试内核版本:5.0.1,操作系统及版本:Unbuntu 19.04
测试结果:
节选:
[ 12.282381] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_dequeue 1870
[ 12.282382] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c vmci_qpair_dequev 3225
[ 12.282383] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_dequeue_locked 2619
[ 12.282384] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_memcpy_from_queue_iter 392
[ 12.282388] kernel: net/vmw_vsock/af_vsock.c vsock_stream_recvmsg 1694
[ 12.282389] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_dequeue 1870
[ 12.282389] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c vmci_qpair_dequev 3225
[ 12.282390] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_dequeue_locked 2619
[ 12.282391] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_memcpy_from_queue_iter 392
[ 12.282404] kernel: net/vmw_vsock/af_vsock.c vsock_stream_sendmsg 1554
[ 12.282406] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_enqueue 1882
[ 12.282406] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c vmci_qpair_enquev 3183
[ 12.282407] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_memcpy_to_queue_iter 344
[ 12.282409] kernel: net/vmw_vsock/vmci_transport.c __vmci_transport_send_control_pkt 212
[ 12.282409] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_peer_rid 120
[ 12.282410] kernel: drivers/misc/vmw_vmci/vmci_host.c vmci_host_code_active 114
[ 12.282411] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_guest_code_active 76
[ 12.282411] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_guest_code_active 76
[ 12.282412] kernel: drivers/misc/vmw_vmci/vmci_driver.c vmci_get_context_id 47
[ 12.282413] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_guest_code_active 76
[ 12.282413] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_get_vm_context_id 82
[ 12.282536] kernel: net/vmw_vsock/af_vsock.c vsock_stream_recvmsg 1694
[ 12.282539] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_dequeue 1870
[ 12.282540] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c vmci_qpair_dequev 3225
[ 12.282541] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_dequeue_locked 2619
[ 12.282542] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_memcpy_from_queue_iter 392
[ 12.282546] kernel: net/vmw_vsock/af_vsock.c vsock_stream_recvmsg 1694
[ 12.282547] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_dequeue 1870
[ 12.282548] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c vmci_qpair_dequev 3225
[ 12.282548] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_dequeue_locked 2619
[ 12.282549] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_memcpy_from_queue_iter 392
[ 12.282564] kernel: net/vmw_vsock/af_vsock.c vsock_stream_sendmsg 1554
[ 12.282566] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_enqueue 1882
[ 12.282566] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c vmci_qpair_enquev 3183
[ 12.282567] kernel: drivers/misc/vmw_vmci/vmci_queue_pair.c qp_memcpy_to_queue_iter 344
[ 12.282569] kernel: net/vmw_vsock/vmci_transport.c __vmci_transport_send_control_pkt 212
[ 12.282570] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_peer_rid 120
[ 12.282570] kernel: drivers/misc/vmw_vmci/vmci_host.c vmci_host_code_active 114
[ 12.282571] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_guest_code_active 76
[ 12.282572] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_guest_code_active 76
[ 12.282573] kernel: drivers/misc/vmw_vmci/vmci_driver.c vmci_get_context_id 47
[ 12.282573] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_guest_code_active 76
[ 12.282574] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_get_vm_context_id 82
[ 12.282605] kernel: net/vmw_vsock/af_vsock.c vsock_stream_recvmsg 1694
[ 12.282657] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_interrupt 379
[ 12.282660] kernel: drivers/misc/vmw_vmci/vmci_guest.c vmci_dispatch_dgs 214
[ 12.282785] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_allow 672
[ 12.282786] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_peer_rid 120
[ 12.282803] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_allow 672
[ 12.282804] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_peer_rid 120
[ 12.282805] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_stream_allow 672
[ 12.282805] kernel: net/vmw_vsock/vmci_transport.c vmci_transport_peer_rid 120
操作原理:
在函数体第一行加入这行:
问题来了:
1、在哪些函数里边添加呢?
2、这个函数调用是存在头文件依赖的,如果头文件未包含会编译报错?
3、如果我们在所有 .c文件的函数里边添加也会有问题,因为内核执行的时候说不定这个函数还未声明,更不能调用了
当前我的处理办法是这样的:
1、把所有C文件(头文件不需要添加)查找出来;
2、把所有C文件里边调用到pr_xxx函数的C文件找出来;
3、把找到的这些C文件所有函数所在的所有行找出来;
4、在一个C文件中从行编号大的开始往行编号小(为啥是从编号大往编号小的方向呢?因为你先在编号小的行添加后,编号大的行的行编号就变了)的方向加入如下字符串:
PrintLogString='\ \ \ \ pr_info("%s %s %d\\n", __FILE__, __FUNCTION__, __LINE__); '
添加打印日志后如下:
5、当所有修改完成后,重新编译内核,重启电脑
6、重启完电脑后打开/var/log/dmesg文件就能看到最开始的测试结果
实际测试的时候发现一些问题:
1、找出函数行可能有些问题,需要去除一些误行;
2、重新编译内核后,重启电脑,发现每次重启后日志都不一样,我重启了好几十次,有点蛋疼,这个问题还没空定位;
3、生成日志文件比原来大不少;
4、我们现在添加日志的地方只在调用pr_xxx 函数的C文件里边添加的,还有很多文件没有添加,一共31996个,我们当前只添加了6262个:
shell脚本及测试结果归档:
https://github.com/FuckedName/LinuxKernelStartDetails
欢迎转载,是否注明出处无所谓。