Linux UML Kernel Debugging method

Source: Internet
Author: User

Summary of Linux UML kernel debugging methods

The building of a UML environment

1 Download Internal core

Select version Linux-3.10.57.tar.xz from official website www.kernel.org

Unzip to the appropriate path???? /opt/um/linux-3.10.57

?

2 UM-based kernel configuration

#cd/opt/um/linux-3.10.57

#cp cd/boot/config-3.8.13.13-cdos. config

# Make Olddefconfig Arch=um

?

To facilitate debugging, modify the configuration file

#make Mrproper

#make Mrproper Arch=um

# Make Menufconfig Arch=um

Make sure that the configuration is selected by selecting:

Kernel hacking->

Compile the kernel with debug info (the corresponding debug_info configuration is yes)

and compile the kernel with frame pointers (the corresponding Frame_pointer configuration is yes)

This generates a binary kernel Linux with detailed debugging information.

?

At the same time, after generating the. config file, before compiling, you can use the editor to open the source root directory of the makefile file, the compilation optimization level-o2 to-o1, which can be guaranteed by the premise of compiling the kernel file generated by a good debugging effect.

3 Compiling kernels and modules

#make Linux Arch=um

#make Modules Arch=um

#make Modules_install Arch=um

?

Build the kernel we need, and support debugging.

?

4 Making the file system

The direct boot will be problematic and the root file system cannot be found. So we use people ready-made.

http://fs.devloop.org.uk/ Download centos6.x-x86-root_fs.bz2

Get CENTOS6.X-X86-ROOT_FS by GUNZIP2 decompression

Note: CentOS is available in practice, and the same Ubuntu trusty run-time encounters various problems.

After downloading or making a better file system, you can copy the modules generated from the previous step to the corresponding directory in the UML root file system. The simplest way to pass files between host Linux and the UML root file system is to use a directory that mounts the UML root file system to host Linux and then use the CP. Copy files from the source root directory in host Linux to the UML root file system:

#mount-O loop centos6.x-x86-root_fs/mnt

#cp –R /opt/um/linux-3.10.57/mods/lib/modules/3.10.57 /mnt/lib/modules

#umount/mnt

?

5 Making File Exchange system

In general, it is also possible to not use the swap file system, which may have some advantages over the stability of the system.

Use the following command to generate:

#dd If=/dev/zero of=swap_fs bs=1m count=512

?

#mkswap./swap_fs

?

?

Two GDB debugging UML

After the above steps, the required environment for debugging is ready, then you can start debugging work.

1 Running User-mode Linux

Under the compiled /opt/um/linux-3.10.57 root directory, perform Linux run

# ./vmlinux ubda=. Centos6.x-x86-root_fs Ubdb=swap_fs

or # ./linux ubda=. Centos6.x-x86-root_fs Ubdb=swap_fs

?

The following information appears, indicating that the UML was successfully run, default to log on with the root account, no password.

CentOS Release 6.5 (Final)

Kernel 3.10.57 on an i686

?

localhost login:

?

2 gdb Debugging UML

Keep the UML in the previous step in a running state and open another terminal.

First query the UML process number, you can see that the UML root process number is 29142, but GDB is bound to its child process 29143.

[email protected]:/opt/um/linux-3.10.57# ps-el|grep Linux

4 S 0 29413 30142 0-8836 hrtime pts/22 00:00:02 Linux

1 S 0 29420 29413 0 0-8836 sys_io pts/22 00:00:00 Linux

1 S 0 29421 29413 0 0-8836 unix_s pts/22 00:00:00 Linux

1 S 0 29422 29413 0 0-8836 poll_s pts/22 00:00:00 Linux

1 T 0 29423 29413 0 0-346 ptrace pts/22 00:00:00 Linux

1 T 0 29551 29413 0 0-167 ptrace pts/22 00:00:00 Linux

1 T 0 29702 29413 0 0-172 ptrace pts/22 00:00:00 Linux

1 T 0 30000 29413 0 0-242 ptrace pts/22 00:00:00 Linux

1 T 0 30025 29413 0 0-357 ptrace pts/22 00:00:00 Linux

1 T 0 30032 29413 0 0-381 ptrace pts/22 00:00:00 Linux

?

Start gdb and go to gdb debug environment

#gdb Linux

#attach 29143

?

3 Testing GDB

Set breakpoints in the GDB environment in Sys_clone.

#b Sys_clone

#i b

?

Executing command ls-l in a UML environment, the system will stop at the Sys_clone () function, and you can now see the state of the Sys_clone () function running in GDB.

?

At this point, the UML debugging environment has been set up, we can do basic debugging of the Linux kernel.

?

Reference documents

1 http://blog.csdn.net/ztz0223/article/details/7874759

2 http://blog.chinaunix.net/uid-21525518-id-1824661.html

3 http://blog.sina.com.cn/s/blog_70dd16910101akk2.html

?

?

?

Linux UML Kernel Debugging method

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.