€•ÂjŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ:/translations/zh_CN/process/debugging/gdb-kernel-debugging”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ:/translations/zh_TW/process/debugging/gdb-kernel-debugging”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ:/translations/it_IT/process/debugging/gdb-kernel-debugging”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ:/translations/ja_JP/process/debugging/gdb-kernel-debugging”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ:/translations/ko_KR/process/debugging/gdb-kernel-debugging”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ:/translations/sp_SP/process/debugging/gdb-kernel-debugging”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒ highlightlang”“”)”}”(hhh]”h}”(h]”h ]”h"]”h$]”h&]”Œlang”Œnone”Œforce”‰Œlinenothreshold”Šÿÿÿÿÿÿÿuh1h¡hhhžhhŸŒT/var/lib/git/docbuild/linux/Documentation/process/debugging/gdb-kernel-debugging.rst”h KubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒ$Debugging kernel and modules via gdb”h]”hŒ$Debugging kernel and modules via gdb”…””}”(hh¸hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¶hh³hžhhŸh°h KubhŒ paragraph”“”)”}”(hXìThe kernel debugger kgdb, hypervisors like QEMU or JTAG-based hardware interfaces allow to debug the Linux kernel and its modules during runtime using gdb. Gdb comes with a powerful scripting interface for python. The kernel provides a collection of helper scripts that can simplify typical kernel debugging steps. This is a short tutorial about how to enable and use them. It focuses on QEMU/KVM virtual machines as target, but the examples can be transferred to the other gdb stubs as well.”h]”hXìThe kernel debugger kgdb, hypervisors like QEMU or JTAG-based hardware interfaces allow to debug the Linux kernel and its modules during runtime using gdb. Gdb comes with a powerful scripting interface for python. The kernel provides a collection of helper scripts that can simplify typical kernel debugging steps. This is a short tutorial about how to enable and use them. It focuses on QEMU/KVM virtual machines as target, but the examples can be transferred to the other gdb stubs as well.”…””}”(hhÈhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h Khh³hžhubh²)”}”(hhh]”(h·)”}”(hŒ Requirements”h]”hŒ Requirements”…””}”(hhÙhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¶hhÖhžhhŸh°h KubhŒ bullet_list”“”)”}”(hhh]”hŒ list_item”“”)”}”(hŒ]gdb 7.2+ (recommended: 7.4+) with python support enabled (typically true for distributions) ”h]”hÇ)”}”(hŒ[gdb 7.2+ (recommended: 7.4+) with python support enabled (typically true for distributions)”h]”hŒ[gdb 7.2+ (recommended: 7.4+) with python support enabled (typically true for distributions)”…””}”(hhòhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h Khhîubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhhéhžhhŸh°h Nubah}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1hçhŸh°h KhhÖhžhubeh}”(h]”Œ requirements”ah ]”h"]”Œ requirements”ah$]”h&]”uh1h±hh³hžhhŸh°h Kubh²)”}”(hhh]”(h·)”}”(hŒSetup”h]”hŒSetup”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¶hjhžhhŸh°h Kubhè)”}”(hhh]”(hí)”}”(hŒòCreate a virtual Linux machine for QEMU/KVM (see www.linux-kvm.org and www.qemu.org for more details). For cross-development, https://landley.net/aboriginal/bin keeps a pool of machine images and toolchains that can be helpful to start from. ”h]”hÇ)”}”(hŒñCreate a virtual Linux machine for QEMU/KVM (see www.linux-kvm.org and www.qemu.org for more details). For cross-development, https://landley.net/aboriginal/bin keeps a pool of machine images and toolchains that can be helpful to start from.”h]”(hŒ~Create a virtual Linux machine for QEMU/KVM (see www.linux-kvm.org and www.qemu.org for more details). For cross-development, ”…””}”(hj.hžhhŸNh NubhŒ reference”“”)”}”(hŒ"https://landley.net/aboriginal/bin”h]”hŒ"https://landley.net/aboriginal/bin”…””}”(hj8hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j:uh1j6hj.ubhŒQ keeps a pool of machine images and toolchains that can be helpful to start from.”…””}”(hj.hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h Khj*ubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhj'hžhhŸh°h Nubhí)”}”(hŒ Build the kernel with CONFIG_GDB_SCRIPTS enabled, but leave CONFIG_DEBUG_INFO_REDUCED off. If your architecture supports CONFIG_FRAME_POINTER, keep it enabled. ”h]”hÇ)”}”(hŒŸBuild the kernel with CONFIG_GDB_SCRIPTS enabled, but leave CONFIG_DEBUG_INFO_REDUCED off. If your architecture supports CONFIG_FRAME_POINTER, keep it enabled.”h]”hŒŸBuild the kernel with CONFIG_GDB_SCRIPTS enabled, but leave CONFIG_DEBUG_INFO_REDUCED off. If your architecture supports CONFIG_FRAME_POINTER, keep it enabled.”…””}”(hj[hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h KhjWubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhj'hžhhŸh°h Nubhí)”}”(hXÃInstall that kernel on the guest, turn off KASLR if necessary by adding "nokaslr" to the kernel command line. Alternatively, QEMU allows to boot the kernel directly using -kernel, -append, -initrd command line switches. This is generally only useful if you do not depend on modules. See QEMU documentation for more details on this mode. In this case, you should build the kernel with CONFIG_RANDOMIZE_BASE disabled if the architecture supports KASLR. ”h]”hÇ)”}”(hXÂInstall that kernel on the guest, turn off KASLR if necessary by adding "nokaslr" to the kernel command line. Alternatively, QEMU allows to boot the kernel directly using -kernel, -append, -initrd command line switches. This is generally only useful if you do not depend on modules. See QEMU documentation for more details on this mode. In this case, you should build the kernel with CONFIG_RANDOMIZE_BASE disabled if the architecture supports KASLR.”h]”hXÆInstall that kernel on the guest, turn off KASLR if necessary by adding “nokaslr†to the kernel command line. Alternatively, QEMU allows to boot the kernel directly using -kernel, -append, -initrd command line switches. This is generally only useful if you do not depend on modules. See QEMU documentation for more details on this mode. In this case, you should build the kernel with CONFIG_RANDOMIZE_BASE disabled if the architecture supports KASLR.”…””}”(hjshžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K"hjoubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhj'hžhhŸh°h Nubhí)”}”(hŒQBuild the gdb scripts (required on kernels v5.1 and above):: make scripts_gdb ”h]”(hÇ)”}”(hŒat VM startup time by appending "-s" to the QEMU command line ”h]”hÇ)”}”(hŒ=at VM startup time by appending "-s" to the QEMU command line”h]”hŒAat VM startup time by appending “-s†to the QEMU command line”…””}”(hjÐhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K0hjÌubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÉubah}”(h]”h ]”h"]”h$]”h&]”j j uh1hçhŸh°h K0hjÅubah}”(h]”h ]”h"]”h$]”h&]”uh1jÃhŸh°h K0hj±ubhÇ)”}”(hŒor”h]”hŒor”…””}”(hjðhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K2hj±ubjÄ)”}”(hŒH- during runtime by issuing "gdbserver" from the QEMU monitor console ”h]”hè)”}”(hhh]”hí)”}”(hŒDduring runtime by issuing "gdbserver" from the QEMU monitor console ”h]”hÇ)”}”(hŒCduring runtime by issuing "gdbserver" from the QEMU monitor console”h]”hŒGduring runtime by issuing “gdbserver†from the QEMU monitor console”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K4hjubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhjubah}”(h]”h ]”h"]”h$]”h&]”j j uh1hçhŸh°h K4hjþubah}”(h]”h ]”h"]”h$]”h&]”uh1jÃhŸh°h K4hj±ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhj'hžhhŸh°h Nubhí)”}”(hŒcd /path/to/linux-build ”h]”hÇ)”}”(hŒcd /path/to/linux-build”h]”hŒcd /path/to/linux-build”…””}”(hj3hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K7hj/ubah}”(h]”h ]”h"]”h$]”h&]”uh1hìhj'hžhhŸh°h Nubhí)”}”(hX Start gdb: gdb vmlinux Note: Some distros may restrict auto-loading of gdb scripts to known safe directories. In case gdb reports to refuse loading vmlinux-gdb.py, add:: add-auto-load-safe-path /path/to/linux-build to ~/.gdbinit. See gdb help for more details. ”h]”(hÇ)”}”(hŒStart gdb: gdb vmlinux”h]”hŒStart gdb: gdb vmlinux”…””}”(hjKhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K9hjGubhÇ)”}”(hŒ’Note: Some distros may restrict auto-loading of gdb scripts to known safe directories. In case gdb reports to refuse loading vmlinux-gdb.py, add::”h]”hŒ‘Note: Some distros may restrict auto-loading of gdb scripts to known safe directories. In case gdb reports to refuse loading vmlinux-gdb.py, add:”…””}”(hjYhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K;hjGubjš)”}”(hŒ,add-auto-load-safe-path /path/to/linux-build”h]”hŒ,add-auto-load-safe-path /path/to/linux-build”…””}”hjgsbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h K>hjGubhÇ)”}”(hŒ-to ~/.gdbinit. See gdb help for more details.”h]”hŒ-to ~/.gdbinit. See gdb help for more details.”…””}”(hjuhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K@hjGubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhj'hžhhŸh°h Nubhí)”}”(hŒ;Attach to the booted guest:: (gdb) target remote :1234 ”h]”(hÇ)”}”(hŒAttach to the booted guest::”h]”hŒAttach to the booted guest:”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h KBhj‰ubjš)”}”(hŒ(gdb) target remote :1234”h]”hŒ(gdb) target remote :1234”…””}”hj›sbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h KDhj‰ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhj'hžhhŸh°h Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1hçhŸh°h Khjhžhubeh}”(h]”Œsetup”ah ]”h"]”Œsetup”ah$]”h&]”uh1h±hh³hžhhŸh°h Kubh²)”}”(hhh]”(h·)”}”(hŒ0Examples of using the Linux-provided gdb helpers”h]”hŒ0Examples of using the Linux-provided gdb helpers”…””}”(hjÀhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¶hj½hžhhŸh°h KHubhè)”}”(hhh]”(hí)”}”(hX]Load module (and main kernel) symbols:: (gdb) lx-symbols loading vmlinux scanning for modules in /home/user/linux/build loading @0xffffffffa0020000: /home/user/linux/build/net/netfilter/xt_tcpudp.ko loading @0xffffffffa0016000: /home/user/linux/build/net/netfilter/xt_pkttype.ko loading @0xffffffffa0002000: /home/user/linux/build/net/netfilter/xt_limit.ko loading @0xffffffffa00ca000: /home/user/linux/build/net/packet/af_packet.ko loading @0xffffffffa003c000: /home/user/linux/build/fs/fuse/fuse.ko ... loading @0xffffffffa0000000: /home/user/linux/build/drivers/ata/ata_generic.ko ”h]”(hÇ)”}”(hŒ'Load module (and main kernel) symbols::”h]”hŒ&Load module (and main kernel) symbols:”…””}”(hjÕhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h KJhjÑubjš)”}”(hX(gdb) lx-symbols loading vmlinux scanning for modules in /home/user/linux/build loading @0xffffffffa0020000: /home/user/linux/build/net/netfilter/xt_tcpudp.ko loading @0xffffffffa0016000: /home/user/linux/build/net/netfilter/xt_pkttype.ko loading @0xffffffffa0002000: /home/user/linux/build/net/netfilter/xt_limit.ko loading @0xffffffffa00ca000: /home/user/linux/build/net/packet/af_packet.ko loading @0xffffffffa003c000: /home/user/linux/build/fs/fuse/fuse.ko ... loading @0xffffffffa0000000: /home/user/linux/build/drivers/ata/ata_generic.ko”h]”hX(gdb) lx-symbols loading vmlinux scanning for modules in /home/user/linux/build loading @0xffffffffa0020000: /home/user/linux/build/net/netfilter/xt_tcpudp.ko loading @0xffffffffa0016000: /home/user/linux/build/net/netfilter/xt_pkttype.ko loading @0xffffffffa0002000: /home/user/linux/build/net/netfilter/xt_limit.ko loading @0xffffffffa00ca000: /home/user/linux/build/net/packet/af_packet.ko loading @0xffffffffa003c000: /home/user/linux/build/fs/fuse/fuse.ko ... loading @0xffffffffa0000000: /home/user/linux/build/drivers/ata/ata_generic.ko”…””}”hjãsbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h KLhjÑubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÎhžhhŸh°h Nubhí)”}”(hŒøSet a breakpoint on some not yet loaded module function, e.g.:: (gdb) b btrfs_init_sysfs Function "btrfs_init_sysfs" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (btrfs_init_sysfs) pending. ”h]”(hÇ)”}”(hŒ?Set a breakpoint on some not yet loaded module function, e.g.::”h]”hŒ>Set a breakpoint on some not yet loaded module function, e.g.:”…””}”(hjûhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h KWhj÷ubjš)”}”(hŒ®(gdb) b btrfs_init_sysfs Function "btrfs_init_sysfs" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (btrfs_init_sysfs) pending.”h]”hŒ®(gdb) b btrfs_init_sysfs Function "btrfs_init_sysfs" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (btrfs_init_sysfs) pending.”…””}”hj sbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h KYhj÷ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÎhžhhŸh°h Nubhí)”}”(hŒ!Continue the target:: (gdb) c ”h]”(hÇ)”}”(hŒContinue the target::”h]”hŒContinue the target:”…””}”(hj!hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K^hjubjš)”}”(hŒ(gdb) c”h]”hŒ(gdb) c”…””}”hj/sbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h K`hjubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÎhžhhŸh°h Nubhí)”}”(hX/Load the module on the target and watch the symbols being loaded as well as the breakpoint hit:: loading @0xffffffffa0034000: /home/user/linux/build/lib/libcrc32c.ko loading @0xffffffffa0050000: /home/user/linux/build/lib/lzo/lzo_compress.ko loading @0xffffffffa006e000: /home/user/linux/build/lib/zlib_deflate/zlib_deflate.ko loading @0xffffffffa01b1000: /home/user/linux/build/fs/btrfs/btrfs.ko Breakpoint 1, btrfs_init_sysfs () at /home/user/linux/fs/btrfs/sysfs.c:36 36 btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); ”h]”(hÇ)”}”(hŒ`Load the module on the target and watch the symbols being loaded as well as the breakpoint hit::”h]”hŒ_Load the module on the target and watch the symbols being loaded as well as the breakpoint hit:”…””}”(hjGhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h KbhjCubjš)”}”(hXÀloading @0xffffffffa0034000: /home/user/linux/build/lib/libcrc32c.ko loading @0xffffffffa0050000: /home/user/linux/build/lib/lzo/lzo_compress.ko loading @0xffffffffa006e000: /home/user/linux/build/lib/zlib_deflate/zlib_deflate.ko loading @0xffffffffa01b1000: /home/user/linux/build/fs/btrfs/btrfs.ko Breakpoint 1, btrfs_init_sysfs () at /home/user/linux/fs/btrfs/sysfs.c:36 36 btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj);”h]”hXÀloading @0xffffffffa0034000: /home/user/linux/build/lib/libcrc32c.ko loading @0xffffffffa0050000: /home/user/linux/build/lib/lzo/lzo_compress.ko loading @0xffffffffa006e000: /home/user/linux/build/lib/zlib_deflate/zlib_deflate.ko loading @0xffffffffa01b1000: /home/user/linux/build/fs/btrfs/btrfs.ko Breakpoint 1, btrfs_init_sysfs () at /home/user/linux/fs/btrfs/sysfs.c:36 36 btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj);”…””}”hjUsbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h KehjCubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÎhžhhŸh°h Nubhí)”}”(hXDump the log buffer of the target kernel:: (gdb) lx-dmesg [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Linux version 3.8.0-rc4-dbg+ (... [ 0.000000] Command line: root=/dev/sda2 resume=/dev/sda1 vga=0x314 [ 0.000000] e820: BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved .... ”h]”(hÇ)”}”(hŒ*Dump the log buffer of the target kernel::”h]”hŒ)Dump the log buffer of the target kernel:”…””}”(hjmhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h Kmhjiubjš)”}”(hXÂ(gdb) lx-dmesg [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Linux version 3.8.0-rc4-dbg+ (... [ 0.000000] Command line: root=/dev/sda2 resume=/dev/sda1 vga=0x314 [ 0.000000] e820: BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved ....”h]”hXÂ(gdb) lx-dmesg [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Linux version 3.8.0-rc4-dbg+ (... [ 0.000000] Command line: root=/dev/sda2 resume=/dev/sda1 vga=0x314 [ 0.000000] e820: BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved ....”…””}”hj{sbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h Kohjiubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÎhžhhŸh°h Nubhí)”}”(hŒÁExamine fields of the current task struct(supported by x86 and arm64 only):: (gdb) p $lx_current().pid $1 = 4998 (gdb) p $lx_current().comm $2 = "modprobe\000\000\000\000\000\000\000" ”h]”(hÇ)”}”(hŒLExamine fields of the current task struct(supported by x86 and arm64 only)::”h]”hŒKExamine fields of the current task struct(supported by x86 and arm64 only):”…””}”(hj“hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h Kyhjubjš)”}”(hŒj(gdb) p $lx_current().pid $1 = 4998 (gdb) p $lx_current().comm $2 = "modprobe\000\000\000\000\000\000\000"”h]”hŒj(gdb) p $lx_current().pid $1 = 4998 (gdb) p $lx_current().comm $2 = "modprobe\000\000\000\000\000\000\000"”…””}”hj¡sbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h K{hjubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÎhžhhŸh°h Nubhí)”}”(hŒ¸Make use of the per-cpu function for the current or a specified CPU:: (gdb) p $lx_per_cpu("runqueues").nr_running $3 = 1 (gdb) p $lx_per_cpu("runqueues", 2).nr_running $4 = 0 ”h]”(hÇ)”}”(hŒEMake use of the per-cpu function for the current or a specified CPU::”h]”hŒDMake use of the per-cpu function for the current or a specified CPU:”…””}”(hj¹hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K€hjµubjš)”}”(hŒh(gdb) p $lx_per_cpu("runqueues").nr_running $3 = 1 (gdb) p $lx_per_cpu("runqueues", 2).nr_running $4 = 0”h]”hŒh(gdb) p $lx_per_cpu("runqueues").nr_running $3 = 1 (gdb) p $lx_per_cpu("runqueues", 2).nr_running $4 = 0”…””}”hjÇsbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h K‚hjµubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÎhžhhŸh°h Nubhí)”}”(hXÑDig into hrtimers using the container_of helper:: (gdb) set $next = $lx_per_cpu("hrtimer_bases").clock_base[0].active.next (gdb) p *$container_of($next, "struct hrtimer", "node") $5 = { node = { node = { __rb_parent_color = 18446612133355256072, rb_right = 0x0 , rb_left = 0x0 }, expires = { tv64 = 1835268000000 } }, _softexpires = { tv64 = 1835268000000 }, function = 0xffffffff81078232 , base = 0xffff88003fd0d6f0, state = 1, start_pid = 0, start_site = 0xffffffff81055c1f , start_comm = "swapper/2\000\000\000\000\000\000" } ”h]”(hÇ)”}”(hŒ1Dig into hrtimers using the container_of helper::”h]”hŒ0Dig into hrtimers using the container_of helper:”…””}”(hjßhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K‡hjÛubjš)”}”(hXn(gdb) set $next = $lx_per_cpu("hrtimer_bases").clock_base[0].active.next (gdb) p *$container_of($next, "struct hrtimer", "node") $5 = { node = { node = { __rb_parent_color = 18446612133355256072, rb_right = 0x0 , rb_left = 0x0 }, expires = { tv64 = 1835268000000 } }, _softexpires = { tv64 = 1835268000000 }, function = 0xffffffff81078232 , base = 0xffff88003fd0d6f0, state = 1, start_pid = 0, start_site = 0xffffffff81055c1f , start_comm = "swapper/2\000\000\000\000\000\000" }”h]”hXn(gdb) set $next = $lx_per_cpu("hrtimer_bases").clock_base[0].active.next (gdb) p *$container_of($next, "struct hrtimer", "node") $5 = { node = { node = { __rb_parent_color = 18446612133355256072, rb_right = 0x0 , rb_left = 0x0 }, expires = { tv64 = 1835268000000 } }, _softexpires = { tv64 = 1835268000000 }, function = 0xffffffff81078232 , base = 0xffff88003fd0d6f0, state = 1, start_pid = 0, start_site = 0xffffffff81055c1f , start_comm = "swapper/2\000\000\000\000\000\000" }”…””}”hjísbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h K‰hjÛubeh}”(h]”h ]”h"]”h$]”h&]”uh1hìhjÎhžhhŸh°h Nubeh}”(h]”h ]”h"]”h$]”h&]”j j uh1hçhŸh°h KJhj½hžhubeh}”(h]”Œ0examples-of-using-the-linux-provided-gdb-helpers”ah ]”h"]”Œ0examples of using the linux-provided gdb helpers”ah$]”h&]”uh1h±hh³hžhhŸh°h KHubh²)”}”(hhh]”(h·)”}”(hŒList of commands and functions”h]”hŒList of commands and functions”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¶hjhžhhŸh°h K£ubhÇ)”}”(hŒ{The number of commands and convenience functions may evolve over the time, this is just a snapshot of the initial version::”h]”hŒzThe number of commands and convenience functions may evolve over the time, this is just a snapshot of the initial version:”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K¥hjhžhubjš)”}”(hXô(gdb) apropos lx function lx_current -- Return current task function lx_module -- Find module by name and return the module variable function lx_per_cpu -- Return per-cpu variable 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 lx-dmesg -- Print Linux kernel log buffer lx-lsmod -- List currently loaded modules lx-symbols -- (Re-)load symbols of Linux kernel and currently loaded modules”h]”hXô(gdb) apropos lx function lx_current -- Return current task function lx_module -- Find module by name and return the module variable function lx_per_cpu -- Return per-cpu variable 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 lx-dmesg -- Print Linux kernel log buffer lx-lsmod -- List currently loaded modules lx-symbols -- (Re-)load symbols of Linux kernel and currently loaded modules”…””}”hj.sbah}”(h]”h ]”h"]”h$]”h&]”j©jªuh1j™hŸh°h K¨hjhžhubhÇ)”}”(hŒƒDetailed help can be obtained via "help " for commands and "help function " for convenience functions.”h]”hŒ‹Detailed help can be obtained via “help †for commands and “help function †for convenience functions.”…””}”(hj<hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÆhŸh°h K²hjhžhubeh}”(h]”Œlist-of-commands-and-functions”ah ]”h"]”Œlist of commands and functions”ah$]”h&]”uh1h±hh³hžhhŸh°h K£ubeh}”(h]”Œ$debugging-kernel-and-modules-via-gdb”ah ]”h"]”Œ$debugging kernel and modules via gdb”ah$]”h&]”uh1h±hhhžhhŸh°h Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”h°uh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(h¶NŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”j}Œerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”h°Œ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jWjTjjjºj·j j jOjLuŒ nametypes”}”(jW‰j‰jº‰j ‰jO‰uh}”(jTh³jhÖj·jj j½jLjuŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nhžhub.