1.
1.1 aarch64-linux-gnu- defconfig
[lhu3@zch127bld08 linux-stable]$ qemu-system-aarch64 --version
QEMU emulator version 5.0.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers
[lake@localhost linux-stable]$
##### aarch64/gcc9.2 build kernel 5.10 with arch/arm64/configs/defconfig
[lake@localhost linux-stable]$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (BLD = 1649) 9.2.0 20190812 (build.sh rev=gaf57174 s=F920 -i /opt/freescale Xarmv8 -V release_gaf57174_build_Fed_Xarmv8)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
1.2 qemu/gdb server
### -S wait for gdb
## -s default -gdb tcp::1234
[lake@localhost linux-stable]$ qemu-system-aarch64 -device VGA -machine virt -cpu cortex-a57 -m 1024M -kernel arch/arm64/boot/Image -initrd ../../yocto/qemu-aarch64-defconfig/initram-root.cpio.gz -append "console=ttyAMA0 root=/dev/ram rootwait rw earlycon rdinit=/sbin/init" -net nic -net user -serial stdio -S -gdb tcp::41234
1.3 CROSS build gdb
[lake@localhost source]$ wget -q https://ftp.gnu.org/gnu/gdb/gdb-10.2.tar.gz --no-check-certificate
##
[lake@localhost gdb-10.2]$ ./configure --target=aarch64-linux-gnu --program-prefix=aarch64-linux-gnu- --prefix=$HOME/extra/source/tmp
[lake@localhost source]$ export PATH=/home/lhu3/extra/source/tmp/bin:$PATH
[lake@localhost source]$ which aarch64-linux-gnu-gdb
~/extra/source/tmp/bin/aarch64-linux-gnu-gdb
[lake@localhost linux-stable]$ which aarch64-linux-gnu-gdb
~/extra/source/tmp/bin/aarch64-linux-gnu-gdb
[lake@localhost linux-stable]$ ~/extra/source/tmp/bin/aarch64-linux-gnu-gdb --version
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
1.4 gdb break start_kernel
[lake@localhost source]$ cd lfs/linux-stable/
[lake@localhost linux-stable]$ aarch64-linux-gnu-gdb vmlinux
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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 "--host=x86_64-pc-linux-gnu --target=aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from vmlinux...
(gdb) target remote :41234
Remote debugging using :41234
0x0000000040000000 in ?? ()
(gdb) hbreak start_kernel
Hardware assisted breakpoint 1 at 0xffff800011310a24: file init/main.c, line 850.
(gdb) c
Continuing.
Breakpoint 1, start_kernel () at init/main.c:850
850 {
(gdb) list
845 {
846 rest_init();
847 }
848
849 asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
850 {
851 char *command_line;
852 char *after_dashes;
853
854 set_task_stack_end_magic(&init_task);
(gdb) c
Continuing.
[Inferior 1 (process 1) exited normally]
(gdb)
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070]
[ 0.000000] Linux version 5.10.81-00615-g47bff1c097d1 (lake@localhost ) (aarch64-linux-gnu-gcc (BLD = 1649) 9.2.0 20190812 (build.sh rev=gaf57174 s=F920 -i /opt/freescale Xarmv8 -V release_gaf57174_build_Fed_Xarmv8), GNU ld (GNU Binutils) 2.32) #13 SMP PREEMPT Fri Nov 26 17:39:57 CST 2021
[ 0.000000] Machine model: linux,dummy-virt
[ 0.000000] efi: UEFI not found.
[ 0.000000] earlycon: pl11 at MMIO 0x0000000009000000 (options '')
[ 0.000000] printk: bootconsole [pl11] enabled
[ 0.000000] NUMA: No NUMA configuration found
.............
2. gdb with python Refer to kernel/Documentation/dev-tools/gdb-kernel-debugging.rst
2.1 build python with --enable-shared
2.2 build gdb/aarch64-linux-gnu with --with-python=yes
[lake@localhost gdb-10.2]$ ./configure --target=aarch64-linux-gnu --program-prefix=aarch64-linux-gnu- --prefix=/home/lhu3/extra/source/tmp --with-python=yes
2.3 Test python with gdb
$ ~/extra/source/tmp/bin/aarch64-linux-gnu-gdb -q -ex "python print(1+1)" -ex "quit"
2
2.4 Enable CONFIG_GDB_SCRIPTS in kernel config
2.5 Test with lx-version with kernel/scripts/gdb/vmlinux-gdb.py
[lake@localhost linux-stable]$ ~/extra/source/tmp/bin/aarch64-linux-gnu-gdb -ex "add-auto-load-safe-path scripts/gdb/vmlinux-gdb.py" -ex "file vmlinux" -ex "lx-version" -q
Reading symbols from vmlinux...
Linux version 5.10.81-00617-ge6bbcc8c95b7-dirty (lake@localhost ) (aarch64-linux-gnu-gcc (BLD = 1649) 9.2.0 20190812 (build.sh rev=gaf57174 s=F920 -i /opt/freescale Xarmv8 -V release_gaf57174_build_Fed_Xarmv8), GNU ld (GNU Binutils) 2.32) #15 SMP PREEMPT Wed Dec 1 15:31:42 CST 2021
(gdb) quit
[lake@localhost linux-stable]$
[lake@localhost linux-stable]$ ~/extra/source/tmp/bin/aarch64-linux-gnu-gdb -ex "add-auto-load-safe-path scripts/gdb/vmlinux-gdb.py" -ex "file vmlinux"
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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 "--host=x86_64-pc-linux-gnu --target=aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Reading symbols from vmlinux...
(gdb) target remote :41234
Remote debugging using :41234
0x0000000040000000 in ?? ()
(gdb) "lx-version"
Undefined command: "". Try "help".
(gdb) lx-version
Python Exception <class 'gdb.MemoryError'> Cannot access memory at address 0xffff800010c10130:
Error occurred in Python: Cannot access memory at address 0xffff800010c10130
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0xffff800010beec10 in __cpu_do_idle () at arch/arm64/kernel/process.c:79
79 }
(gdb) apropos lx
function lx_clk_core_lookup -- Find struct clk_core by name
function lx_current -- Return current task.
function lx_device_find_by_bus_name -- Find struct device by bus and name (both strings)
function lx_device_find_by_class_name -- Find struct device by class and name (both strings)
function lx_module -- Find module by name and return the module variable.
function lx_per_cpu -- Return per-cpu variable.
function lx_rb_first -- Lookup and return a node from an RBTree
function lx_rb_last -- Lookup and return a node from an RBTree.
function lx_rb_next -- Lookup and return a node from an RBTree.
function lx_rb_prev -- Lookup and return a node from an RBTree.
function lx_task_by_pid -- Find Linux task by PID and return the task_struct variable.
function lx_thread_info -- Calculate Linux thread_info from task variable.
function lx_thread_info_by_pid -- Calculate Linux thread_info from task variable found by pid
lx-clk-summary -- Print clk tree summary
lx-cmdline -- Report the Linux Commandline used in the current kernel.
lx-configdump -- Output kernel config to the filename specified as the command
lx-cpus -- List CPU status arrays
lx-device-list-bus -- Print devices on a bus (or all buses if not specified)
lx-device-list-class -- Print devices in a class (or all classes if not specified)
lx-device-list-tree -- Print a device and its children recursively
lx-dmesg -- Print Linux kernel log buffer.
lx-fdtdump -- Output Flattened Device Tree header and dump FDT blob to the filename
lx-genpd-summary -- Print genpd summary
lx-iomem -- Identify the IO memory resource locations defined by the kernel
lx-ioports -- Identify the IO port resource locations defined by the kernel
lx-list-check -- Verify a list consistency
lx-lsmod -- List currently loaded modules.
lx-mounts -- Report the VFS mounts of the current process namespace.
lx-ps -- Dump Linux tasks.
lx-symbols -- (Re-)load symbols of Linux kernel and currently loaded modules.
--Type <RET> for more, q to quit, c to continue without paging--
lx-timerlist -- Print /proc/timer_list
lx-version -- Report the Linux Version of the current kernel.
(gdb) lx-ps
TASK PID COMM
0xffff8000118c18c0 0 swapper/0
0xffff000002070000 1 init
0xffff000002070dc0 2 kthreadd
0xffff000002071b80 3 rcu_gp
0xffff000002072940 4 rcu_par_gp
0xffff000002073700 5 kworker/0:0
0xffff0000020744c0 6 kworker/0:0H
0xffff000002075280 7 kworker/u2:0
0xffff000002076040 8 mm_percpu_wq
0xffff000002076e00 9 rcu_tasks_kthre
0xffff000002090000 10 ksoftirqd/0
0xffff000002090dc0 11 rcu_preempt
0xffff000002091b80 12 migration/0
0xffff000002092940 13 cpuhp/0
0xffff000002093700 14 kdevtmpfs
0xffff0000020944c0 15 netns
0xffff000002095280 16 kworker/0:1
0xffff000002096040 17 kauditd
0xffff000002096e00 18 oom_reaper
0xffff0000021c0000 19 writeback
0xffff0000021c0dc0 20 kcompactd0
0xffff0000021c1b80 21 ksmd
0xffff0000021c2940 22 khugepaged
0xffff000002208dc0 31 cryptd
0xffff000002209b80 47 kintegrityd
0xffff000002208000 48 kblockd
0xffff00000220d280 49 blkcg_punt_bio
0xffff00000220ee00 50 tpm_dev_wq
0xffff00000220a940 51 ata_sff
--Type <RET> for more, q to quit, c to continue without paging--
0xffff00000220e040 52 edac-poller
0xffff00000220c4c0 53 devfreq_wq
0xffff00000220b700 54 watchdogd
0xffff0000021c3700 55 kworker/u2:1
0xffff0000021c44c0 56 kworker/0:1H
0xffff0000021c5280 57 rpciod
0xffff0000021c6e00 58 kworker/u3:0
0xffff0000021c6040 59 xprtiod
0xffff000003b80000 87 kswapd0
0xffff000003b82940 88 nfsiod
0xffff000003b86e00 91 ttm_swap
0xffff000003b844c0 93 kworker/u2:2
0xffff000003b86040 95 vfio-irqfd-clea
0xffff000003b83700 100 init
0xffff000003b81b80 101 init
0xffff000003b85280 102 init
0xffff000003b80dc0 103 init
(gdb)
(gdb) lx-version
Linux version 5.10.81-00617-ge6bbcc8c95b7-dirty (lake@localhost ) (aarch64-linux-gnu-gcc (BLD = 1649) 9.2.0 20190812 (build.sh rev=gaf57174 s=F920 -i /opt/freescale Xarmv8 -V release_gaf57174_build_Fed_Xarmv8), GNU ld (GNU Binutils) 2.32) #15 SMP PREEMPT Wed Dec 1 15:31:42 CST 2021
(gdb) lx-cmdline
console=ttyAMA0 root=/dev/ram rootwait rw earlycon rdinit=/sbin/init
(gdb) lx-fdtdump
fdt_magic: 0xD00DFEED
fdt_totalsize: 0x100000
off_dt_struct: 0x40
off_dt_strings: 0x1B48
off_mem_rsvmap: 0x30
version: 17
last_comp_version: 2
Dumped fdt blob to fdtdump.dtb
(gdb)
(gdb) lx-clk-summary
enable prepare protect
clock count count count rate
------------------------------------------------------------------------
clk24mhz 4 5 0 24000000
(gdb)
(gdb) lx-mount
mount super_block devname pathname fstype options
0xffff000002024140 0xffff000002011000 none / rootfs rw 0 0
0xffff00000222cc80 0xffff000003e4d000 none /proc proc rw,nodiratime,relatime 0 0
0xffff00000222cdc0 0xffff000003e4d800 none /sys sysfs rw,relatime 0 0
(gdb) lx-lsmod
Address Module Size Used by
(gdb)
(gdb) lx-dmesg
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070]
[ 0.000000] Linux version 5.10.81-00617-ge6bbcc8c95b7-dirty (lake@localhost ) (aarch64-linux-gnu-gcc (BLD = 1649) 9.2.0 20190812 (build.sh rev=gaf57174 s=F920 -i /opt/freescale Xarmv8 -V release_gaf57174_build_Fed_Xarmv8), GNU ld (GNU Binutils) 2.32) #15 SMP PREEMPT Wed Dec 1 15:31:42 CST 2021
[ 0.000000] Machine model: linux,dummy-virt
[ 0.000000] efi: UEFI not found.
[ 0.000000] earlycon: pl11 at MMIO 0x0000000009000000 (options '')
[ 0.000000] printk: bootconsole [pl11] enabled
[ 0.000000] NUMA: No NUMA configuration found
[ 0.000000] NUMA: Faking a node at [mem 0x0000000040000000-0x000000007fffffff]
[ 0.000000] NUMA: NODE_DATA [mem 0x7fdf6b00-0x7fdf8fff]
[lake@iZbp19xtvqkuusirldf83dZ ~]$