Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11
Transcript of Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11
![Page 1: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/1.jpg)
Debugging Linux Kernel Sourcewith Eclipse & QEMU
in Fedora Core 11
Hyung Won Choihttp://web.njit.edu/~hwc1027
![Page 2: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/2.jpg)
2/63
Acknowledgement
• These slides are based on Takis Blog. – http://issaris.blogspot.com/2007/12/download-
linux-kernel-sourcecode-from.html
• All the credits go to the author of the Blog.
![Page 3: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/3.jpg)
3/63
OS & Software Environment
• OS: Fedora Core 11• Linux Kernel Source: 2.6.30.2• IDE for Debugging: Eclipse-CDT• Virtual Machine for Debugging: QEMU• Compiler: GCC (version 4.4)
![Page 4: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/4.jpg)
4/63
1. Install Eclipse/Eclipse-CDT
• Fedora Core 10/11– Install Fedora Eclipse packages
– From CD/DVD or with yum.
• Other distribution– Download "Eclipse IDE for C/C++
Developers" from Eclipse site & Install.
– http://www.eclipse.org/downloads/
![Page 5: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/5.jpg)
5/63
2. Download Linux Kernel
• Obtain Linux Kernel source from Linux Kernel website– http://www.kernel.org
– I downloaded 2.6.30.2 version (on 7/20/09)
– http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.2.tar.bz2
![Page 6: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/6.jpg)
6/63
3. Untar Linux Kernel source
• Change to “root” user in a Terminal/Shell$ su –
• Untar Linux Kernel source:$ cp linux-2.6.30.2.tar.bz2 /usr/local/src/
$ cd /usr/local/src/
$ tar jxvf linux-2.6.30.2.tar.bz2
![Page 7: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/7.jpg)
7/63
4. Configure with .config (1)
$ mkdir -p /mnt/build/linux-2.6$ cp /boot/config-2.6.29.4-167.fc11.i686.PAE /mnt/build/linux-2.6/.config$ cd /usr/local/src/linux-2.6.30.2/$ make oldconfig O=/mnt/build/linux-2.6…
![Page 8: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/8.jpg)
8/63
4. Configure with .config (2)Kernel compression mode> 1. Gzip (KERNEL_GZIP) (NEW)
2. Bzip2 (KERNEL_BZIP2) (NEW)3. LZMA (KERNEL_LZMA) (NEW)
choice[1-3?]:...Strip assembler-generated symbols during link (STRIP_ASM_SYMS) [N/y/?] (NEW) Support for extended (non-PC) x86 platforms (X86_EXTENDED_PLATFORM) [Y/n/?]Support non-standard 32-bit SMP architectures (X86_32_NON_STANDARD) [N/y/?] Paravirtualization layer for spinlocks (PARAVIRT_SPINLOCKS) [N/y/?]
...// It asked many things. I entered “default” for all the questions.# configuration written to .config
![Page 9: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/9.jpg)
9/63
4. Configure with .config (3)
$ make menuconfig O=/mnt/build/linux-2.6
![Page 10: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/10.jpg)
10/63
4. Configure with .config (3)• Select “Kernel Hacking ”
![Page 11: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/11.jpg)
11/63
4. Configure with .config (3)• Enable “Compile the kernel with debug info”
Already checked
![Page 12: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/12.jpg)
12/63
4. Configure with .config (3)• Enable “Compile the kernel with frame pointers”
Already enabled
![Page 13: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/13.jpg)
13/63
5. Run Eclipse (or Eclipse-cdt)
• In a terminal/shell:
$ eclipse
![Page 14: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/14.jpg)
14/63
5. Run Eclipse (or Eclipse-cdt)• “Select a workspace”: /root/workspace
![Page 15: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/15.jpg)
15/63
5. Run Eclipse (or Eclipse-cdt)
![Page 16: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/16.jpg)
16/63
5. Run Eclipse (or Eclipse-cdt)• “Go to the Workbench”
![Page 17: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/17.jpg)
17/63
5. Run Eclipse (or Eclipse-cdt)• Select “Window Preferences”:
![Page 18: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/18.jpg)
18/63
5. Run Eclipse (or Eclipse-cdt)• Select “Window Preferences”:
![Page 19: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/19.jpg)
19/63
5. Run Eclipse (or Eclipse-cdt)• Select “General Workspace”• Deselect “Build automatically” & “Apply”
![Page 20: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/20.jpg)
20/63
5. Run Eclipse (or Eclipse-cdt)• Select “C/C++ Indexer”
Switch "Fast C/C++ Indexer" to "No Indexer”
Click “OK”
![Page 21: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/21.jpg)
21/63
• “File New Project..” on Eclipse menu
6. New Project
![Page 22: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/22.jpg)
22/63
6. New Project• Select “C C Project” & click “Next”
![Page 23: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/23.jpg)
23/63
6. New Project• Select “Makefile project” “Empty Project”
![Page 24: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/24.jpg)
24/63
6. New Project• Uncheck “Use default location” checkbox
![Page 25: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/25.jpg)
25/63
6. New Project• Enter the project name in “Project name”• Enter “/usr/local/src/linux-2.6.30.2” into “Location”
Click “Next”
![Page 26: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/26.jpg)
26/63
6. New Project• Click “Finish”
![Page 27: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/27.jpg)
27/63
6. New Project• Answer “Yes”
![Page 28: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/28.jpg)
28/63
6. New Project• New Project is created.
![Page 29: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/29.jpg)
29/63
7. Configuring Project• Click the right button (mouse) on the project.• Select “Properties”
![Page 30: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/30.jpg)
30/63
7. Configuring Project• Select “C/C++ Builders”• Uncheck “Use default build command”
![Page 31: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/31.jpg)
31/63
7. Configuring Project• Enter “make CC=gcc O=/mnt/build/linux-2.6” in “Build command”• Enter “/mnt/build/linux-2.6” in “Build directory” by “File system..”
Click “OK”
![Page 32: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/32.jpg)
32/63
8. Build• Select “Project Build all” on the menu
![Page 33: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/33.jpg)
33/63
8. Build• Shows the progress for building kernel
![Page 34: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/34.jpg)
34/63
8. Build• Shows the progress for building kernel
![Page 35: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/35.jpg)
35/63
8. Build• Found an error & Building was stopped.
Error!
![Page 36: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/36.jpg)
36/63
8. Build
Error!
• “extern” (jffs2-user.h) caused an error.
![Page 37: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/37.jpg)
37/63
8. Build• Modify jffs2-user.h file: remove “extern”
– target_endian is only used in jffs2-user.h.
![Page 38: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/38.jpg)
38/63
8. Build• Rebuild with “Project Build all” & created a bzImage• Kernel: arch/x86/boot/bzImage is ready (#1)
![Page 39: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/39.jpg)
39/63
9. QEMU Installation
• Install QEMU & Supporting software
• From Fedora 11 CD/DVD, install in order (or yum):– qemu-common-0.10-16.fc11.i586.rpm– qemu-img-0.10-16.fc11.i586.rpm– bochs-bios-2.3.8-0.6.git04387139e3b.fc11.noarch.rpm– etherboot-zroms-kvm-5.4.4-13.fc11.noarch.rpm– vgabios-0.6-0.5.b.fc11.noarch.rpm– qemu-system-x86-0.10-16.fc11.i586.rpm– qemu-kvm-0.10-16.fc11.i586.rpm (optional)
• Note: If you already installed, skip this.
![Page 40: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/40.jpg)
40/63
10. First Run QEMU
• In a terminal/shell
$ qemu -s -S -hda /dev/zero -kernel/mnt/build/linux-2.6/arch/x86/boot/bzImage
![Page 41: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/41.jpg)
41/63
10. First Run QEMU• Shows empty (blank) screen
– Leave this QEMU screen
![Page 42: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/42.jpg)
42/63
11. Eclipse Debug Configurations• “Run Debug Configurations..”
![Page 43: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/43.jpg)
43/63
11. Eclipse Debug Configurations• Double click “C/C++ Local Application”
![Page 44: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/44.jpg)
44/63
11. Eclipse Debug Configurations• Put “/mnt/build/linux-2.6/vmlinux” in “C/C++
Application”
![Page 45: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/45.jpg)
45/63
11. Eclipse Debug Configurations• In “Debugger” tab
– “gdbserver Debugger” in “Debugger:”– “start_kernel” in “Stop on startup at:”
• “Connection”– Select “TCP”
in “Type:” list– Put “1234” in
“Port number”
• Click “Debug”
![Page 46: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/46.jpg)
46/63
11. Eclipse Debug Configurations• Eclipse compiles and links in progress
![Page 47: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/47.jpg)
47/63
11. Eclipse Debug Configurations• After a while, it opens “Confirm Perspective Switch”
Click Yes
![Page 48: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/48.jpg)
48/63
11. Eclipse Debug Configurations• Shows the changed perspective
![Page 49: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/49.jpg)
49/63
12. Back to QEMU screen• Shows some outputs.
![Page 50: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/50.jpg)
50/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
![Page 51: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/51.jpg)
51/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
Outputs on QEMU screen
![Page 52: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/52.jpg)
52/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
Outputs on QEMU screen
![Page 53: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/53.jpg)
53/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
Outputs on QEMU screen
![Page 54: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/54.jpg)
54/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
Outputs on QEMU screen
![Page 55: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/55.jpg)
55/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
![Page 56: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/56.jpg)
56/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
Outputs on QEMU screen
![Page 57: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/57.jpg)
57/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
![Page 58: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/58.jpg)
58/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
Outputs on QEMU screen
![Page 59: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/59.jpg)
59/63
13. Line-by-line run in Eclipse• In Eclipse, “Run Step over” (or F6)
– Several “Run Step over”s (or F6)
![Page 60: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/60.jpg)
60/63
14. Final QEMU screen
• After rest_init() run, QEMU console shows kernel panic.– Since it doesn’t have a rootfile system
– /dev/zero was assigned in the initial run.
• Can add a rootfile system later.
![Page 61: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/61.jpg)
61/63
14. Final QEMU screen
![Page 62: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/62.jpg)
62/63
14. Final QEMU screen
![Page 63: Debugging Linux Kernel Source with Eclipse & QEMU in Fedora Core 11](https://reader035.fdocuments.in/reader035/viewer/2022071600/613d1b8b736caf36b759664d/html5/thumbnails/63.jpg)
63/63
15. End
• Now, you have an environment to debug Linux Kernel source code.
• All the credits go to Takis Blog.– http://issaris.blogspot.com/2007/12/download-
linux-kernel-sourcecode-from.html
Thank you.