Oops information for Linux kernel debugging

Source: Internet
Author: User

Oops information for Linux kernel debugging

Oops indicates "oh". When a kernel error occurs (for example, an Invalid Address is accessed), the output information becomes oops information. The following is an example to describe oops information:

Example: To test oops information, we can select any Kernel File for testing. I will take I2C as an example:

1.
Modify Linux source code/Drivers/I2C/i2c-core.c
In the FunctionStatic int _ init i2c_init (void)Add the following statement at the beginning:

int * ptest = NULL;*ptest = 0xabcd;

As follows:


When the Linux kernel is executed, an error occurs and oops information is generated.

2.
Then, compile I2C into the kernel in menuconfig:
Make menuconfig
Select I2C support in device drivers to compile I2C into the kernel

3.
Recompile the kernel and start it with the kernel.

4.
Oops information appears ~~ For example:

Starting from row 7th bug to ending with oops Information

5.

In order to correspond the machine code address in oops information to the source file, we also need to disassemble the compiled kernel image for comparison. However, since we used the make bzimage command to generate the bzimage kernel compression image, we cannot disassemble, So we run the following command:

Make vmlinux indicates that the generated kernel image is not compressed.


The generated kernel image is about 150 MB!



6.

Disassemble the uncompressed kernel image generated in Step 1:

Objdump-D vmlinux> vmlinux. Dis


The generated vmlinux. Dis is about 500 mb! Haha, as follows:

vmlinux:     file format elf32-i386Disassembly of section .text:c1000000 <_text>:c1000000:       f6 86 11 02 00 00 40    testb  $0x40,0x211(%esi)c1000007:       75 14                   jne    c100001d <_text+0x1d>c1000009:       0f 01 15 16 4e 6a 01    lgdtl  0x16a4e16c1000010:       b8 18 00 00 00          mov    $0x18,%eaxc1000015:       8e d8                   mov    %eax,%dsc1000017:       8e c0                   mov    %eax,%esc1000019:       8e e0                   mov    %eax,%fsc100001b:       8e e8                   mov    %eax,%gsc100001d:       fc                      cldc100001e:       31 c0                   xor    %eax,%eaxc1000020:       bf 00 90 7a 01          mov    $0x17a9000,%edic1000025:       b9 5c b8 83 01          mov    $0x183b85c,%ecxc100002a:       29 f9                   sub    %edi,%ecxc100002c:       c1 e9 02                shr    $0x2,%ecxc100002f:       f3 ab                   rep stos %eax,%es:(%edi)c1000031:       bf e0 99 73 01          mov    $0x17399e0,%edic1000036:       b9 00 04 00 00          mov    $0x400,%ecxc100003b:       fc                      cldc100003c:       f3 a5                   rep movsl %ds:(%esi),%es:(%edi)c100003e:       8b 35 08 9c 73 01       mov    0x1739c08,%esic1000044:       21 f6                   and    %esi,%esic1000046:       74 0c                   je     c1000054 <_text+0x54>c1000048:       bf 00 73 73 01          mov    $0x1737300,%edic100004d:       b9 00 02 00 00          mov    $0x200,%ecxc1000052:       f3 a5                   rep movsl %ds:(%esi),%es:(%edi)c1000054:       66 81 3d e6 9b 73 01    cmpw   $0x207,0x1739be6c100005b:       07 02c100005d:       72 1c                   jb     c100007b <default_entry>c100005f:       a1 1c 9c 73 01          mov    0x1739c1c,%eaxc1000064:       3d 04 00 00 00          cmp    $0x4,%eaxc1000069:       73 0e                   jae    c1000079 <lguest_entry>c100006b:       8b 04 85 c0 72 73 01    mov    0x17372c0(,%eax,4),%eaxc1000072:       2d 00 00 00 c0          sub    $0xc0000000,%eaxc1000077:       ff e0                   jmp    *%eax               ..................................................





The following describes oops in detail:


BUG: unable to handle kernel NULL pointer dereference at (null)

This is a string description of OOPS information, indicating that we have accessed the NULL pointer.



IP: [<c172f60b>] i2c_init+0x9/0x63

<C172f60b> indicates the IP pointer at the kernel error. Search "c172f60b" in vmlinux. Dis and find the following:

c172f5fe:       5e                      pop    %esic172f5ff:       5f                      pop    %edic172f600:       5d                      pop    %ebpc172f601:       c3                      retc172f602 <i2c_init>:c172f602:       55                      push   %ebpc172f603:       b8 20 c0 6d c1          mov    $0xc16dc020,%eaxc172f608:       89 e5                   mov    %esp,%ebpc172f60a:       53                      push   %ebxc172f60b:       c7 05 00 00 00 00 cd    movl   $0xabcd,0x0c172f612:       ab 00 00c172f615:       e8 c6 92 bd ff          call   c13088e0 <bus_register>c172f61a:       85 c0                   test   %eax,%eaxc172f61c:       89 c3                   mov    %eax,%ebxc172f61e:       75 40                   jne    c172f660 <i2c_init+0x5e>c172f620:       b8 67 ee 63 c1          mov    $0xc163ee67,%eaxc172f625:       e8 36 ab bd ff          call   c130a160 <class_compat_register>c172f62a:       85 c0                   test   %eax,%eaxc172f62c:       a3 d4 76 83 c1          mov    %eax,0xc18376d4c172f631:       74 1e                   je     c172f651 <i2c_init+0x4f>

This is exactly in the i2c_init function.



i2c_init+0x9/0x63

The error occurs when the starting address (0xc172f602) of the i2c_init function is offset to 0x9, And the i2c_init function is 0x63 bytes,IP address at error point = c172f60b, exactly equal to 0xc172f602 + 0x9



Pid: 1

Process ID with error



[    0.992003] EIP: 0060:[<c172f60b>] EFLAGS: 00010246 CPU: 0                   [    0.992003] EIP is at i2c_init+0x9/0x63                                      [    0.992003] EAX: c16dc020 EBX: c1785e34 ECX: 00000000 EDX: 00000000          [    0.992003] ESI: c16fe164 EDI: 00000000 EBP: df071f98 ESP: df071f94          [    0.992003]  DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068                    [    0.992003] Process swapper (pid: 1, ti=df070000 task=df068000 task.ti=df070)

The value of each register when an error occurs. CPU: 0 indicates the number of the wrong CPU. For a single processor system, the number is 0.



[    1.240004] Call Trace:[    1.240004]  [<c1001272>] ? do_one_initcall+0x32/0x1a0[    1.240004]  [<c172f602>] ? i2c_init+0x0/0x63[    1.240004]  [<c17018d9>] ? kernel_init+0x12d/0x183[    1.240004]  [<c17017ac>] ? kernel_init+0x0/0x183[    1.240004]  [<c1003e67>] ? kernel_thread_helper+0x7/0x10

Stack call in case of an error. The bottom is the top-level call.




Code: 89 18 83 7d ec 00 0f 85 64 ff ff ff 31 db b8 00 c0 6d c1 e8

Machine code of the command near the wrong command


Using the above information, we can quickly find the wrong location ~~


Done!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.