大概是:
所有make command (make defconfig, make menuconfig, make) 都要加上 ARCH=um
kernel config 要開啟 kernel-hacking : Compile with debug info 和 compile with frame-buffer-support (default也是開啟的)
然後 build rootfs,這部份 follow 一般用 busybox 產生 rootfs 的 instruction就可以。
我是用上一篇,kgdb 的 busybox.
用 gdb run uml linux. 重點是:
- linux 的 rootfs 需要用 gdb -x command 的方式,讓 gdb 把 rootfs parameter 傳給 linux
- uml linux 會產生 SIGSEGV signal ,要請 gdb bypass -- 這個也一樣放到 -x command 的 command script 中
command 這個檔的內容:
set args ubd0=/home/charles-chang/uml/linux-2.6.34.1/busybox.img
handle SIGUSR1 pass nostop noprint
handle SIGSEGV pass nostop noprint
gdb 啟動後,可以先設break pont 到 start_kernel
break start_kernel
然後就可以開始 run:
run
然後就會停在 start_kernel。用
continue
繼續...然後會停在一個signal 的地方...再用 continue 繼續就可以...這個就是 gdb log:
charles-chang@rbtlegacy:~/uml/linux-2.6.34.1$ gdb -x ./command ./linux
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) run
Starting program: /home/charles-chang/uml/linux-2.6.34.1/linux ubd0=/home/charles-chang/uml/linux-2.6.34.1/busybox.img
Locating the bottom of the address space ... 0x1000
Locating the top of the address space ... 0xc0000000
Core dump limits :
soft - 0
hard - NONE
Checking that ptrace can change system call numbers...OK
Checking syscall emulation patch for ptrace...OK
Checking advanced syscall emulation patch for ptrace...OK
Checking for tmpfs mount on /dev/shm...OK
Checking PROT_EXEC mmap in /dev/shm/...OK
Checking for the skas3 patch in the host:
- /proc/mm...not found: No such file or directory
- PTRACE_FAULTINFO...not found
- PTRACE_LDT...not found
UML running in SKAS0 mode
Linux version 2.6.34.1 (charles-chang@rbtlegacy) (gcc version 4.3.2 (Debian 4.3.2-1.1) ) #1 Mon Jul 26 15:42:19 CST 2010
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 8128
Kernel command line: ubd0=/home/charles-chang/uml/linux-2.6.34.1/busybox.img root=98:0
PID hash table entries: 128 (order: -3, 512 bytes)
Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
Memory: 30048k available
Hierarchical RCU implementation.
RCU-based detection of stalled CPUs is enabled.
NR_IRQS:15
Calibrating delay loop... 1900.54 BogoMIPS (lpj=9502720)
Mount-cache hash table entries: 512
Checking for host processor cmov support...Yes
Checking that host ptys support output SIGIO...Yes
Checking that host ptys support SIGIO on close...No, enabling workaround
Using 2.6 host AIO
NET: Registered protocol family 16
bio: create slab at 0
Switching to clocksource itimer
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 1, 8192 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
IRQ 9/mconsole: IRQF_DISABLED is not guaranteed on shared IRQs
mconsole (version 2) initialized on /home/charles-chang/.uml/oJVcbD/mconsole
Checking host MADV_REMOVE support...OK
Host TLS support detected
Detected host type: i386 (GDT indexes 6 to 9)
VFS: Disk quotas dquot_6.5.2
Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
msgmni has been set to 58
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
TCP cubic registered
NET: Registered protocol family 17
Initialized stdio console driver
Console initialized on /dev/tty0
console [tty0] enabled
Initializing software serial port version 1
console [mc-1] enabled
ubda: unknown partition table
IRQ 3/console-write: IRQF_DISABLED is not guaranteed on shared IRQs
IRQ 2/console: IRQF_DISABLED is not guaranteed on shared IRQs
IRQ 10/winch: IRQF_DISABLED is not guaranteed on shared IRQs
kjournald starting. Commit interval 5 seconds
EXT3-fs (ubda): mounted filesystem with writeback data mode
VFS: Mounted root (ext3 filesystem) readonly on device 98:0.
line_ioctl: tty0: unknown ioctl: 0x5600
[New LWP 32568]
Executing new program: /proc/32568/exe
/proc/32568/exe: Permission denied.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) n
Program not restarted.
(gdb) c
Continuing.
IRQ 13/xterm: IRQF_DISABLED is not guaranteed on shared IRQs
Processing /etc/profile... Done
# INFO: RCU detected CPU 0 stall (t=2009 jiffies)
IRQ 2/console: IRQF_DISABLED is not guaranteed on shared IRQs
IRQ 3/console-write: IRQF_DISABLED is not guaranteed on shared IRQs
IRQ 10/winch: IRQF_DISABLED is not guaranteed on shared IRQs
INFO: RCU detected CPU 0 stall (t=1715 jiffies)
另外這一頁 http://user-mode-linux.sourceforge.net/old/debugging.html 有 configure uml kernel 另一種 mode 配合 gdb debug...下次試試.
原來這一篇 http://web2.clarkson.edu/class/cs644/kernel/setup/uml/gdb_uml.html 就有講在 gdb 下用 command 指定 root image 的方法...
# gdb ./linux
(gdb) handle SIGSEGV pass nostop noprint
Signal Stop Print Pass to program Description
SIGSEGV No No Yes Segmentation fault
(gdb) handle SIGUSR1 pass nostop noprint
Signal Stop Print Pass to program Description
SIGUSR1 No No Yes User defined signal 1
(gdb) r ubd0=/home/charles-chang/uml/linux-2.6.34.1/busybox.img
這一篇有exmple : 教你怎麼trace do_fork..
沒有留言:
張貼留言