Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108593
  • 博文数量: 75
  • 博客积分: 2850
  • 博客等级: 少校
  • 技术积分: 870
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-30 22:43
文章分类

全部博文(75)

文章存档

2011年(1)

2010年(59)

2009年(11)

2008年(4)

我的朋友

分类: LINUX

2010-08-22 23:13:20

Kgdb的调试准备及调试
Target端:
      
       #mv System.map  System.map-2.6.15.5
       #mv bzImage  vmlinuz-2.6.15.5
       #ln ?s System.map-2.6.15.5  System.map(在这之前,把系统原来的符号链接删除)
       #ln ?s vmlinuz  vmlinuz-2.6.15.5(在内核目录下执行完make install后,这些命令能直接跳过)

在/boot目录下执行一下命令:
# new-kernel-pkg --mkinitrd --depmod --install 2.6.18 (这条命令因为执行不成功,所以我先不执行,主要是因为我们的内核是在host上进行编译,执行这条命令主要是对内核模块进行依赖性处理及文件系统映像的处理,关于这些mkinitrd,system.map vmlinuz等文件的信息能参考本人blog上转载的文章:几个重要的RedHat Linux内核文件介绍)
(在执行完内核模块的安装及内核安装后,该命令能正常通过)
#df (查看根目录在那个分区,下一步要用到。注意,这里根分区不时boot的那个50M的分区,而一般是你最大的那个分区,也就是“/”,千万不要搞错哦。我的为 /dev/shda2)
上面的步骤后,我们要进行的就是修改/boot/grub/grub.conf
title Red Hat Linux (2.4.20-8)
root (hd0,0)
kernel /vmlinuz-2.4.20-8 ro root=LABEL=/
initrd /initrd-2.4.20-8.img
#上面是你的原来的,不要动 。 下面这个是要自己填写上去的。
title Red Hat Linux (2.6.18.8)
root (hd0,0)
kernel /vmlinuz-2.6.18.8 ro root=/dev/sda2 kgdbwait 8250kgdb=0,115200

设置好后,target就能重启了。下面的步骤我们就能参考kgdb的官方文件:
Target设备重启后,我们就能看见双系统的启动目录了,这个时候我们选择2.6.15.5的内核启动,
出现下面的信息后,就表示启动正常了,正在等待host设备上GDB发送控制命令
Uncompressing Linux... Ok, booting the kernel

Host端:
回到内核的源码顶层目录
#gdbmod-2.4  vmlinux
GNU gdb 6.4
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db library "/lib/tls/i686/libthread_db.so.1".

(gdb) set remotebaud 115200   (我们输入的命令)
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
breakpoint () at kernel/kgdb.c:1876
1876            atomic_set(&kgdb_setting_breakpoint, 0);
(gdb) break console_init
Breakpoint 1 at 0xc03643c6: file drivers/char/tty_io.c, line 2932.
(gdb) c
Continuing.
[New thread 32768]

