博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
慢慢欣赏linux qemu gdb调试跟踪
阅读量:4068 次
发布时间:2019-05-25

本文共 17601 字,大约阅读时间需要 58 分钟。

第一个窗口:

创建console节点, 启动qemu

rlk@ubuntu:runninglinuxkernel_4.0_x86$ cd _install_x86/rlk@ubuntu:_install_x86$ mkdir devrlk@ubuntu:_install_x86$ cd dev/rlk@ubuntu:dev$ sudo mknod console c 5 1rlk@ubuntu:dev$ lsconsolerlk@ubuntu:runninglinuxkernel_4.0_x86$ ./run.sh x86_64 debugEnable GDB debug mode

在第二个窗口开启gdb

rlk@ubuntu:runninglinuxkernel_4.0_x86$ file vmlinuxvmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=534e5567ee8043ec8f3a85cfb8cd59d6b269947a, with debug_info, not strippedrlk@ubuntu:runninglinuxkernel_4.0_x86$ gdb-multiarch --tui vmlinuxrlk@ubuntu:runninglinuxkernel_4.0_x86$NU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-gitCopyright (C) 2018 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 "x86_64-linux-gnu".Type "show configuration" for configuration details.---Type
to continue, or q
to quit---For bug reporting instructions, please see:
.Find the GDB manual and other documentation resources online at:
.For help, type "help".Type "apropos word" to search for commands related to "word"...Reading symbols from vmlinux...done.(gdb) (gdb) target remote localhost:1234 // 这一步不可或缺The program is not being run.Breakpoint 1 at 0xffffffff81ed1829: file init/main.c, line 490.Breakpoint 1 at 0xffffffff81ed1829: file init/main.c, line 490.(gdb) b start_kernelBreakpoint 1 at 0xffffffff81ed1829: file init/main.c, line 490.(gdb) cContinuing.Breakpoint 1, start_kernel () at init/main.c:490(gdb) c

这时第一个窗口显示kernel启动信息

