In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to debug the linux kernel module. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
1. Start the virtual machine and run it to kgdb: Waiting for connection from remote gdb
two。 Run on the host machine: socat tcp-listen:8888 / tmp/vbox2, where / tmp/vbox2 is the pipe file, which is the redirect destination file for the serial port of the target machine, and socat redirects the pipe file to port 8888 of tcp socket.
3. Open a new virtual terminal, cd path/to/kernel/source/tree, and execute gdb. / vmlinux
Output
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.
The target machine starts until you are prompted for a user name and password.
4. Enter the target machine, enter the user name and password (it is recommended to use the root user under the character interface), enter the g command, the target machine is cut off, and control is transferred to the gdb in the host machine. (add a line alias g='echo g > / proc/sysrq-trigger' to .bashrc in the user directory of the target machine root)
5. In the gdb in the host machine
(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. In the target machine
Insmod klogger2.ko
The target machine is cut off again, and control is transferred to the gdb in the host machine.
7. In the gdb in the host machine
[New Thread 4693]
[Switching to Thread 4693]
Breakpoint 1, sys_init_module (umod=0x0, len=0, uargs=0x0)
At kernel/module.c:2288
2288 if (mod- > init! = NULL)
(gdb) print-mod-segment
Name:.note.gnu.build-id Address:0xdf977058
Name:.text Address:0xdf975000
Name:.rodata Address:0xdf977080
Name:.rodata.str1.4 Address:0xdf9774b4
Name:.rodata.str1.1 Address:0xdf977522
Name:.parainstructions Address:0xdf977a00
Name:.data Address:0xdf978440
Name:.gnu.linkonce.this_module Address:0xdf978480
Name:.bss Address:0xdf978a00
Name:.symtab Address:0xdf977a08
Name:.strtab Address:0xdf978078
(gdb) add-symbol-file / home/done/programs/linux-kernel/vlogger/klogger2.ko 0xdf975000-s .data 0xdf978440-s .bss 0xdf978a00
Add symbol table from file "/ home/done/programs/linux-kernel/vlogger/klogger2.ko" at
.text _ addr = 0xdf975000
.data _ addr = 0xdf978440
.bss _ addr = 0xdf978a00
(y or n) y
Reading symbols from / home/done/programs/linux-kernel/vlogger/klogger2.ko...done.
(gdb) b hook_init
Breakpoint 2 at 0xdf976d19: file / home/done/programs/linux-kernel/vlogger/hook.c, line 255.
(gdb)
You can debug your own LKM modules.
The initialization configuration file of gdb is attached ~ / .gdbinit
Define set-remote
Echo set remote baud rate to 115200c/s\ n
Set remotebaud 115200
Echo set remote target to local tcp socket\ n
Target remote tcp:localhost:8888
End
Define set-mod-break
Echo set breakpoint in system module init function\ n
Break kernel/module.c:2288
End
Define print-mod-segment
Set $sect_num=mod- > sect_attrs- > nsections
Set $cur=0
While $cur
< $sect_num printf "Name:%-s Address:0x%x\n",mod->Sect_attrs- > attrs [$cur]-> name,mod- > sect_attrs- > attrs [$cur]-> address
Set $cur=$cur+1
End
End
Postscript: gdb debugging script is really difficult to write, simple string variable connection and equivalence judgment are very difficult, I do not know if my level is too poor or the script function of gdb is too weak, in short, kernel debugging is more difficult than Windbg.
On how to debug the linux kernel module to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.