Linux入门教程:Linux内核模块调试

  1. 开启虚拟机,虚拟机运行到 kgdb: Waiting for connection from remote gdb

  2. 在Host机上运行: socat tcp-listen:8888 /tmp/vbox2, 其中/tmp/vbox2为管道文件,它是目标机串口的重定向目的文件,socat将这个管道文件又重定向到tcp socket的8888端口。

  3. 开启一个新的虚拟终端,cd path/to/kernel/source/tree, 然后执行gdb ./vmlinux

  输出

  GNU gdb 6.8-debian

  Copyright (C) 2008 Free Software Foundation, Inc.

  License GPLv3+: GNU GPL version 3 or later <>

  This is free software: you are free to change and redistribute it.

  There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

  and "show warranty" for details.

  This GDB was configured as "i486-linux-gnu"...

  (gdb) set-remote

  set remote baud rate to 115200c/s

  set remote target to local tcp socket

  kgdb_breakpoint () at kernel/kgdb.c:1721

  1721        wmb(); /* Sync point after breakpoint */

  (gdb) c

  Continuing.

  目标机会一直启动,直到提示输入用户名密码。

  4. 进入目标机,输入用户名密码(推荐使用字符界面下的root用户),输入g命令,目标机被断下,控制移交到Host机中的gdb中。(目标机root的用户目录中的.bashrc中添加一行alias g='echo g>/proc/sysrq-trigger')

  5. 在Host机中的gdb中

  (gdb) set-mod-break

  set breakpoint in system module init function

  Breakpoint 1 at 0xc014bac5: file kernel/module.c, line 2288.

  (gdb) c

  Continuing.

  6. 在目标机中

  insmod klogger2.ko

  目标机再次断下,控制权移交Host机中的gdb

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/25146.html