
Recall first from ftrace and kgdb
- ftrace records activity while Linux runs and exposes its controls through tracefs.
- The function tracer records function entries, while function_graph shows nesting and elapsed time for observed calls.
- Tracepoints are predefined instrumentation sites, while kprobes and uprobes add probes to kernel and user-space code respectively.
Decode a kernel oops to source
5 min readWhen the kernel does crash, the oops is the evidence to decode. This lesson answers objdump, addr2line and faddr2line, printk and dynamic debug, and matching each bug class to the right tool.
The kernel's bug-hunting guide describes a problem you can encounter on a board with a failing driver. The report identifies an instruction in compiled kernel code, and you need to find the source expression that produced it. If the board is still responsive, save the kernel message buffer with sudo dmesg > kernel.log. If it stops responding during boot, capture the serial console on the host from power-on. Save the first fault report, including the messages leading up to it. Errors after the first fault can be consequences of damaged kernel state. Kernel bug-hunting guide
A a diagnostic report the kernel emits when it encounters certain serious faults can include the fault description, registers, the instruction location and a call trace. Execution can continue after some oopses, with the affected task terminated in some cases. A a condition in which the kernel stops normal operation may follow an oops, depending on the fault context and settings. A panic can also occur without an oops. The final panic message can tell you why the kernel stopped. Read the preceding messages to see what happened first.
Find the instruction pointer first. On AArch64, look for the pc field. If the report gives both the address of a failed memory access and the instruction pointer, use the instruction pointer for source lookup. The access address describes the memory the instruction tried to use. Then read the caller frames to establish how the code was reached. A caller's reported location may correspond to the return address, so inspect the surrounding source when identifying the call.
Use vmlinux from the exact build that ran, or the matching unstripped .ko for a loadable module named in the report. The ELF needs debug line information, and you need the corresponding source tree to read the surrounding code. A shared release string can occur across rebuilds with different instruction layouts. Keep the debug ELF alongside the deployed build artifacts so you can identify the right one later.
A symbolized location has the form function+offset/size. The offset is a byte displacement from the start of the function. The size is the reported function extent and helps distinguish candidates when symbol names repeat. Copy the complete token, retaining the hexadecimal offset and size as printed. If the trace appends a module name in square brackets, use that name to identify the module ELF and pass the function token separately.
From the kernel source root, set elf to the debug ELF path. The prompts below let you use the actual values from your build and report.
read -r -p 'Debug ELF path: ' elf
read -r -p 'Function+offset/size: ' frame
scripts/faddr2line "$elf" "$frame"
On a cross-build host, set CROSS_COMPILE to the prefix of the target GNU binutils for the script. For example, if the tools are named aarch64-linux-gnu-readelf and aarch64-linux-gnu-addr2line, run CROSS_COMPILE=aarch64-linux-gnu- scripts/faddr2line "$elf" "$frame". Use the prefix for the tools you actually installed.
faddr2line resolves the offset using the ELF's symbol and debug information. A function-relative offset survives moving the function as a whole to a different runtime address, as happens with kernel address space layout randomization. An optimized instruction can be attributed to an inlined helper, with additional source locations describing where that helper was inlined. Read those locations together. If the script fails to resolve the frame, verify the object, build identity and debug information before drawing conclusions from a nearby line.
Use objdump when you need the instruction itself. For built-in code, list the function's disassembly, then add the reported byte offset to the function start shown in that listing. Pass the resulting ELF address to addr2line. Use the target-prefixed versions of these commands when cross-decoding.
objdump -dS --disassemble="${frame%%+*}" "$elf"
read -r -p 'Computed ELF address (include 0x): ' elf_addr
addr2line -e "$elf" -f -i "$elf_addr"
objdump -dS interleaves available source with disassembly. addr2line -f -i reports function names and includes inline locations. For a relocatable module ELF, addresses can be relative to an individual section. If doing a manual lookup, identify the code section and use addr2line -j with that section name and its section-relative address. If all you have is a raw runtime instruction address, establish the relocation for that kernel boot or the runtime base of the relevant module section before doing an ELF lookup.
A decoded line tells you where the fault became visible. If the instruction loads through a pointer, use the disassembly and saved registers to identify the address it accessed. Then follow the caller and the source to see where the pointer came from. The fault location alone cannot tell you when a bad pointer was first stored.
See kernel decisions with dynamic debug
3 min readWhen a driver returns an error and Linux keeps running, existing messages may record the condition that led to the return. printk() writes to the kernel log buffer. Helpers such as pr_err() and pr_info() supply a severity level, and device-scoped helpers such as dev_err() add device context. Console visibility depends on the console log level. A message can be present in the buffer and visible to dmesg even when it never appeared on the serial console. The buffer has finite capacity, so collect messages during the reproduction if the system is busy. Kernel printk documentation
With CONFIG_DYNAMIC_DEBUG enabled, the kernel registers debug call sites such as pr_debug() and dev_dbg() for runtime control. If the kernel was built with CONFIG_DYNAMIC_DEBUG_CORE alone, code must opt in to be registered. Inspect the catalog before choosing a selector. On a system exposing it through procfs, read /proc/dynamic_debug/control. It can also be available through mounted debugfs at /sys/kernel/debug/dynamic_debug/control. A missing entry for your driver can mean that the module has yet to load or that its calls were omitted from the catalog. A selector can only enable registered calls. Dynamic debug HOWTO
Use the path and line number from an entry that is currently disabled. The example assumes the procfs control file is available. Enter the path exactly as shown in the catalog and enter the line number separately.
ctl=/proc/dynamic_debug/control
sudo cat "$ctl" | less
read -r -p 'Catalog source path: ' src
read -r -p 'Catalog line number: ' line
printf 'file %s line %s +p\n' "$src" "$line" | sudo tee "$ctl" > /dev/null
sudo dmesg -w
Here +p enables printing. Reproduce the operation from another terminal if appropriate, then stop the live reader with Ctrl+C. dmesg -w displays existing messages and waits for new ones, so use timestamps to distinguish messages from your reproduction. Read the control entry again to verify that its flags include p. A registered and enabled call site only emits a message when execution reaches it. If a driver remains quiet, check whether the reproduction actually reaches the selected branch. To restore the initially disabled site, use the same selector with -p.
printf 'file %s line %s -p\n' "$src" "$line" | sudo tee "$ctl" > /dev/null
A broad selector can generate enough logging to obscure the messages you need, and additional printing can change the timing of a driver race. Start with one file and line or one function. For built-in code that executes before you can write to the control file, a kernel command line query such as dyndbg="func FUNCTION +p" can enable a known function early. Replace FUNCTION with a registered function name from the build.
Choose the tool by the evidence you need
2 min read| Symptom and question | First tool | Evidence to collect |
|---|---|---|
| The kernel oopsed. Which instruction faulted? | Saved oops, faddr2line, objdump |
Source location, instruction, registers and callers |
| A driver returned an error. Which condition did it report? | dmesg, then dynamic debug |
Existing messages and selected debug messages |
| A program cannot open or configure a device. Which system call failed? | strace |
The call, its arguments, its result and any reported error |
| A program crashes or computes a wrong value. What was in memory? | GDB with gdbserver |
User-space stack, variables and memory on the target |
| The workload uses too much CPU. Where is it spending CPU time? | perf sampling |
Frequently sampled functions for that workload |
| A driver misses a deadline. In what order did events run? | ftrace |
Timestamped events such as interrupts, wakeups and scheduling |
| A reproducible kernel fault requires live state inspection. What is the value before it fails? | kgdb on a configured test target |
Kernel stack, registers and variables at a breakpoint |
A single device symptom can lead to more than one tool. If a program gets an error when it configures a sensor, use strace to establish which operation returned it. If the driver has a debug message in the relevant error path, enable it and repeat the same operation. If the sensor works but samples occasionally arrive late, trace the relevant events and compare their timestamps. A CPU profile can reveal expensive execution in that test. The timestamps answer the ordering question.
If you need to inspect the value at a specific point in kernel code, a kgdb breakpoint can give you that view. Stopping the kernel changes timing, so use event tracing first when the failure depends on scheduling or interrupts. Record the workload and the observation you need before changing the instrumentation. ftrace documentation, KGDB documentation
The next lesson, systemd units and targets, explains how user-space services start and how their dependencies determine what runs during boot. That follows naturally when the kernel reaches user space and the remaining question is why a service did not start.
Key takeaways
- An oops records a kernel fault, and a panic stops normal kernel operation.
- A function-relative offset can be decoded using the matching debug ELF without the runtime relocation address.
- Dynamic debug enables existing debug call sites that the kernel has registered.
- The evidence you need determines whether to decode a crash, inspect state, trace events, or profile execution.
Reflect
- Explain to a colleague, in two sentences: identify the faulting instruction and relevant caller frames in a saved kernel oops.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Kernel documentationBug hunting: locating a kernel fault
- Kernel documentationMessage logging with printk: log levels and console output
- Kernel documentationDynamic debug HOWTO: selecting and enabling call sites
- Kernel documentationftrace: kernel tracing
- Kernel documentationKGDB and KDB: kernel debugging
Official documentation first. Links checked when the lesson was published.