€•”nŒ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ŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ:/translations/pt_BR/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)”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´Khjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhhý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”…””}”(hj-h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÊhj*h²hh³hÄh´Kubhü)”}”(hhh]”(j)”}”(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, ”…””}”(hjBh²hh³Nh´NubhŒ reference”“”)”}”(hŒ"https://landley.net/aboriginal/bin”h]”hŒ"https://landley.net/aboriginal/bin”…””}”(hjLh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jNuh1jJhjBubhŒQ keeps a pool of machine images and toolchains that can be helpful to start from.”…””}”(hjBh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´Khj>ubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj;h²hh³hÄh´Nubj)”}”(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.”…””}”(hjoh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´Khjkubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj;h²hh³hÄh´Nubj)”}”(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.”…””}”(hj‡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K"hjƒubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj;h²hh³hÄh´Nubj)”}”(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&]”uh1jhjÝ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”…””}”(hjh²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]”j)”}”(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”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K4hjubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubah}”(h]”h ]”h"]”h$]”h&]”j j!uh1hûh³hÄh´K4hjubah}”(h]”h ]”h"]”h$]”h&]”uh1j×h³hÄh´K4hjÅubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj;h²hh³hÄh´Nubj)”}”(hŒcd /path/to/linux-build ”h]”hÛ)”}”(hŒcd /path/to/linux-build”h]”hŒcd /path/to/linux-build”…””}”(hjGh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K7hjCubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj;h²hh³hÄh´Nubj)”}”(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”…””}”(hj_h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K9hj[ubhÛ)”}”(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:”…””}”(hjmh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K;hj[ubj®)”}”(hŒ,add-auto-load-safe-path /path/to/linux-build”h]”hŒ,add-auto-load-safe-path /path/to/linux-build”…””}”hj{sbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´K>hj[ubhÛ)”}”(hŒ-to ~/.gdbinit. See gdb help for more details.”h]”hŒ-to ~/.gdbinit. See gdb help for more details.”…””}”(hj‰h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K@hj[ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj;h²hh³hÄh´Nubj)”}”(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:”…””}”(hj¡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´KBhjubj®)”}”(hŒ(gdb) target remote :1234”h]”hŒ(gdb) target remote :1234”…””}”hj¯sbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´KDhjubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj;h²hh³hÄh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j j!uh1hûh³hÄh´Khj*h²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]”(j)”}”(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&]”uh1jhjâh²hh³hÄh´Nubj)”}”(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.:”…””}”(hjh²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.”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´KYhj ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjâh²hh³hÄh´Nubj)”}”(hŒ!Continue the target:: (gdb) c ”h]”(hÛ)”}”(hŒContinue the target::”h]”hŒContinue the target:”…””}”(hj5h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K^hj1ubj®)”}”(hŒ(gdb) c”h]”hŒ(gdb) c”…””}”hjCsbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´K`hj1ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjâh²hh³hÄh´Nubj)”}”(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:”…””}”(hj[h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´KbhjWubj®)”}”(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);”…””}”hjisbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´KehjWubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjâh²hh³hÄh´Nubj)”}”(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:”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´Kmhj}ubj®)”}”(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 ....”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´Kohj}ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjâh²hh³hÄh´Nubj)”}”(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´Kyhj£ubj®)”}”(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{hj£ubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjâh²hh³hÄh´Nubj)”}”(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Œd(gdb) p $lx_per_cpu(runqueues).nr_running $3 = 1 (gdb) p $lx_per_cpu(runqueues, 2).nr_running $4 = 0”h]”hŒd(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&]”uh1jhjâh²hh³hÄh´Nubj)”}”(hXhDig into hrtimers using the container_of helper:: (gdb) set $leftmost = $lx_per_cpu(hrtimer_bases).clock_base[0].active.rb_root.rb_leftmost (gdb) p *$container_of($leftmost, "struct hrtimer", "node") $5 = { node = { node = { __rb_parent_color = 18446612686384860673, rb_right = 0xffff888231da8b00, rb_left = 0x0 }, expires = 1228461000000 }, _softexpires = 1228461000000, function = 0xffffffff8137ab20 , base = 0xffff888231d9b4c0, state = 1 '\001', is_rel = 0 '\000', is_soft = 0 '\000', is_hard = 1 '\001' } ”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®)”}”(hX (gdb) set $leftmost = $lx_per_cpu(hrtimer_bases).clock_base[0].active.rb_root.rb_leftmost (gdb) p *$container_of($leftmost, "struct hrtimer", "node") $5 = { node = { node = { __rb_parent_color = 18446612686384860673, rb_right = 0xffff888231da8b00, rb_left = 0x0 }, expires = 1228461000000 }, _softexpires = 1228461000000, function = 0xffffffff8137ab20 , base = 0xffff888231d9b4c0, state = 1 '\001', is_rel = 0 '\000', is_soft = 0 '\000', is_hard = 1 '\001' }”h]”hX (gdb) set $leftmost = $lx_per_cpu(hrtimer_bases).clock_base[0].active.rb_root.rb_leftmost (gdb) p *$container_of($leftmost, "struct hrtimer", "node") $5 = { node = { node = { __rb_parent_color = 18446612686384860673, rb_right = 0xffff888231da8b00, rb_left = 0x0 }, expires = 1228461000000 }, _softexpires = 1228461000000, function = 0xffffffff8137ab20 , base = 0xffff888231d9b4c0, state = 1 '\001', is_rel = 0 '\000', is_soft = 0 '\000', is_hard = 1 '\001' }”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´K‰hjïubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhjâ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”…””}”(hj&h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÊhj#h²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:”…””}”(hj4h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K¡hj#h²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”…””}”hjBsbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´K¤hj#h²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.”…””}”(hjPh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K®hj#h²hubeh}”(h]”Œlist-of-commands-and-functions”ah ]”h"]”Œlist of commands and functions”ah$]”h&]”uh1hÅhhÇh²hh³hÄh´KŸubhÆ)”}”(hhh]”(hË)”}”(hŒDebugging GDB scripts”h]”hŒDebugging GDB scripts”…””}”(hjih²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÊhjfh²hh³hÄh´K²ubhÛ)”}”(hŒÂGDB does not enable a full Python backtrace which can make debugging GDB scripts more difficult than necessary. The following will allow for printing a full backtrace of the python environment::”h]”hŒÁGDB does not enable a full Python backtrace which can make debugging GDB scripts more difficult than necessary. The following will allow for printing a full backtrace of the python environment:”…””}”(hjwh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÚh³hÄh´K´hjfh²hubj®)”}”(hŒ!(gdb) set python print-stack full”h]”hŒ!(gdb) set python print-stack full”…””}”hj…sbah}”(h]”h ]”h"]”h$]”h&]”j½j¾uh1j­h³hÄh´K¸hjfh²hubeh}”(h]”Œdebugging-gdb-scripts”ah ]”h"]”Œdebugging gdb scripts”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”}”(j jj'j$jÎjËj jjcj`j˜j•uŒ nametypes”}”(j ‰j'‰jΉj ‰jc‰j˜‰uh}”(jhÇj$hêjËj*jjÑj`j#j•jfuŒ 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.