[bootlin/training-materials updates] master: debugging: kgdb: add pitfalls and kernel config option (be9521ce)

Clément Léger clement.leger at bootlin.com
Fri Nov 25 10:20:15 CET 2022

Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/be9521cebe37f91720033a05d6a01677316fae39


commit be9521cebe37f91720033a05d6a01677316fae39
Author: Clément Léger <clement.leger at bootlin.com>
Date:   Fri Nov 25 10:20:15 2022 +0100

    debugging: kgdb: add pitfalls and kernel config option
    Signed-off-by: Clément Léger <clement.leger at bootlin.com>


 common/kgdb.tex | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 7 deletions(-)

diff --git a/common/kgdb.tex b/common/kgdb.tex
index 14faf4e0..f56ac35e 100644
--- a/common/kgdb.tex
+++ b/common/kgdb.tex
@@ -10,22 +10,65 @@
   \item Feature supported for the most popular CPU architectures
   \item \kconfig{CONFIG_GDB_SCRIPTS} allows to build GDB python scripts that are
     provided by the kernel.
-  \item {\em Note: to avoid confusing gdb with randomized kernel addresses, make
-        sure \em{kaslr} is disabled using \code{nokaslr} command line
-        parameter.}
     \item See \kdochtml{dev-tools/gdb-kernel-debugging} for more information
+  \frametitle{kgdb kernel config}
+  \begin{itemize}
+    \item \kconfigval{CONFIG_DEBUG_KERNEL}{y} to make KGDB support visible
+    \item \kconfigval{CONFIG_KGDB}{y} to enabled KGDB support
+    \item \kconfigval{CONFIG_DEBUG_INFO}{y} to enabled KGDB support
+    \item \kconfigval{CONFIG_FRAME_POINTER}{y} to have more reliable
+          stacktraces
+    \item \kconfigval{CONFIG_KGDB_SERIAL_CONSOLE}{y} to enabled KGDB support
+          over serial
+    \item \kconfigval{CONFIG_GDB_SCRIPTS}{y} to enabled kernel GDB python
+          scripts
+    \item \kconfigval{CONFIG_RANDOMIZE_BASE}{n} and
+          \kconfigval{CONFIG_WATCHDOG}{n} to disable KALSR and watchdog
+    \item \kconfigval{CONFIG_MAGIC_SYSRQ} to enable Magic SysReq support
+    \item \kconfigval{CONFIG_STRICT_KERNEL_RWX}{n} to disable memory protection
+          on code section, thus allowing to put breakpoints
+  \end{itemize}
+  \frametitle{kgdb pitfalls}
+  \begin{itemize}
+    \item KASLR should be disabled to avoid confusing gdb with randomized kernel
+          addresses
+    \begin{itemize}
+      \item Disable \em{kaslr} mode using \code{nokaslr} command line parameter
+            if enabled in your kernel.
+    \end{itemize}
+    \item Disable the platform watchdog to avoid rebooting while debugging.
+    \begin{itemize}
+      \item When interrupted by KGDB, all interrupts are disabled thus, the
+            watchdog is not serviced.
+      \item Sometimes, watchdog is enabled by upper boot levels. Make sure to
+            disabled the watchdog there too.
+    \end{itemize}
+    \item Can not interrupt kernel execution from gdb using \code{interrupt}
+          command or \code{Ctrl + C}.
+    \item Not possible to break everywhere (see \kconfig{CONFIG_KGDB_HONOUR_BLOCKLIST}).
+    \item Need a console driver with polling support.
+    \item Some architecture lacks functionalities (No watchpoints on arm32 for
+          instance).
+  \end{itemize}
   \frametitle{Using kgdb (1/2)}
   \item Details available in the kernel documentation:
-  \item Recommended to turn on \kconfig{CONFIG_FRAME_POINTER} to aid in
-    producing more reliable stack backtraces in \code{gdb}.
   \item You must include a kgdb I/O driver. One of them is \code{kgdb} over
     serial console (\code{kgdboc}: \code{kgdb} over console, enabled by
@@ -37,6 +80,8 @@
   \item Or at runtime using sysfs:
    \item \code{echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc}
+   \item If the console does not have polling support, this command will yield
+         an error.
@@ -57,7 +102,5 @@
   \item Once connected, you can debug a kernel the way you would debug
     an application program.
-  \item {\em Note: it might be needed to disable the platform watchdog to avoid
-        rebooting while debugging.}
\ No newline at end of file

More information about the training-materials-updates mailing list