The basic debugging method of GDB for Linux kernel __linux
Source: Internet
Author: User
Single Board software Linux kernel appears crash, how to use the GDB tool to debug. The basic method process is as follows:
1. In order to test GDB operation, intentionally in the Kernel/linux/fs/ioctl.c file Do_vfs_ioctl method to add null pointer operation code, and then compiled image into a single board, start a single board, the core crash, part of log as follows:
CPU 0 Unable to handle kernel paging request in virtual Address 00000000, EPC = 800a73b8, RA = = 800a793c oops[#1]:
Cpu 0
$0:00000000 10008d00 00000000 Ffffffea
$4:FFFFFDFD 10008d01 00000001 00000000
$8:00000000 7fed2e40 00001cb2 00000b3b
$12:00031c7f 2ab5ead7 2aaac7c9 15010000
$16:7fed2e18 878ca5a0 00000000 00000001
$20:2ab84980 00000000 00000007 00000000
$24:00000000 2ab62090
$28:8782c000 8782fe98 7fed2fc8 800a793c
hi:0000002a
Lo:000311fc
Epc:800a73b8 Do_vfs_ioctl+0x88/0x5c8
Not tainted
RA:800A793C sys_ioctl+0x44/0x98
STATUS:10008D03 KERNEL EXL IE
cause:00000008
badva:00000000
prid:0002a080 (Broadcom4350)
Modules Linked In:
code:0c029c9f 02003021 8fbf0064 <8c020000> 8fb40060 8fb3005c 8fb20058 8fb10054 8fb00050
Disabling lock debugging due to kernel taint
Kernel panic-not syncing:attempted to kill init!
Rebooting in 1 seconds. <6>
Stopping CPU 1
Kersysmipssoftreset:called on CPU 0 2. Start GDB, run the GDB tool (or./mips-linux-uclibc-gdb) directly on the host (dev) console, and then typing file .../vmlinux start the kernel with debugging information. Note To configure the kernel debug switch to recompile the kernel generation file Vmlinux (larger than the previous file, 50M or more), configure the kernel debug switch as follows,
Kernel Hacking---> [*] Kernel debugging [*] Compile the Kernel with debug info compile kernel command: Make kernelbuild, to be in Proj The root directory of the ECT runs the command for compilation. Start the GDB command as follows: [Myname@localhost bin]$./mips-linux-uclibc-gdb (GDB) file/opt/mydir/kernel/linux/vmlinux
3. GDB Debug Location Checked Call trace log, the most important part in log is "EPC" (Exception program counter), it is where the CR Ash happened. In this example, the ' EPC ' is 0xc0d1d488. For X1000 and X3500, the address like 0x8xxxxxxxx are in kernel, and the address-like 0xcXXXXXXX are in some module. The address 0x800a73b8 corresponds to the address (do_vfs_ioctl+0x88), which represents the offset address 0x88 at the function Do_vfs_ioctl. The debugging process is as follows:
(GDB) List * (0X800A73B8) 0x800a73b8 is in Do_vfs_ioctl (fs/ioctl.c:569).
564 error = Vfs_ioctl (Filp, CMD, arg);
565 break;
566}
567 error = *test;
568 return error;
569}
570
571 Syscall_define3 (IOCTL, unsigned int, fd, unsigned int, cmd, unsigned long, ARG)
572 {
573 struct file *filp;
(GDB) list* (do_vfs_ioctl+0x88)
0x800a73b8 is in Do_vfs_ioctl (fs/ioctl.c:569).
564 error = Vfs_ioctl (Filp, CMD, arg);
565 break;
566}
567 error = *test;
568 return error;
569}
570
571 Syscall_define3 (IOCTL, unsigned int, fd, unsigned int, cmd, unsigned long, ARG)
572 {
573 struct file *filp;
(GDB) list* (sys_ioctl+0x44)
You can parse the code near the function to find the error position in line567,test as null pointer (intentionally assigning null in front).
Note: If the list* (0x80xxxxxx) command prompts you with the following information: No source file for address 0x80xxxxxx. The reason is that the corresponding debug switch was not turned on in make Menuconfig to compile.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service