[    0.000000] Initializing cgroup subsys cpuset[    0.000000] Initializing cgroup subsys cpu[    0.000000] Initializing cgroup subsys cpuacct[    0.000000] Linux version 4.0.0+ (rlk@ubuntu) (gcc versi1[    0.000000] Command line: rdinit=/linuxrc console=ttyS0[    0.000000] e820: BIOS-provided physical RAM map:[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x0000000e[    0.000000] BIOS-e820: [mem 0x000000000009fc00-0x0000000d[    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x0000000d[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x0000000e[    0.000000] BIOS-e820: [mem 0x0000000007fe0000-0x0000000d[    0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x0000000d[    0.000000] NX (Execute Disable) protection: active[    0.000000] SMBIOS 2.8 present.[    0.000000] e820: last_pfn = 0x7fe0 max_arch_pfn = 0x4000[    0.000000] PAT configuration [0-7]: WB  WC  UC- UC  WB  [    0.000000] found SMP MP-table at [mem 0x000f5af0-0x000f][    0.000000] Scanning 1 areas for low memory corruption[    0.000000] init_memory_mapping: [mem 0x00000000-0x000ff][    0.000000] init_memory_mapping: [mem 0x07c00000-0x07dff][    0.000000] init_memory_mapping: [mem 0x00100000-0x07bff][    0.000000] init_memory_mapping: [mem 0x07e00000-0x07fdf][    0.000000] ACPI: Early table checksum verification disad[    0.000000] ACPI: RSDP 0x00000000000F5910 000014 (v00 BO)[    0.000000] ACPI: RSDT 0x0000000007FE156F 000030 (v01 BO)[    0.000000] ACPI: FACP 0x0000000007FE144B 000074 (v01 BO)[    0.000000] ACPI: DSDT 0x0000000007FE0040 00140B (v01 BO)[    0.000000] ACPI: FACS 0x0000000007FE0000 000040[    0.000000] ACPI: APIC 0x0000000007FE14BF 000078 (v01 BO)[    0.000000] ACPI: HPET 0x0000000007FE1537 000038 (v01 BO)[    0.000000] No NUMA configuration found[    0.000000] Faking a node at [mem 0x0000000000000000-0x0][    0.000000] NODE_DATA(0) allocated [mem 0x07fdc000-0x07f][    0.000000] Zone ranges:[    0.000000]   DMA      [mem 0x0000000000001000-0x0000000][    0.000000]   DMA32    [mem 0x0000000001000000-0x0000000][    0.000000]   Normal   empty[    0.000000] Movable zone start for each node[    0.000000] Early memory node ranges[    0.000000]   node   0: [mem 0x0000000000001000-0x000000][    0.000000]   node   0: [mem 0x0000000000100000-0x000000][    0.000000] Initmem setup node 0 [mem 0x0000000000001000][    0.000000] ACPI: PM-Timer IO Port: 0x608[    0.000000] ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] en)[    0.000000] ACPI: LAPIC_NMI (acpi_id[0xff] dfl dfl lint[)[    0.000000] ACPI: IOAPIC (id[0x00] address[0xfec00000] g)[    0.000000] IOAPIC[0]: apic_id 0, version 32, address 0x3[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_ir)[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 5 global_ir)[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_ir)[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 10 global_i)[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 11 global_i)[    0.000000] Using ACPI (MADT) for SMP configuration infon[    0.000000] ACPI: HPET id: 0x8086a201 base: 0xfed00000[    0.000000] smpboot: Allowing 1 CPUs, 0 hotplug CPUs[    0.000000] PM: Registered nosave memory: [mem 0x0000000][    0.000000] PM: Registered nosave memory: [mem 0x0009f00][    0.000000] PM: Registered nosave memory: [mem 0x000a000][    0.000000] PM: Registered nosave memory: [mem 0x000f000][    0.000000] e820: [mem 0x08000000-0xfffbffff] available s[    0.000000] setup_percpu: NR_CPUS:64 nr_cpumask_bits:64 1[    0.000000] PERCPU: Embedded 30 pages/cpu @ffff880007c002[    0.000000] Built 1 zonelists in Node order, mobility gr5[    0.000000] Policy zone: DMA32[    0.000000] Kernel command line: rdinit=/linuxrc console0[    0.000000] PID hash table entries: 512 (order: 0, 4096 )[    0.000000] Memory: 111120K/130552K available (10229K ke)[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, C1[    0.000000] Hierarchical RCU implementation.[    0.000000] 	Additional per-CPU info printed with stalls.[    0.000000] 	RCU restricting CPUs from NR_CPUS=64 to nr_.[    0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=1[    0.000000] NR_IRQS:4352 nr_irqs:256 16[    0.000000] Console: colour VGA+ 80x25[    0.000000] console [ttyS0] enabled[    0.000000] tsc: Fast TSC calibration failed[    0.000000] tsc: Unable to calibrate against PIT[    0.000000] tsc: using HPET reference calibration[    0.000000] tsc: Detected 2801.482 MHz processor[    0.010000] Calibrating delay loop (skipped), value calc)[    0.011887] pid_max: default: 32768 minimum: 301[    0.012604] ACPI: Core revision 20150204[    0.021000] ACPI: All ACPI Tables successfully acquired[    0.023000] Security Framework initialized[    0.027000] SELinux:  Initializing.[    0.028459] Dentry cache hash table entries: 16384 (orde)[    0.032750] Inode-cache hash table entries: 8192 (order:)[    0.033965] Mount-cache hash table entries: 512 (order: )[    0.034210] Mountpoint-cache hash table entries: 512 (or)[    0.047000] Initializing cgroup subsys freezer[    0.050000] mce: CPU supports 10 MCE banks[    0.051000] Last level iTLB entries: 4KB 0, 2MB 0, 4MB 0[    0.051128] Last level dTLB entries: 4KB 0, 2MB 0, 4MB 00[    0.070000] Freeing SMP alternatives memory: 12K (ffffff)[    0.087000] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-11[    0.090000] ..MP-BIOS bug: 8254 timer not connected to IC[    0.090000] ...trying to set up timer (IRQ0) through the.[    0.090000] ..... (found apic 0 pin 2) ...[    0.094000] ....... failed.[    0.094000] ...trying to set up timer as Virtual Wire IR.[    0.107000] ..... works.[    0.109000] APIC calibration not consistent with PM-Times[    0.109000] APIC delta adjusted to PM-Timer: 6250023 (10)[    0.111000] smpboot: CPU0: AMD QEMU Virtual CPU version )[    0.113949] Performance Events: Broken PMU hardware dete.[    0.115246] Failed to access perfctr msr (MSR c0010004 i)[    0.138605] Huh? What family is it: 0x6?![    0.139151] MCE: In-kernel MCE decoding enabled.[    0.140797] x86: Booted up 1 node, 1 CPUs[    0.141342] smpboot: Total of 1 processors activated (56)[    0.172266] devtmpfs: initialized[    0.192000] RTC time:  7:30:30, date: 02/16/21[    0.201708] kworker/u2:1 (16) used greatest stack depth:t[    0.208000] NET: Registered protocol family 16[    0.227000] cpuidle: using governor ladder[    0.227430] cpuidle: using governor menu[    0.233000] ACPI: bus type PCI registered[    0.240000] PCI: Using configuration type 1 for base accs[    0.259320] kworker/u2:1 (36) used greatest stack depth:t[    0.370000] ACPI: Added _OSI(Module Device)[    0.370167] ACPI: Added _OSI(Processor Device)[    0.371190] ACPI: Added _OSI(3.0 _SCP Extensions)[    0.372112] ACPI: Added _OSI(Processor Aggregator Device)[    0.419128] ACPI: Interpreter enabled[    0.420542] ACPI Exception: AE_NOT_FOUND, While evaluati)[    0.423906] ACPI Exception: AE_NOT_FOUND, While evaluati)[    0.428000] ACPI: (supports S0 S3 S4 S5)[    0.428305] ACPI: Using IOAPIC for interrupt routing[    0.432547] PCI: Using host bridge windows from ACPI; ifg[    0.595000] ACPI: PCI Root Bridge [PCI0] (domain 0000 [b)[    0.597558] acpi PNP0A03:00: _OSC: OS supports [ASPM Clo][    0.598566] acpi PNP0A03:00: _OSC failed (AE_NOT_FOUND);M[    0.601973] acpi PNP0A03:00: fail to add MMCONFIG inform.[    0.607325] PCI host bridge to bus 0000:00[    0.610000] pci_bus 0000:00: root bus resource [bus 00-f][    0.610598] pci_bus 0000:00: root bus resource [io  0x00][    0.611155] pci_bus 0000:00: root bus resource [io  0x0d][    0.613315] pci_bus 0000:00: root bus resource [mem 0x00][    0.614146] pci_bus 0000:00: root bus resource [mem 0x08][    0.615467] pci_bus 0000:00: root bus resource [mem 0x10][    0.640220] pci 0000:00:01.1: legacy IDE quirk: reg 0x10][    0.642274] pci 0000:00:01.1: legacy IDE quirk: reg 0x14][    0.642807] pci 0000:00:01.1: legacy IDE quirk: reg 0x18][    0.643120] pci 0000:00:01.1: legacy IDE quirk: reg 0x1c][    0.648877] pci 0000:00:01.3: quirk: [io  0x0600-0x063f]I[    0.649175] pci 0000:00:01.3: quirk: [io  0x0700-0x070f]B[    0.714000] ACPI: PCI Interrupt Link [LNKA] (IRQs 5 *10 )[    0.717000] ACPI: PCI Interrupt Link [LNKB] (IRQs 5 *10 )[    0.719452] ACPI: PCI Interrupt Link [LNKC] (IRQs 5 10 *)[    0.724369] ACPI: PCI Interrupt Link [LNKD] (IRQs 5 10 *)[    0.727492] ACPI: PCI Interrupt Link [LNKS] (IRQs *9)[    0.741000] ACPI: Enabled 2 GPEs in block 00 to 0F[    0.757972] vgaarb: setting as boot device: PCI:0000:00:0[    0.758000] vgaarb: device added: PCI:0000:00:02.0,decode[    0.758233] vgaarb: loaded[    0.759437] vgaarb: bridge control possible 0000:00:02.0[    0.768145] SCSI subsystem initialized[    0.780000] pps_core: LinuxPPS API ver. 1 registered[    0.780192] pps_core: Software ver. 5.3.6 - Copyright 20>[    0.787000] PTP clock support registered[    0.792000] PCI: Using ACPI for IRQ routing[    0.821000] NetLabel: Initializing[    0.821186] NetLabel:  domain hash size = 128[    0.822221] NetLabel:  protocols = UNLABELED CIPSOv4[    0.826618] NetLabel:  unlabeled traffic allowed by defat[    0.828593] HPET: 3 timers in total, 0 timers will be usr[    0.831000] hpet0: at MMIO 0xfed00000, IRQs 2, 8, 0[    0.832209] hpet0: 3 comparators, 64-bit 100.000000 MHz r[    0.840000] Switched to clocksource hpet[    1.263354] pnp: PnP ACPI init[    1.315208] pnp: PnP ACPI: found 6 devices[    1.715603] NET: Registered protocol family 2[    1.746257] TCP established hash table entries: 1024 (or)[    1.748337] TCP bind hash table entries: 1024 (order: 2,)[    1.750025] TCP: Hash tables configured (established 102)[    1.753760] TCP: reno registered[    1.755127] UDP hash table entries: 256 (order: 1, 8192 )[    1.756905] UDP-Lite hash table entries: 256 (order: 1, )[    1.765027] NET: Registered protocol family 1[    1.777854] RPC: Registered named UNIX socket transport .[    1.779829] RPC: Registered udp transport module.[    1.780825] RPC: Registered tcp transport module.[    1.781850] RPC: Registered tcp NFSv4.1 backchannel tran.[    1.784213] pci 0000:00:01.0: PIIX3: Enabling Passive Ree[    1.785735] pci 0000:00:00.0: Limiting direct PCI/PCI trs[    1.787456] pci 0000:00:01.0: Activating ISA DMA hang wos[    1.801902] microcode: AMD CPU family 0x6 not supported[    1.830441] Scanning for low memory corruption every 60 s[    1.889198] futex hash table entries: 256 (order: 2, 163)[    1.895382] audit: initializing netlink subsys (disabled)[    1.901962] audit: type=2000 audit(1613460630.898:1): ind[    1.952932] HugeTLB registered 2 MB page size, pre-allocs[    2.304107] VFS: Disk quotas dquot_6.5.2[    2.309683] VFS: Dquot-cache hash table entries: 512 (or)[    2.479154] NFS: Registering the id_resolver key type[    2.491160] Key type id_resolver registered[    2.493386] Key type id_legacy registered[    2.517859] 9p: Installing v9fs 9p2000 file system support[    2.661222] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)[    2.669101] io scheduler noop registered[    2.672945] io scheduler deadline registered[    2.692790] io scheduler cfq registered (default)[    2.733926] pci_hotplug: PCI Hot Plug PCI Core version: 0.5[    2.793286] input: Power Button as /devices/LNXSYSTM:00/LNXPWRBN:00/input/input0[    2.800001] tsc: Refined TSC clocksource calibration: 2801.598 MHz[    2.809242] ACPI: Power Button [PWRF][    3.825624] Switched to clocksource tsc[    4.653061] ACPI: PCI Interrupt Link [LNKD] enabled at IRQ 11[    4.717238] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled[    4.760445] 00:05: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A[    4.842725] Non-volatile memory driver v1.3[    4.849177] Linux agpgart interface v0.103[    4.907008] VFIO - User Level meta-driver version: 0.3[    4.930563] i8042: PNP: PS/2 Controller [PNP0303:KBD,PNP0f13:MOU] at 0x60,0x64 irq 1,12[    4.964139] serio: i8042 KBD port at 0x60,0x64 irq 1[    4.966874] serio: i8042 AUX port at 0x60,0x64 irq 12[    4.987065] mousedev: PS/2 mouse device common for all mice[    5.022040] rtc_cmos 00:00: RTC can wake from S4[    5.041829] input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input1[    5.060081] rtc_cmos 00:00: rtc core: registered rtc_cmos as rtc0[    5.075261] rtc_cmos 00:00: alarms up to one day, y3k, 114 bytes nvram, hpet irqs[    5.107055] hidraw: raw HID events driver (C) Jiri Kosina[    5.212112] Netfilter messages via NETLINK v0.30.[    5.216179] nf_conntrack version 0.5.0 (868 buckets, 3472 max)[    5.223942] ctnetlink v0.93: registering with nfnetlink.[    5.243300] ip_tables: (C) 2000-2006 Netfilter Core Team[    5.243300] TCP: cubic registered[    5.243300] Initializing XFRM netlink socket[    5.300048] NET: Registered protocol family 10[    5.367313] ip6_tables: (C) 2000-2006 Netfilter Core Team[    5.378250] sit: IPv6 over IPv4 tunneling driver[    5.421105] NET: Registered protocol family 17[    5.432882] 9pnet: Installing 9P2000 support[    5.488288] Key type dns_resolver registered[    5.555895] registered taskstats version 1[    5.588298]   Magic number: 9:395:521[    5.729248] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input3[    5.759681] VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6[    5.761281] Please append a correct "root=" boot option; here are the available partitions:[    5.766110] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)[    5.766613] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.0.0+ #1[    5.766613] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014[    5.766613]  ffffffff00000000 ffffffff819f3a46 ffff8800070f0000 ffff8800070dfd48[    5.766613]  ffff8800070dfd98 ffffffff8153e4fe ffff8800070dfdc8 ffffffff8153e56e[    5.766613]  00000000ffffffff 0000000000000000 0000000000000000 0000000020656c62[    5.766613] Call Trace:[    5.766613]  [
] ? rest_init+0x9a/0x9a[ 5.766613] [
] ? __dump_stack+0x1f/0x22[ 5.766613] [
] ? dump_stack+0x6d/0x87[ 5.766613] [
] ? panic+0xc4/0x263[ 5.766613] [
] ? mount_block_root+0x11c/0x1f3[ 5.766613] [
] ? pmd_to_page+0x7f1/0xec1[ 5.766613] [
] ? mount_root+0x5d/0x62[ 5.766613] [
] ? prepare_namespace+0x1ad/0x1ee[ 5.766613] [
] ? kernel_init_freeable+0x113/0x120[ 5.766613] [
] ? kernel_init+0x11/0x123[ 5.766613] [
] ? kthread_stop+0xb7/0xb7[ 5.766613] [
] ? ret_from_fork+0x58/0x90[ 5.766613] [
] ? rest_init+0x9a/0x9a[ 5.766613] Kernel Offset: 0x0 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffff9fffffff)[ 5.766613] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