Breakpoint 1, console_init () at drivers/char/tty_io.c:2932
2932            (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);
(gdb) list
2927    void __init console_init(void)
2928    {
2929            initcall_t *call;
2930
2931            /* Setup the default TTY line discipline. */
2932            (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);
2933
2934            /*
2935             * set up the console device so that later boot sequences can
2936             * inform about problems etc..
(gdb) c
Continuing.
Linux version 2.6.15.5 (root@dengdalong) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-8))
#7 Thu Aug 30 16:08:40 CST 2007
BIOS-provided physical RAM map:
BIOS-e820: 0000000000000000 - 000000000009f800 (usable)
BIOS-e820: 000000000009f800 - 00000000000a0000 (reserved)
BIOS-e820: 00000000000ca000 - 00000000000cc000 (reserved)
BIOS-e820: 00000000000dc000 - 0000000000100000 (reserved)
BIOS-e820: 0000000000100000 - 0000000009ef0000 (usable)
BIOS-e820: 0000000009ef0000 - 0000000009efc000 (ACPI data)
BIOS-e820: 0000000009efc000 - 0000000009f00000 (ACPI NVS)
BIOS-e820: 0000000009f00000 - 000000000a000000 (usable)
BIOS-e820: 00000000fec00000 - 00000000fec10000 (reserved)
BIOS-e820: 00000000fee00000 - 00000000fee01000 (reserved)
BIOS-e820: 00000000fffe0000 - 0000000100000000 (reserved)
Waiting for connection from remote gdb...
0MB HIGHMEM available.
160MB LOWMEM available.
DMI present.
Allocating PCI resources starting at 10000000 (gap: 0a000000:f4c00000)
Built 1 zonelists
Kernel command line: ro root=/dev/sda2 kgdbwait 8250kgdb=0,115200
Initializing CPU#0
PID hash table entries: 1024 (order: 10, 16384 bytes)
Detected 2663.238 MHz processor.
Using tsc for high-res timesource
Console: colour VGA+ 80x25
Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
Memory: 158984k/163840k available (1813k kernel code, 4304k reserved, 550k data, 248k init, 0k highmem)
Checking if this processor honours the WP bit even in supervisor mode... Ok.
calibrate_delay_direct() failed to get a good estimate for loops_per_jiffy.
Probably due to long platform interrupts. Consider using "lpj=" boot option.
Mount-cache hash table entries: 512
CPU: Trace cache: 12K uops, L1 D cache: 16K
CPU: L2 cache: 1024K
Intel machine check architecture supported.
Intel machine check reporting enabled on CPU#0.
mtrr: v2.0 (20020519)
CPU: Intel(R) Pentium(R) 4 CPU 2.66GHz stepping 08
Enabling fast FPU save and restore... done.
Enabling unmasked SIMD FPU exception support... done.
Checking ’hlt’ instruction... OK.
NET: Registered protocol family 16
EISA bus registered
SCSI subsystem initialized
apm: BIOS version 1.2 Flags 0x03 (Driver version 1.16ac)
Registering GDB sysrq handler
VFS: Disk quotas dquot_6.5.1
Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
NTFS driver 2.1.25 [Flags: R/O].
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered
Real Time Clock Driver v1.12
serio: i8042 AUX port at 0x60,0x64 irq 12
serio: i8042 KBD port at 0x60,0x64 irq 1
Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing disabled
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
Floppy drive(s): fd0 is 1.44M
FDC 0 is a post-1991 82077
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
loop: loaded (max 8 devices)
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
hdc: VMware Virtual IDE CDROM Drive, ATAPI CD/DVD-ROM drive
ide1 at 0x170-0x177,0x376 on irq 15
ide-floppy driver 0.99.newide
mice: PS/2 mouse device common for all mice
md: md driver 0.90.3 MAX_MD_DEVS=256, MD_SB_DISKS=27
md: bitmap version 4.39
device-mapper: 4.4.0-ioctl (2005-01-12) initialised: dm-devel@redhat.com
EISA: Probing bus 0 at eisa.0
NET: Registered protocol family 2
input: AT Translated Set 2 keyboard as /class/input/input0
input: ImPS/2 Generic Wheel Mouse as /class/input/input1
IP route cache hash table entries: 2048 (order: 1, 8192 bytes)
TCP established hash table entries: 8192 (order: 3, 32768 bytes)
TCP bind hash table entries: 8192 (order: 3, 32768 bytes)
TCP: Hash tables configured (established 8192 bind 8192)
TCP reno registered
TCP bic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
NET: Registered protocol family 8
NET: Registered protocol family 20
Using IPI Shortcut mode
md: Autodetecting RAID arrays.
md: autorun ...
md: ... autorun DONE.
VFS: Cannot open root device "sda2" or unknown-block(0,0)
Please append a correct "root=" boot option
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[New thread 1]

到这边我们已GDB已连接上target上的kgdb了。不过我们发现文件系统挂载还存在问题。我猜想是因为上面提到的mkinitrd没有执行的缘故。这个问题我将在后面进行试验,解决后我会在blog上告诉大家。这次X86平台的kgdb调试主要是为了arm的kgdb调试做前期准备。我的最后目标是ARM目标板的kgdb调试。
   
    文件系统的挂载确实是因为initrd-2.6.15.5.img映像没有生长的缘故,initrd是“initial ramdisk”的简
写。initrd一般被用来临时的引导硬件到实际内核vmlinuz能够接管并继续引导的状态。图中的initrd-2.6.15.5.img主要是用于加载ext3等文件系统及scsi设备的驱动。
    比如,使用的是scsi硬盘,而内核vmlinuz中并没有这个scsi硬件的驱动,那么在装入scsi模块之前,内核不能加载根文件系统,但scsi模块存储在根文件系统的/lib/modules下。为了解决这个问题,能引导一个能够读实际内核的initrd内核并用initrd修正scsi引导问题。initrd-2.6.15.5.img是用gzip压缩的文件,initrd实现加载一些模块和安装文件系统等功能
阅读(398) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~