Kgdb kernel debugging for ubuntu8.10 in virtualbox

Source: Internet
Author: User
The establishment of the Linux kernel debugging environment has always been a problem for new Linux kernel beginners. Recently, I have started to develop security-related Linux systems. Sometimes I have to debug the Linux kernel and driver, I encountered many difficulties when setting up the debugging environment. I generally gave VMware the Linux kernel debugging environment on the Internet. Unfortunately, as I said earlier, my ubuntu8.10amd64bit cannot be installed with vmware6.0 or 6.5, I have to use virtualbox instead.
Because the CPU of your machine is amd64bit, you chose Ubuntu 8.10 desktop x86_64 when installing Ubuntu on the physical machine. However, your CPU is old and does not support virtual mode, therefore, UBUNTU x86_64 cannot be installed in virtualbox, and only 32-bit Ubuntu can be installed. However, kernel debugging requires that the development and target machines have the same kernel tree, initially, I wanted to compile the 32-bit Kernel on my 64-bit machine. Later I Wanted To clone another 32-bit Ubuntu virtual machine as a development machine, so as not to bother. Of course, when the OS version of the host is the same as the OS version of the target machine, you can directly use the host as the development machine instead of Virtual Development machine. The following describes how to set up the kernel debugging environment:
1. First install virtualbox and install ubuntu8.10 Virtual Machine in virtualbox. For more information, see "Install Ubuntu Virtual Machine in virtualbox 8.10".

2. compile the debug kernel in the virtual machine. The kernel of this version is integrated with kgdb internally and no patch is required. This is a difference from the kgdb setting before 2.6.15, many people mentioned this on the Internet. For the steps to compile the kernel and add startup items, refer to the previous Ubuntu kernel upgrade. The only difference is that oldconfig cannot be used for make, but menuconfig or gconfig (xconfig has not been tried, if you do not know if this is the case, you must install another support library in gconfig or menuconfig, as shown in the following code:
1) make menuconfig
Sudo apt-Get install libncurses5-dev
2) Make gconfig
Apt-Get install libglade2-dev
The command for compiling the kgdb kernel (using gconfig) on Ubuntu can be described as follows (Su can be used to switch to the root account first ),
1) apt-Get install build-essential kernel-package libglade2-dev
2) Make mrproper & make gconfig
3) A Configuration selection interface is displayed during gconfig. You can save the configuration without any modification.

4) make bzimage & make modules & make modules_install & make install & mkinitramfs-O/boot/initrd. img-2.6.27.18 2.6.27.18
In step 2, the commands in the kernel compilation process are completed one by one. Well, you can find a place to take a rest. Generally, the compilation process takes about two hours and varies depending on the quality of the machine. It will be a little slower in the virtual machine, generally, it is better to compile at night.

3. After the kernel is compiled, you can clone the machine above. VMware has the clone menu option, but virtualbox does not. However, the essence of the clone is to copy a virtual disk file, you can directly copy a copy of The VMware Virtual Disk File to other places to open and run, however, virtualbox does not allow you to do this, but you can use vboxmanager clonevdi to clone virtualbox virtual hard disk images.
Cd ~ /. Virtualbox/VDI/
By default, the virtualbox hard disk image file is stored here. you can clone another image:
Vboxmanage clonevdi ubuntu8.10targetos. VDI ubuntu8.10devos. VDI
Create a new virtual machine and register the cloned hard disk when creating the hard disk. In this way, the development machine is the clone body of the target machine.

4. Configure the serial port. For details about the virutalbox serial port configuration, refer to the previous "virtualbox virtual machine serial port settings under Ubuntu". Here, we need to add that both virtual machines connect their com 1 port to a named pipe/tmp/vbox on the host, the COM ports of the two are connected together. In addition, only one of the two virtual machines can choose to create a channel, and only one of them can be started first, therefore, we recommend that you create a channel for the development machine and use the/tmp/vbox naming channel for the target machine. In this way, the development machine does not need to be restarted every time the target machine is restarted and debugged.

5. Configure the startup items of the target machine. In the target machine
Sudo gedit/boot/GRUB/menu. lst; backup is recommended.
The original menu. lst is as follows:
Title Ubuntu 8.10, kernel 2.6.27-7-generic
UUID d77795b1-d4b4-466c-8989-d828d7eba4c5
Kernel/boot/vmlinuz-2.6.27-7-generic root = UUID = d77795b1-d4b4-466c-8989-d828d7eba4c5 Ro locale = zh_cn quiet splash
Initrd/boot/initrd. img-2.6.27-7-generic
Quiet
...
After adding a startup Item
Title Ubuntu 8.10, kernel 2.6.27-7-generic
UUID d77795b1-d4b4-466c-8989-d828d7eba4c5
Kernel/boot/vmlinuz-2.6.27-7-generic root = UUID = d77795b1-d4b4-466c-8989-d828d7eba4c5 Ro locale = zh_cn quiet splash
Initrd/boot/initrd. img-2.6.27-7-generic
Quiet

Title Ubuntu 8.10, kernel 2.6.27.18-with kgdb
UUID d77795b1-d4b4-466c-8989-d828d7eba4c5
Kernel/boot/vmlinuz-2.6.27.18 root = UUID = d77795b1-d4b4-466c-8989-d828d7eba4c5 Ro kgdboc = ttys0, 115200 kgdbwait
Initrd/boot/initrd. img-2.6.27-7-generic
...

6. Start the development machine first. Start the target machine and Press ESC to start the kernel with kgdb. After a while, the startup process will be paused and prompt you to wait for remote GDB debugging ,,

Switch to the development machine and enter the source code directory to run
GDB./vmlinux, GDB
After startup, set the baud rate and debugging terminal in GDB
(GDB) set remotebaud 115200
(GDB) targ

Et remote/dev/ttys0
In this way, you can debug the kernel,

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.