上面挂死的原因是没有指定rootfs。

方法是:

rlk@ubuntu:runninglinuxkernel_4.0_x86$ ./run_debian_x86_64.sh run debug

因为上述脚本制定了ramdisk

 

第二个例子,调试cpuinfo_open

第一步:gdb界面设置断点

第二步:linux命令行界面 触发函数对应的命令

第三步:gdb界面敲入bt等调试命令进行调试

第四步:gdb界面,调试完毕继续执行键入c

第五步:命令行界面显示完整命令

在qemu环境中用gdb调试Linux内核

https://www.cnblogs.com/wipan/p/9264979.html

QEMU+gdb调试Linux内核全过程

https://blog.csdn.net/jasonlee_lijiaqi/article/details/80967912

使用QEMU和GDB调试Linux内核

https://consen.github.io/2018/01/17/debug-linux-kernel-with-qemu-and-gdb/

How to debug the Linux kernel with GDB and QEMU?

https://stackoverflow.com/questions/11408041/how-to-debug-the-linux-kernel-with-gdb-and-qemu

QEMU+GDB调试Linux内核总结(全)

https://blog.csdn.net/weixin_37867857/article/details/88205130

使用QEMU和GDB调试Linux内核

https://consen.github.io/2018/01/17/debug-linux-kernel-with-qemu-and-gdb/

