Skip to content

Commit 39762d2

Browse files
committed
gdb: start linux kernel scripts section.
Investigate thread awareness
1 parent 0dfbd93 commit 39762d2

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

README.adoc

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,100 @@ Bibliography:
20202020
* https://stackoverflow.com/questions/10490756/how-to-use-sched-getaffinity-and-sched-setaffinity-in-linux-from-c/50117787#50117787
20212021
* https://stackoverflow.com/questions/42800801/how-to-use-gdb-to-debug-qemu-with-smp-symmetric-multiple-processors
20222022

2023+
=== Linux kernel GDB scripts
2024+
2025+
We source the Linux kernel GDB scripts by default for `lx-symbols`, but they also contains some other goodies worth looking into.
2026+
2027+
Those scripts basically parse some in-kernel datastructures to offer greater visibility with GDB.
2028+
2029+
All defined commands are prefixed by `lx-`, so to get a full list just try to tab complete that.
2030+
2031+
There aren't as many as I'd like, and the ones that do exist are pretty self explanatory, but let's give a few examples.
2032+
2033+
Show dmesg:
2034+
2035+
....
2036+
lx-dmesg
2037+
....
2038+
2039+
Show the <<kernel-command-line-parameters>>:
2040+
2041+
....
2042+
lx-cmdline
2043+
....
2044+
2045+
Dump the device tree to a `fdtdump.dtb` file in the current directory:
2046+
2047+
....
2048+
lx-fdtdump
2049+
pwd
2050+
....
2051+
2052+
List inserted kernel modules:
2053+
2054+
....
2055+
lx-lsmod
2056+
....
2057+
2058+
Sample output:
2059+
2060+
....
2061+
Address Module Size Used by
2062+
0xffffff80006d0000 hello 16384 0
2063+
....
2064+
2065+
Bibliography:
2066+
2067+
* https://events.static.linuxfound.org/sites/events/files/slides/Debugging%20the%20Linux%20Kernel%20with%20GDB.pdf
2068+
* https://wiki.linaro.org/LandingTeams/ST/GDB
2069+
2070+
==== lx-ps
2071+
2072+
List all processes:
2073+
2074+
....
2075+
lx-ps
2076+
....
2077+
2078+
Sample output:
2079+
2080+
....
2081+
0xffff88000ed08000 1 init
2082+
0xffff88000ed08ac0 2 kthreadd
2083+
....
2084+
2085+
The second and third fields are obviously PID and process name.
2086+
2087+
The first one is more interesting, and contains the address of the `task_struct` in memory.
2088+
2089+
This can be confirmed with:
2090+
2091+
....
2092+
p ((struct task_struct)*0xffff88000ed08000
2093+
....
2094+
2095+
which contains the correct PID for all threads I've tried:
2096+
2097+
....
2098+
pid = 1,
2099+
....
2100+
2101+
TODO get the PC of the kthreads: https://stackoverflow.com/questions/26030910/find-program-counter-of-process-in-kernel Then we would be able to see where the threads are stopped in the code!
2102+
2103+
On ARM, I tried:
2104+
2105+
....
2106+
task_pt_regs((struct thread_info *)((struct task_struct)*0xffffffc00e8f8000))->uregs[ARM_pc]
2107+
....
2108+
2109+
but `task_pt_regs` is a `#define` and GDB cannot see defines without `-ggdb3`: https://stackoverflow.com/questions/2934006/how-do-i-print-a-defined-constant-in-gdb which are apparently not set?
2110+
2111+
Bibliography:
2112+
2113+
* https://stackoverflow.com/questions/9561546/thread-aware-gdb-for-kernel
2114+
* https://wiki.linaro.org/LandingTeams/ST/GDB
2115+
* https://events.static.linuxfound.org/sites/events/files/slides/Debugging%20the%20Linux%20Kernel%20with%20GDB.pdf presentation: https://www.youtube.com/watch?v=pqn5hIrz3A8
2116+
20232117
== KGDB
20242118

20252119
TODO: only working with <<graphic-mode>>. Without it, nothing shows on the terminal. So likely something linked to the option `console=ttyS0`.

0 commit comments

Comments
 (0)