mohitmishra786/low-level-dev-skills

kernel-debugging-advanced

Advanced kernel debugging skill for ftrace, trace-cmd, perf, kprobes, kgdb, and crash analysis.

Quelltext ansehen
Originales Skill-Dokument

Aus dem Quell-Repository gerendert; Überschriften, Beispiele, Code, Tabellen, Links und Bilder bleiben erhalten.

Advanced Kernel Debugging

Purpose

Extend skills/kernel/kernel-debugging with production-grade tracing: ftrace, trace-cmd, kernel perf, kprobes/kretprobes, kgdb, crash dump analysis, and printk discipline. Not merged with kernel-debugging — that skill covers baseline kgdb/dyndbg; this one focuses on trace-cmd, function_graph, and live/post-mortem production workflows.

When to Use

  • Latency spikes in kernel driver without obvious bug
  • Tracing function call graph in kernel
  • Live inspection without recompiling (kprobes, bpf)
  • Post-mortem vmcore after panic

Workflow

1. ftrace function graph

bash
# Enable function graph tracer
echo function_graph > /sys/kernel/debug/tracing/current_tracer
echo my_driver_probe > /sys/kernel/debug/tracing/set_graph_function
echo 1 > /sys/kernel/debug/tracing/tracing_on
# reproduce issue
cat /sys/kernel/debug/tracing/trace
echo 0 > /sys/kernel/debug/tracing/tracing_on

Requires CONFIG_FUNCTION_GRAPH_TRACER and debugfs mounted.

2. trace-cmd record

bash
trace-cmd record -p function_graph -F my_probe
trace-cmd report
trace-cmd stat

Portable capture for sharing with others.

3. perf in kernel context

bash
perf record -a -g -- sleep 10
perf report --stdio
perf probe --add my_driver:probe

See skills/profilers/linux-perf for userspace overlap.

4. kprobes (dynamic)

c
#include <linux/kprobes.h>

static struct kprobe kp = {
    .symbol_name = "do_sys_open",
    .pre_handler = handler,
};
register_kprobe(&kp);

Use sparingly in production; prefer static tracepoints when available.

5. dyndbg and printk discipline

bash
echo 'module mydriver +p' > /sys/kernel/debug/dynamic_debug/control
echo 'file drivers/foo/*.c +p' > /sys/kernel/debug/dynamic_debug/control
c
pr_debug("state=%d\n", s);           /* compile-time optional */
printk_ratelimited(KERN_WARNING "hw fault\n");

6. kgdb / kdb

bash
# kernel cmdline: kgdboc=ttyS0,115200 kgdbwait
echo g > /proc/sysrq-trigger   # break into debugger (when configured)

7. Crash dump (vmcore)

bash
# after kdump capture
crash /usr/lib/debug/vmlinux vmcore
crash> bt
crash> dev -s

8. Agent usage

/kernel-debugging-advanced Trace my_driver_ioctl latency with ftrace function_graph

Common Problems

SymptomCauseFix
Empty traceTracer not enabledtracing_on; check current_tracer
ftrace overheadGraph all functionsFilter with set_graph_function
kprobe failInlined symbolTry nearby symbol or static key
kgdb no connectWrong kgdboc ttyMatch serial/USB gadget
crash no symbolsMissing debuginfoInstall linux-image-dbg / vmlinux

Related Skills

  • skills/kernel/kernel-debugging — baseline kgdb, dyndbg
  • skills/profilers/linux-perf — perf record/report
  • skills/observability/ebpf — BPF kprobe alternative
  • skills/kernel-dev/writing-char-drivers — ioctl trace targets
  • skills/debuggers/core-dumps — userspace core parallels
aus demselben Repository

Weitere Skills

Alle Skills
mohitmishra786
Community

static-analysis

Static analysis skill for C/C++ codebases. Use when hardening code quality, triaging noisy builds, running clang-tidy, cppcheck, or scan-build, interpreting check categories, suppressing false positives, or integrating static analysis into CI. Activates on queries about clang-tidy checks, cppcheck, scan-build, compilecommands.json, code hardening, or static analysis warnings.

Installationen
1
GitHub Stars
263
Aktualisiert
27. Juni
mohitmishra786
Community

assembly-x86

x86-64 assembly skill for reading, writing, and debugging assembly code. Use when reading GCC/Clang assembly output, writing inline asm in C/C++, understanding the System V AMD64 ABI calling convention, or debugging register and stack state. Activates on queries about x86-64 assembly, AT&T vs Intel syntax, inline asm, calling conventions, SIMD intrinsics, or reading disassembly output from objdump or GDB.

Installationen
1
GitHub Stars
258
Aktualisiert
27. Juni
mohitmishra786
Community

cpp-modules

C++20 modules skill for modern C++ projects. Use when working with named modules, module partitions, header units, CMake MODULESOURCES, Clang -fmodules-ts, BMI caching issues, or migrating from headers to modules. Activates on queries about C++20 modules, import statements, module interface units, header units, or BMI files.

Installationen
1
GitHub Stars
258
Aktualisiert
27. Juni
mohitmishra786
Community

gcc

GCC compiler skill for C/C++ projects. Use when selecting optimization levels, warning flags, debug builds, LTO, sanitizer instrumentation, or diagnosing compilation errors with GCC. Covers flag selection for debug vs release, ABI concerns, preprocessor macros, profile-guided optimization, and integration with build systems. Activates on queries about gcc flags, compilation errors, performance tuning, warning suppression, or cross-standard compilation.

Installationen
1
GitHub Stars
258
Aktualisiert
27. Juni