How to Build A Custom Linux Kernel For Qemu (2015 Edition)

http://mgalgs.github.io/2015/05/16/how-to-build-a-custom-linux-kernel-for-qemu-2015-edition.html

Debugging kernel and modules via gdb

https://www.kernel.org/doc/Documentation/dev-tools/gdb-kernel-debugging.rst

借助qemu使用gdb去跟踪和学习内核

https://blog.csdn.net/weixin_38227420/article/details/89923867

你可能感兴趣的文章
mongoDB简介
查看>>
Redis持久化存储(AOF与RDB两种模式)
查看>>
memcached工作原理与优化建议
查看>>
Redis与Memcached的区别
查看>>
redis sharding方案
查看>>
程序员最核心的竞争力是什么?
查看>>
Node.js机制及原理理解初步
查看>>
linux CPU个数查看
查看>>
分布式应用开发相关的面试题收集
查看>>
简单理解Socket及TCP/IP、Http、Socket的区别
查看>>
利用HTTP Cache来优化网站
查看>>
利用负载均衡优化和加速HTTP应用
查看>>
消息队列设计精要
查看>>
分布式缓存负载均衡负载均衡的缓存处理:虚拟节点对一致性hash的改进
查看>>
分布式存储系统设计(1)—— 系统架构
查看>>
MySQL数据库的高可用方案总结
查看>>
常用排序算法总结(一) 比较算法总结
查看>>
SSH原理与运用
查看>>
SIGN UP BEC2
查看>>
S3C2440中对LED驱动电路的理解
查看>>