<!DOCTYPE html>
<html lang="en" data-content_root="../../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Using kgdb, kdb and the kernel debugger internals — The Linux Kernel documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/alabaster.css?v=3918102e" />
<script src="../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../_static/doctools.js?v=9bcbadda"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Userspace debugging advice" href="userspace_debugging_guide.html" />
<link rel="prev" title="Debugging kernel and modules via gdb" href="gdb-kernel-debugging.html" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
</head><body>
<div class="document">
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../index.html">
<img class="logo" src="../../_static/logo.svg" alt="Logo of The Linux Kernel"/>
</a></p>
<h1 class="logo"><a href="../../index.html">The Linux Kernel</a></h1>
<p class="blurb">6.18.50</p>
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
<p>
<h3 class="kernel-toc-contents">Contents</h3>
<input type="checkbox" class="kernel-toc-toggle" id = "kernel-toc-toggle" checked>
<label class="kernel-toc-title" for="kernel-toc-toggle"></label>
<div class="kerneltoc" id="kerneltoc">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../development-process.html">Development process</a></li>
<li class="toctree-l1"><a class="reference internal" href="../submitting-patches.html">Submitting patches</a></li>
<li class="toctree-l1"><a class="reference internal" href="../code-of-conduct.html">Code of conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../maintainer/index.html">Maintainer handbook</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">All development-process docs</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../index.html#an-introduction-to-how-kernel-development-works">An introduction to how kernel development works</a></li>
<li class="toctree-l2"><a class="reference internal" href="../index.html#tools-and-technical-guides-for-kernel-developers">Tools and technical guides for kernel developers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../index.html#policy-guides-and-developer-statements">Policy guides and developer statements</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../index.html#dealing-with-bugs">Dealing with bugs</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="index.html">Debugging advice for Linux Kernel developers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../handling-regressions.html">Handling regressions</a></li>
<li class="toctree-l3"><a class="reference internal" href="../security-bugs.html">Security bugs</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cve.html">CVEs</a></li>
<li class="toctree-l3"><a class="reference internal" href="../embargoed-hardware-issues.html">Embargoed hardware issues</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../index.html#maintainer-information">Maintainer information</a></li>
<li class="toctree-l2"><a class="reference internal" href="../index.html#other-material">Other material</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../core-api/index.html">Core API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../driver-api/index.html">Driver APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../subsystem-apis.html">Subsystems</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../locking/index.html">Locking</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../license-rules.html">Licensing rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../doc-guide/index.html">Writing documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/index.html">Development tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/testing-overview.html">Testing guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kernel-hacking/index.html">Hacking guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../trace/index.html">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fault-injection/index.html">Fault injection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livepatch/index.html">Livepatching</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rust/index.html">Rust</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/index.html">Administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kbuild/index.html">Build system</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/reporting-issues.html">Reporting issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tools/index.html">Userspace tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../userspace-api/index.html">Userspace API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../firmware-guide/index.html">Firmware</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../devicetree/index.html">Firmware and Devicetree</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../arch/index.html">CPU architectures</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../staging/index.html">Unsorted documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../translations/index.html">Translations</a></li>
</ul>
</div>
<script type="text/javascript"> <!--
var sbar = document.getElementsByClassName("sphinxsidebar")[0];
let currents = document.getElementsByClassName("current")
if (currents.length) {
sbar.scrollTop = currents[currents.length - 1].offsetTop;
}
--> </script>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/process/debugging/kgdb.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
</div>
</div>
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="using-kgdb-kdb-and-the-kernel-debugger-internals">
<h1>Using kgdb, kdb and the kernel debugger internals<a class="headerlink" href="#using-kgdb-kdb-and-the-kernel-debugger-internals" title="Link to this heading">¶</a></h1>
<dl class="field-list simple">
<dt class="field-odd">Author<span class="colon">:</span></dt>
<dd class="field-odd"><p>Jason Wessel</p>
</dd>
</dl>
<section id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h2>
<p>The kernel has two different debugger front ends (kdb and kgdb) which
interface to the debug core. It is possible to use either of the
debugger front ends and dynamically transition between them if you
configure the kernel properly at compile and runtime.</p>
<p>Kdb is simplistic shell-style interface which you can use on a system
console with a keyboard or serial console. You can use it to inspect
memory, registers, process lists, dmesg, and even set breakpoints to
stop in a certain location. Kdb is not a source level debugger, although
you can set breakpoints and execute some basic kernel run control. Kdb
is mainly aimed at doing some analysis to aid in development or
diagnosing kernel problems. You can access some symbols by name in
kernel built-ins or in kernel modules if the code was built with
<code class="docutils literal notranslate"><span class="pre">CONFIG_KALLSYMS</span></code>.</p>
<p>Kgdb is intended to be used as a source level debugger for the Linux
kernel. It is used along with gdb to debug a Linux kernel. The
expectation is that gdb can be used to “break in” to the kernel to
inspect memory, variables and look through call stack information
similar to the way an application developer would use gdb to debug an
application. It is possible to place breakpoints in kernel code and
perform some limited execution stepping.</p>
<p>Two machines are required for using kgdb. One of these machines is a
development machine and the other is the target machine. The kernel to
be debugged runs on the target machine. The development machine runs an
instance of gdb against the vmlinux file which contains the symbols (not
a boot image such as bzImage, zImage, uImage...). In gdb the developer
specifies the connection parameters and connects to kgdb. The type of
connection a developer makes with gdb depends on the availability of
kgdb I/O modules compiled as built-ins or loadable kernel modules in the
test machine’s kernel.</p>
</section>
<section id="compiling-a-kernel">
<h2>Compiling a kernel<a class="headerlink" href="#compiling-a-kernel" title="Link to this heading">¶</a></h2>
<ul class="simple">
<li><p>In order to enable compilation of kdb, you must first enable kgdb.</p></li>
<li><p>The kgdb test compile options are described in the kgdb test suite
chapter.</p></li>
</ul>
<section id="kernel-config-options-for-kgdb">
<h3>Kernel config options for kgdb<a class="headerlink" href="#kernel-config-options-for-kgdb" title="Link to this heading">¶</a></h3>
<p>To enable <code class="docutils literal notranslate"><span class="pre">CONFIG_KGDB</span></code> you should look under
<span class="menuselection">Kernel hacking ‣ Kernel debugging</span> and select
<span class="menuselection">KGDB: kernel debugger</span>.</p>
<p>While it is not a hard requirement that you have symbols in your vmlinux
file, gdb tends not to be very useful without the symbolic data, so you
will want to turn on <code class="docutils literal notranslate"><span class="pre">CONFIG_DEBUG_INFO</span></code> which is called
<span class="menuselection">Compile the kernel with debug info</span> in the config menu.</p>
<p>It is advised, but not required, that you turn on the
<code class="docutils literal notranslate"><span class="pre">CONFIG_FRAME_POINTER</span></code> kernel option which is called <span class="menuselection">Compile
the kernel with frame pointers</span> in the config menu. This option inserts code
into the compiled executable which saves the frame information in registers
or on the stack at different points which allows a debugger such as gdb to
more accurately construct stack back traces while debugging the kernel.</p>
<p>If the architecture that you are using supports the kernel option
<code class="docutils literal notranslate"><span class="pre">CONFIG_STRICT_KERNEL_RWX</span></code>, you should consider turning it off. This
option will prevent the use of software breakpoints because it marks
certain regions of the kernel’s memory space as read-only. If kgdb
supports it for the architecture you are using, you can use hardware
breakpoints if you desire to run with the <code class="docutils literal notranslate"><span class="pre">CONFIG_STRICT_KERNEL_RWX</span></code>
option turned on, else you need to turn off this option.</p>
<p>Next you should choose one or more I/O drivers to interconnect the debugging
host and debugged target. Early boot debugging requires a KGDB I/O
driver that supports early debugging and the driver must be built into
the kernel directly. Kgdb I/O driver configuration takes place via
kernel or module parameters which you can learn more about in the
section that describes the parameter kgdboc.</p>
<p>Here is an example set of <code class="docutils literal notranslate"><span class="pre">.config</span></code> symbols to enable or disable for kgdb:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span># CONFIG_STRICT_KERNEL_RWX is not set
CONFIG_FRAME_POINTER=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
</pre></div>
</div>
</section>
<section id="kernel-config-options-for-kdb">
<h3>Kernel config options for kdb<a class="headerlink" href="#kernel-config-options-for-kdb" title="Link to this heading">¶</a></h3>
<p>Kdb is quite a bit more complex than the simple gdbstub sitting on top
of the kernel’s debug core. Kdb must implement a shell, and also adds
some helper functions in other parts of the kernel, responsible for
printing out interesting data such as what you would see if you ran
<code class="docutils literal notranslate"><span class="pre">lsmod</span></code>, or <code class="docutils literal notranslate"><span class="pre">ps</span></code>. In order to build kdb into the kernel you follow the
same steps as you would for kgdb.</p>
<p>The main config option for kdb is <code class="docutils literal notranslate"><span class="pre">CONFIG_KGDB_KDB</span></code> which is called
<span class="menuselection">KGDB_KDB: include kdb frontend for kgdb</span> in the config menu.
In theory you would have already also selected an I/O driver such as the
<code class="docutils literal notranslate"><span class="pre">CONFIG_KGDB_SERIAL_CONSOLE</span></code> interface if you plan on using kdb on a
serial port, when you were configuring kgdb.</p>
<p>If you want to use a PS/2-style keyboard with kdb, you would select
<code class="docutils literal notranslate"><span class="pre">CONFIG_KDB_KEYBOARD</span></code> which is called <span class="menuselection">KGDB_KDB: keyboard as
input device</span> in the config menu. The <code class="docutils literal notranslate"><span class="pre">CONFIG_KDB_KEYBOARD</span></code> option is not
used for anything in the gdb interface to kgdb. The <code class="docutils literal notranslate"><span class="pre">CONFIG_KDB_KEYBOARD</span></code>
option only works with kdb.</p>
<p>Here is an example set of <code class="docutils literal notranslate"><span class="pre">.config</span></code> symbols to enable/disable kdb:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span># CONFIG_STRICT_KERNEL_RWX is not set
CONFIG_FRAME_POINTER=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
CONFIG_KGDB_KDB=y
CONFIG_KDB_KEYBOARD=y
</pre></div>
</div>
</section>
</section>
<section id="kernel-debugger-boot-arguments">
<h2>Kernel Debugger Boot Arguments<a class="headerlink" href="#kernel-debugger-boot-arguments" title="Link to this heading">¶</a></h2>
<p>This section describes the various runtime kernel parameters that affect
the configuration of the kernel debugger. The following chapter covers
using kdb and kgdb as well as providing some examples of the
configuration parameters.</p>
<section id="kernel-parameter-kgdboc">
<h3>Kernel parameter: kgdboc<a class="headerlink" href="#kernel-parameter-kgdboc" title="Link to this heading">¶</a></h3>
<p>The kgdboc driver was originally an abbreviation meant to stand for
“kgdb over console”. Today it is the primary mechanism to configure how
to communicate from gdb to kgdb as well as the devices you want to use
to interact with the kdb shell.</p>
<p>For kgdb/gdb, kgdboc is designed to work with a single serial port. It
is intended to cover the circumstance where you want to use a serial
console as your primary console as well as using it to perform kernel
debugging. It is also possible to use kgdb on a serial port which is not
designated as a system console. Kgdboc may be configured as a kernel
built-in or a kernel loadable module. You can only make use of
<code class="docutils literal notranslate"><span class="pre">kgdbwait</span></code> and early debugging if you build kgdboc into the kernel as
a built-in.</p>
<p>Optionally you can elect to activate kms (Kernel Mode Setting)
integration. When you use kms with kgdboc and you have a video driver
that has atomic mode setting hooks, it is possible to enter the debugger
on the graphics console. When the kernel execution is resumed, the
previous graphics mode will be restored. This integration can serve as a
useful tool to aid in diagnosing crashes or doing analysis of memory
with kdb while allowing the full graphics console applications to run.</p>
<section id="kgdboc-arguments">
<h4>kgdboc arguments<a class="headerlink" href="#kgdboc-arguments" title="Link to this heading">¶</a></h4>
<p>Usage:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=[kms][[,]kbd][[,]serial_device][,baud]
</pre></div>
</div>
<p>The order listed above must be observed if you use any of the optional
configurations together.</p>
<p>Abbreviations:</p>
<ul class="simple">
<li><p>kms = Kernel Mode Setting</p></li>
<li><p>kbd = Keyboard</p></li>
</ul>
<p>You can configure kgdboc to use the keyboard, and/or a serial device
depending on if you are using kdb and/or kgdb, in one of the following
scenarios. The order listed above must be observed if you use any of the
optional configurations together. Using kms + only gdb is generally not
a useful combination.</p>
<section id="using-loadable-module-or-built-in">
<h5>Using loadable module or built-in<a class="headerlink" href="#using-loadable-module-or-built-in" title="Link to this heading">¶</a></h5>
<ol class="arabic">
<li><p>As a kernel built-in:</p>
<p>Use the kernel boot argument:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=<tty-device>,[baud]
</pre></div>
</div>
</li>
<li><p>As a kernel loadable module:</p>
<p>Use the command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>modprobe kgdboc kgdboc=<tty-device>,[baud]
</pre></div>
</div>
<p>Here are two examples of how you might format the kgdboc string. The
first is for an x86 target using the first serial port. The second
example is for the ARM Versatile AB using the second serial port.</p>
<ol class="arabic simple">
<li><p><code class="docutils literal notranslate"><span class="pre">kgdboc=ttyS0,115200</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">kgdboc=ttyAMA1,115200</span></code></p></li>
</ol>
</li>
</ol>
</section>
<section id="configure-kgdboc-at-runtime-with-sysfs">
<h5>Configure kgdboc at runtime with sysfs<a class="headerlink" href="#configure-kgdboc-at-runtime-with-sysfs" title="Link to this heading">¶</a></h5>
<p>At run time you can enable or disable kgdboc by writing parameters
into sysfs. Here are two examples:</p>
<ol class="arabic">
<li><p>Enable kgdboc on ttyS0:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc
</pre></div>
</div>
</li>
<li><p>Disable kgdboc:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo "" > /sys/module/kgdboc/parameters/kgdboc
</pre></div>
</div>
</li>
</ol>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>You do not need to specify the baud if you are configuring the
console on tty which is already configured or open.</p>
</div>
</section>
<section id="more-examples">
<h5>More examples<a class="headerlink" href="#more-examples" title="Link to this heading">¶</a></h5>
<p>You can configure kgdboc to use the keyboard, and/or a serial device
depending on if you are using kdb and/or kgdb, in one of the following
scenarios.</p>
<ol class="arabic">
<li><p>kdb and kgdb over only a serial port:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=<serial_device>[,baud]
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=ttyS0,115200
</pre></div>
</div>
</li>
<li><p>kdb and kgdb with keyboard and a serial port:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=kbd,<serial_device>[,baud]
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=kbd,ttyS0,115200
</pre></div>
</div>
</li>
<li><p>kdb with a keyboard:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=kbd
</pre></div>
</div>
</li>
<li><p>kdb with kernel mode setting:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=kms,kbd
</pre></div>
</div>
</li>
<li><p>kdb with kernel mode setting and kgdb over a serial port:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=kms,kbd,ttyS0,115200
</pre></div>
</div>
</li>
</ol>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Kgdboc does not support interrupting the target via the gdb remote
protocol. You must manually send a <cite>SysRq-G</cite> unless you have a proxy
that splits console output to a terminal program. A console proxy has a
separate TCP port for the debugger and a separate TCP port for the
“human” console. The proxy can take care of sending the <cite>SysRq-G</cite>
for you.</p>
</div>
<p>When using kgdboc with no debugger proxy, you can end up connecting the
debugger at one of two entry points. If an exception occurs after you
have loaded kgdboc, a message should print on the console stating it is
waiting for the debugger. In this case you disconnect your terminal
program and then connect the debugger in its place. If you want to
interrupt the target system and forcibly enter a debug session you have
to issue a <cite>Sysrq</cite> sequence and then type the letter <cite>g</cite>. Then you
disconnect the terminal session and connect gdb. Your options if you
don’t like this are to hack gdb to send the <cite>SysRq-G</cite> for you as well as
on the initial connect, or to use a debugger proxy that allows an
unmodified gdb to do the debugging.</p>
</section>
</section>
</section>
<section id="kernel-parameter-kgdboc-earlycon">
<h3>Kernel parameter: <code class="docutils literal notranslate"><span class="pre">kgdboc_earlycon</span></code><a class="headerlink" href="#kernel-parameter-kgdboc-earlycon" title="Link to this heading">¶</a></h3>
<p>If you specify the kernel parameter <code class="docutils literal notranslate"><span class="pre">kgdboc_earlycon</span></code> and your serial
driver registers a boot console that supports polling (doesn’t need
interrupts and implements a nonblocking read() function) kgdb will attempt
to work using the boot console until it can transition to the regular
tty driver specified by the <code class="docutils literal notranslate"><span class="pre">kgdboc</span></code> parameter.</p>
<p>Normally there is only one boot console (especially that implements the
read() function) so just adding <code class="docutils literal notranslate"><span class="pre">kgdboc_earlycon</span></code> on its own is
sufficient to make this work. If you have more than one boot console you
can add the boot console’s name to differentiate. Note that names that
are registered through the boot console layer and the tty layer are not
the same for the same port.</p>
<p>For instance, on one board to be explicit you might do:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc_earlycon=qcom_geni kgdboc=ttyMSM0
</pre></div>
</div>
<p>If the only boot console on the device was “qcom_geni”, you could simplify:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc_earlycon kgdboc=ttyMSM0
</pre></div>
</div>
</section>
<section id="kernel-parameter-kgdbwait">
<h3>Kernel parameter: <code class="docutils literal notranslate"><span class="pre">kgdbwait</span></code><a class="headerlink" href="#kernel-parameter-kgdbwait" title="Link to this heading">¶</a></h3>
<p>The Kernel command line option <code class="docutils literal notranslate"><span class="pre">kgdbwait</span></code> makes kgdb wait for a
debugger connection during booting of a kernel. You can only use this
option if you compiled a kgdb I/O driver into the kernel and you
specified the I/O driver configuration as a kernel command line option.
The kgdbwait parameter should always follow the configuration parameter
for the kgdb I/O driver in the kernel command line else the I/O driver
will not be configured prior to asking the kernel to use it to wait.</p>
<p>The kernel will stop and wait as early as the I/O driver and
architecture allows when you use this option. If you build the kgdb I/O
driver as a loadable kernel module kgdbwait will not do anything.</p>
</section>
<section id="kernel-parameter-kgdbcon">
<h3>Kernel parameter: <code class="docutils literal notranslate"><span class="pre">kgdbcon</span></code><a class="headerlink" href="#kernel-parameter-kgdbcon" title="Link to this heading">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">kgdbcon</span></code> feature allows you to see <a class="reference internal" href="../../core-api/printk-basics.html#c.printk" title="printk"><code class="xref c c-func docutils literal notranslate"><span class="pre">printk()</span></code></a> messages inside gdb
while gdb is connected to the kernel. Kdb does not make use of the kgdbcon
feature.</p>
<p>Kgdb supports using the gdb serial protocol to send console messages to
the debugger when the debugger is connected and running. There are two
ways to activate this feature.</p>
<ol class="arabic">
<li><p>Activate with the kernel command line option:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdbcon
</pre></div>
</div>
</li>
<li><p>Use sysfs before configuring an I/O driver:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo 1 > /sys/module/debug_core/parameters/kgdb_use_con
</pre></div>
</div>
</li>
</ol>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If you do this after you configure the kgdb I/O driver, the
setting will not take effect until the next point the I/O is
reconfigured.</p>
</div>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>You cannot use kgdboc + kgdbcon on a tty that is an
active system console. An example of incorrect usage is:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>console=ttyS0,115200 kgdboc=ttyS0 kgdbcon
</pre></div>
</div>
</div>
<p>It is possible to use this option with kgdboc on a tty that is not a
system console.</p>
</section>
<section id="run-time-parameter-kgdbreboot">
<h3>Run time parameter: <code class="docutils literal notranslate"><span class="pre">kgdbreboot</span></code><a class="headerlink" href="#run-time-parameter-kgdbreboot" title="Link to this heading">¶</a></h3>
<p>The kgdbreboot feature allows you to change how the debugger deals with
the reboot notification. You have 3 choices for the behavior. The
default behavior is always set to 0.</p>
<table class="docutils align-default">
<tbody>
<tr class="row-odd"><td><p>1</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">echo</span> <span class="pre">-1</span> <span class="pre">></span> <span class="pre">/sys/module/debug_core/parameters/kgdbreboot</span></code></p></td>
<td><p>Ignore the reboot notification entirely.</p></td>
</tr>
<tr class="row-even"><td><p>2</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">echo</span> <span class="pre">0</span> <span class="pre">></span> <span class="pre">/sys/module/debug_core/parameters/kgdbreboot</span></code></p></td>
<td><p>Send the detach message to any attached debugger client.</p></td>
</tr>
<tr class="row-odd"><td><p>3</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">echo</span> <span class="pre">1</span> <span class="pre">></span> <span class="pre">/sys/module/debug_core/parameters/kgdbreboot</span></code></p></td>
<td><p>Enter the debugger on reboot notify.</p></td>
</tr>
</tbody>
</table>
</section>
<section id="kernel-parameter-nokaslr">
<h3>Kernel parameter: <code class="docutils literal notranslate"><span class="pre">nokaslr</span></code><a class="headerlink" href="#kernel-parameter-nokaslr" title="Link to this heading">¶</a></h3>
<p>If the architecture that you are using enables KASLR by default,
you should consider turning it off. KASLR randomizes the
virtual address where the kernel image is mapped and confuses
gdb which resolves addresses of kernel symbols from the symbol table
of vmlinux.</p>
</section>
</section>
<section id="using-kdb">
<h2>Using kdb<a class="headerlink" href="#using-kdb" title="Link to this heading">¶</a></h2>
<section id="quick-start-for-kdb-on-a-serial-port">
<h3>Quick start for kdb on a serial port<a class="headerlink" href="#quick-start-for-kdb-on-a-serial-port" title="Link to this heading">¶</a></h3>
<p>This is a quick example of how to use kdb.</p>
<ol class="arabic">
<li><p>Configure kgdboc at boot using kernel parameters:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>console=ttyS0,115200 kgdboc=ttyS0,115200 nokaslr
</pre></div>
</div>
<p>OR</p>
<p>Configure kgdboc after the kernel has booted; assuming you are using
a serial port console:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc
</pre></div>
</div>
</li>
<li><p>Enter the kernel debugger manually or by waiting for an oops or
fault. There are several ways you can enter the kernel debugger
manually; all involve using the <cite>SysRq-G</cite>, which means you must have
enabled <code class="docutils literal notranslate"><span class="pre">CONFIG_MAGIC_SYSRQ=y</span></code> in your kernel config.</p>
<ul>
<li><p>When logged in as root or with a super user session you can run:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo g > /proc/sysrq-trigger
</pre></div>
</div>
</li>
<li><p>Example using minicom 2.2</p>
<p>Press: <cite>CTRL-A</cite> <cite>f</cite> <cite>g</cite></p>
</li>
<li><p>When you have telneted to a terminal server that supports sending
a remote break</p>
<p>Press: <cite>CTRL-]</cite></p>
<p>Type in: <code class="docutils literal notranslate"><span class="pre">send</span> <span class="pre">break</span></code></p>
<p>Press: <cite>Enter</cite> <cite>g</cite></p>
</li>
</ul>
</li>
<li><p>From the kdb prompt you can run the <code class="docutils literal notranslate"><span class="pre">help</span></code> command to see a complete
list of the commands that are available.</p>
<p>Some useful commands in kdb include:</p>
<table class="docutils align-default">
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">lsmod</span></code></p></td>
<td><p>Shows where kernel modules are loaded</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">ps</span></code></p></td>
<td><p>Displays only the active processes</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ps</span> <span class="pre">A</span></code></p></td>
<td><p>Shows all the processes</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">summary</span></code></p></td>
<td><p>Shows kernel version info and memory usage</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">bt</span></code></p></td>
<td><p>Get a backtrace of the current process using <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">dump_stack()</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">dmesg</span></code></p></td>
<td><p>View the kernel syslog buffer</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">go</span></code></p></td>
<td><p>Continue the system</p></td>
</tr>
</tbody>
</table>
</li>
<li><p>When you are done using kdb you need to consider rebooting the system
or using the <code class="docutils literal notranslate"><span class="pre">go</span></code> command to resuming normal kernel execution. If you
have paused the kernel for a lengthy period of time, applications
that rely on timely networking or anything to do with real wall clock
time could be adversely affected, so you should take this into
consideration when using the kernel debugger.</p></li>
</ol>
</section>
<section id="quick-start-for-kdb-using-a-keyboard-connected-console">
<h3>Quick start for kdb using a keyboard connected console<a class="headerlink" href="#quick-start-for-kdb-using-a-keyboard-connected-console" title="Link to this heading">¶</a></h3>
<p>This is a quick example of how to use kdb with a keyboard.</p>
<ol class="arabic">
<li><p>Configure kgdboc at boot using kernel parameters:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=kbd
</pre></div>
</div>
<p>OR</p>
<p>Configure kgdboc after the kernel has booted:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo kbd > /sys/module/kgdboc/parameters/kgdboc
</pre></div>
</div>
</li>
<li><p>Enter the kernel debugger manually or by waiting for an oops or
fault. There are several ways you can enter the kernel debugger
manually; all involve using the <cite>SysRq-G</cite>, which means you must have
enabled <code class="docutils literal notranslate"><span class="pre">CONFIG_MAGIC_SYSRQ=y</span></code> in your kernel config.</p>
<ul>
<li><p>When logged in as root or with a super user session you can run:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo g > /proc/sysrq-trigger
</pre></div>
</div>
</li>
<li><p>Example using a laptop keyboard:</p>
<p>Press and hold down: <cite>Alt</cite></p>
<p>Press and hold down: <cite>Fn</cite></p>
<p>Press and release the key with the label: <cite>SysRq</cite></p>
<p>Release: <cite>Fn</cite></p>
<p>Press and release: <cite>g</cite></p>
<p>Release: <cite>Alt</cite></p>
</li>
<li><p>Example using a PS/2 101-key keyboard</p>
<p>Press and hold down: <cite>Alt</cite></p>
<p>Press and release the key with the label: <cite>SysRq</cite></p>
<p>Press and release: <cite>g</cite></p>
<p>Release: <cite>Alt</cite></p>
</li>
</ul>
</li>
<li><p>Now type in a kdb command such as <code class="docutils literal notranslate"><span class="pre">help</span></code>, <code class="docutils literal notranslate"><span class="pre">dmesg</span></code>, <code class="docutils literal notranslate"><span class="pre">bt</span></code> or <code class="docutils literal notranslate"><span class="pre">go</span></code> to
continue kernel execution.</p></li>
</ol>
</section>
</section>
<section id="using-kgdb-gdb">
<h2>Using kgdb / gdb<a class="headerlink" href="#using-kgdb-gdb" title="Link to this heading">¶</a></h2>
<p>In order to use kgdb you must activate it by passing configuration
information to one of the kgdb I/O drivers. If you do not pass any
configuration information kgdb will not do anything at all. Kgdb will
only actively hook up to the kernel trap hooks if a kgdb I/O driver is
loaded and configured. If you unconfigure a kgdb I/O driver, kgdb will
unregister all the kernel hook points.</p>
<p>All kgdb I/O drivers can be reconfigured at run time, if
<code class="docutils literal notranslate"><span class="pre">CONFIG_SYSFS</span></code> and <code class="docutils literal notranslate"><span class="pre">CONFIG_MODULES</span></code> are enabled, by echo’ing a new
config string to <code class="docutils literal notranslate"><span class="pre">/sys/module/<driver>/parameter/<option></span></code>. The driver
can be unconfigured by passing an empty string. You cannot change the
configuration while the debugger is attached. Make sure to detach the
debugger with the <code class="docutils literal notranslate"><span class="pre">detach</span></code> command prior to trying to unconfigure a
kgdb I/O driver.</p>
<section id="connecting-with-gdb-to-a-serial-port">
<h3>Connecting with gdb to a serial port<a class="headerlink" href="#connecting-with-gdb-to-a-serial-port" title="Link to this heading">¶</a></h3>
<ol class="arabic">
<li><p>Configure kgdboc</p>
<p>Configure kgdboc at boot using kernel parameters:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdboc=ttyS0,115200
</pre></div>
</div>
<p>OR</p>
<p>Configure kgdboc after the kernel has booted:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc
</pre></div>
</div>
</li>
<li><p>Stop kernel execution (break into the debugger)</p>
<p>In order to connect to gdb via kgdboc, the kernel must first be
stopped. There are several ways to stop the kernel which include
using kgdbwait as a boot argument, via a <cite>SysRq-G</cite>, or running the
kernel until it takes an exception where it waits for the debugger to
attach.</p>
<ul>
<li><p>When logged in as root or with a super user session you can run:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>echo g > /proc/sysrq-trigger
</pre></div>
</div>
</li>
<li><p>Example using minicom 2.2</p>
<p>Press: <cite>CTRL-A</cite> <cite>f</cite> <cite>g</cite></p>
</li>
<li><p>When you have telneted to a terminal server that supports sending
a remote break</p>
<p>Press: <cite>CTRL-]</cite></p>
<p>Type in: <code class="docutils literal notranslate"><span class="pre">send</span> <span class="pre">break</span></code></p>
<p>Press: <cite>Enter</cite> <cite>g</cite></p>
</li>
</ul>
</li>
<li><p>Connect from gdb</p>
<p>Example (using a directly connected port):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% gdb ./vmlinux
(gdb) set serial baud 115200
(gdb) target remote /dev/ttyS0
</pre></div>
</div>
<p>Example (kgdb to a terminal server on TCP port 2012):</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>% gdb ./vmlinux
(gdb) target remote 192.168.2.2:2012
</pre></div>
</div>
<p>Once connected, you can debug a kernel the way you would debug an
application program.</p>
<p>If you are having problems connecting or something is going seriously
wrong while debugging, it will most often be the case that you want
to enable gdb to be verbose about its target communications. You do
this prior to issuing the <code class="docutils literal notranslate"><span class="pre">target</span> <span class="pre">remote</span></code> command by typing in:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>set debug remote 1
</pre></div>
</div>
</li>
</ol>
<p>Remember if you continue in gdb, and need to “break in” again, you need
to issue an other <cite>SysRq-G</cite>. It is easy to create a simple entry point by
putting a breakpoint at <code class="docutils literal notranslate"><span class="pre">sys_sync</span></code> and then you can run <code class="docutils literal notranslate"><span class="pre">sync</span></code> from a
shell or script to break into the debugger.</p>
</section>
</section>
<section id="kgdb-and-kdb-interoperability">
<h2>kgdb and kdb interoperability<a class="headerlink" href="#kgdb-and-kdb-interoperability" title="Link to this heading">¶</a></h2>
<p>It is possible to transition between kdb and kgdb dynamically. The debug
core will remember which you used the last time and automatically start
in the same mode.</p>
<section id="switching-between-kdb-and-kgdb">
<h3>Switching between kdb and kgdb<a class="headerlink" href="#switching-between-kdb-and-kgdb" title="Link to this heading">¶</a></h3>
<section id="switching-from-kgdb-to-kdb">
<h4>Switching from kgdb to kdb<a class="headerlink" href="#switching-from-kgdb-to-kdb" title="Link to this heading">¶</a></h4>
<p>There are two ways to switch from kgdb to kdb: you can use gdb to issue
a maintenance packet, or you can blindly type the command <code class="docutils literal notranslate"><span class="pre">$3#33</span></code>.
Whenever the kernel debugger stops in kgdb mode it will print the
message <code class="docutils literal notranslate"><span class="pre">KGDB</span> <span class="pre">or</span> <span class="pre">$3#33</span> <span class="pre">for</span> <span class="pre">KDB</span></code>. It is important to note that you have
to type the sequence correctly in one pass. You cannot type a backspace
or delete because kgdb will interpret that as part of the debug stream.</p>
<ol class="arabic">
<li><p>Change from kgdb to kdb by blindly typing:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>$3#33
</pre></div>
</div>
</li>
<li><p>Change from kgdb to kdb with gdb:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>maintenance packet 3
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Now you must kill gdb. Typically you press <cite>CTRL-Z</cite> and issue
the command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kill -9 %
</pre></div>
</div>
</div>
</li>
</ol>
</section>
<section id="change-from-kdb-to-kgdb">
<h4>Change from kdb to kgdb<a class="headerlink" href="#change-from-kdb-to-kgdb" title="Link to this heading">¶</a></h4>
<p>There are two ways you can change from kdb to kgdb. You can manually
enter kgdb mode by issuing the kgdb command from the kdb shell prompt,
or you can connect gdb while the kdb shell prompt is active. The kdb
shell looks for the typical first commands that gdb would issue with the
gdb remote protocol and if it sees one of those commands it
automatically changes into kgdb mode.</p>
<ol class="arabic">
<li><p>From kdb issue the command:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>kgdb
</pre></div>
</div>
</li>
<li><p>At the kdb prompt, disconnect the terminal program and connect gdb in
its place.</p></li>
</ol>
</section>
</section>
<section id="running-kdb-commands-from-gdb">
<h3>Running kdb commands from gdb<a class="headerlink" href="#running-kdb-commands-from-gdb" title="Link to this heading">¶</a></h3>
<p>It is possible to run a limited set of kdb commands from gdb, using the
gdb monitor command. You don’t want to execute any of the run control or
breakpoint operations, because it can disrupt the state of the kernel
debugger. You should be using gdb for breakpoints and run control
operations if you have gdb connected. The more useful commands to run
are things like lsmod, dmesg, ps or possibly some of the memory
information commands. To see all the kdb commands you can run
<code class="docutils literal notranslate"><span class="pre">monitor</span> <span class="pre">help</span></code>.</p>
<p>Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>(gdb) monitor ps
1 idle process (state I) and
27 sleeping system daemon (state M) processes suppressed,
use 'ps A' to see all.
Task Addr Pid Parent [*] cpu State Thread Command
0xc78291d0 1 0 0 0 S 0xc7829404 init
0xc7954150 942 1 0 0 S 0xc7954384 dropbear
0xc78789c0 944 1 0 0 S 0xc7878bf4 sh
(gdb)
</pre></div>
</div>
</section>
</section>
<section id="kgdb-test-suite">
<h2>kgdb Test Suite<a class="headerlink" href="#kgdb-test-suite" title="Link to this heading">¶</a></h2>
<p>When kgdb is enabled in the kernel config you can also elect to enable
the config parameter <code class="docutils literal notranslate"><span class="pre">KGDB_TESTS</span></code>. Turning this on will enable a special
kgdb I/O module which is designed to test the kgdb internal functions.</p>
<p>The kgdb tests are mainly intended for developers to test the kgdb
internals as well as a tool for developing a new kgdb architecture
specific implementation. These tests are not really for end users of the
Linux kernel. The primary source of documentation would be to look in
the <code class="docutils literal notranslate"><span class="pre">drivers/misc/kgdbts.c</span></code> file.</p>
<p>The kgdb test suite can also be configured at compile time to run the
core set of tests by setting the kernel config parameter
<code class="docutils literal notranslate"><span class="pre">KGDB_TESTS_ON_BOOT</span></code>. This particular option is aimed at automated
regression testing and does not require modifying the kernel boot config
arguments. If this is turned on, the kgdb test suite can be disabled by
specifying <code class="docutils literal notranslate"><span class="pre">kgdbts=</span></code> as a kernel boot argument.</p>
</section>
<section id="kernel-debugger-internals">
<h2>Kernel Debugger Internals<a class="headerlink" href="#kernel-debugger-internals" title="Link to this heading">¶</a></h2>
<section id="architecture-specifics">
<h3>Architecture Specifics<a class="headerlink" href="#architecture-specifics" title="Link to this heading">¶</a></h3>
<p>The kernel debugger is organized into a number of components:</p>
<ol class="arabic">
<li><p>The debug core</p>
<p>The debug core is found in <code class="docutils literal notranslate"><span class="pre">kernel/debugger/debug_core.c</span></code>. It
contains:</p>
<ul>
<li><p>A generic OS exception handler which includes sync’ing the
processors into a stopped state on an multi-CPU system.</p></li>
<li><p>The API to talk to the kgdb I/O drivers</p></li>
<li><p>The API to make calls to the arch-specific kgdb implementation</p></li>
<li><p>The logic to perform safe memory reads and writes to memory while
using the debugger</p></li>
<li><p>A full implementation for software breakpoints unless overridden
by the arch</p></li>
<li><p>The API to invoke either the kdb or kgdb frontend to the debug
core.</p></li>
<li><p>The structures and callback API for atomic kernel mode setting.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>kgdboc is where the kms callbacks are invoked.</p>
</div>
</li>
</ul>
</li>
<li><p>kgdb arch-specific implementation</p>
<p>This implementation is generally found in <code class="docutils literal notranslate"><span class="pre">arch/*/kernel/kgdb.c</span></code>. As
an example, <code class="docutils literal notranslate"><span class="pre">arch/x86/kernel/kgdb.c</span></code> contains the specifics to
implement HW breakpoint as well as the initialization to dynamically
register and unregister for the trap handlers on this architecture.
The arch-specific portion implements:</p>
<ul class="simple">
<li><p>contains an arch-specific trap catcher which invokes
<code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">kgdb_handle_exception()</span></code> to start kgdb about doing its work</p></li>
<li><p>translation to and from gdb specific packet format to <code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span></code></p></li>
<li><p>Registration and unregistration of architecture specific trap
hooks</p></li>
<li><p>Any special exception handling and cleanup</p></li>
<li><p>NMI exception handling and cleanup</p></li>
<li><p>(optional) HW breakpoints</p></li>
</ul>
</li>
<li><p>gdbstub frontend (aka kgdb)</p>
<p>The gdbstub is located in <code class="docutils literal notranslate"><span class="pre">kernel/debug/gdbstub.c</span></code>. It contains:</p>
<ul class="simple">
<li><p>All the logic to implement the gdb serial protocol</p></li>
</ul>
</li>
<li><p>kdb frontend</p>
<p>The kdb debugger shell is broken down into a number of components.
The kdb core is located in kernel/debug/kdb. There are a number of
helper functions in some of the other kernel components to make it
possible for kdb to examine and report information about the kernel
without taking locks that could cause a kernel deadlock. The kdb core
implements the following functionality.</p>
<ul class="simple">
<li><p>A simple shell</p></li>
<li><p>The kdb core command set</p></li>
<li><p>A registration API to register additional kdb shell commands.</p>
<ul>
<li><p>A good example of a self-contained kdb module is the <code class="docutils literal notranslate"><span class="pre">ftdump</span></code>
command for dumping the ftrace buffer. See:
<code class="docutils literal notranslate"><span class="pre">kernel/trace/trace_kdb.c</span></code></p></li>
<li><p>For an example of how to dynamically register a new kdb command
you can build the kdb_hello.ko kernel module from
<code class="docutils literal notranslate"><span class="pre">samples/kdb/kdb_hello.c</span></code>. To build this example you can set
<code class="docutils literal notranslate"><span class="pre">CONFIG_SAMPLES=y</span></code> and <code class="docutils literal notranslate"><span class="pre">CONFIG_SAMPLE_KDB=m</span></code> in your kernel
config. Later run <code class="docutils literal notranslate"><span class="pre">modprobe</span> <span class="pre">kdb_hello</span></code> and the next time you
enter the kdb shell, you can run the <code class="docutils literal notranslate"><span class="pre">hello</span></code> command.</p></li>
</ul>
</li>
<li><p>The implementation for <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">kdb_printf()</span></code> which emits messages directly
to I/O drivers, bypassing the kernel log.</p></li>
<li><p>SW / HW breakpoint management for the kdb shell</p></li>
</ul>
</li>
<li><p>kgdb I/O driver</p>
<p>Each kgdb I/O driver has to provide an implementation for the
following:</p>
<ul class="simple">
<li><p>configuration via built-in or module</p></li>
<li><p>dynamic configuration and kgdb hook registration calls</p></li>
<li><p>read and write character interface</p></li>
<li><p>A cleanup handler for unconfiguring from the kgdb core</p></li>
<li><p>(optional) Early debug methodology</p></li>
</ul>
<p>Any given kgdb I/O driver has to operate very closely with the
hardware and must do it in such a way that does not enable interrupts
or change other parts of the system context without completely
restoring them. The kgdb core will repeatedly “poll” a kgdb I/O
driver for characters when it needs input. The I/O driver is expected
to return immediately if there is no data available. Doing so allows
for the future possibility to touch watchdog hardware in such a way
as to have a target system not reset when these are enabled.</p>
</li>
</ol>
<p>If you are intent on adding kgdb architecture specific support for a new
architecture, the architecture should define <code class="docutils literal notranslate"><span class="pre">HAVE_ARCH_KGDB</span></code> in the
architecture specific Kconfig file. This will enable kgdb for the
architecture, and at that point you must create an architecture specific
kgdb implementation.</p>
<p>There are a few flags which must be set on every architecture in their
<code class="docutils literal notranslate"><span class="pre">asm/kgdb.h</span></code> file. These are:</p>
<ul class="simple">
<li><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">NUMREGBYTES</span></code>:</dt><dd><p>The size in bytes of all of the registers, so that we
can ensure they will all fit into a packet.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">BUFMAX</span></code>:</dt><dd><p>The size in bytes of the buffer GDB will read into. This must
be larger than NUMREGBYTES.</p>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">CACHE_FLUSH_IS_SAFE</span></code>:</dt><dd><p>Set to 1 if it is always safe to call
flush_cache_range or flush_icache_range. On some architectures,
these functions may not be safe to call on SMP since we keep other
CPUs in a holding pattern.</p>
</dd>
</dl>
</li>
</ul>
<p>There are also the following functions for the common backend, found in
<code class="docutils literal notranslate"><span class="pre">kernel/kgdb.c</span></code>, that must be supplied by the architecture-specific
backend unless marked as (optional), in which case a default function
maybe used if the architecture does not need to provide a specific
implementation.</p>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_skipexception">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_skipexception</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">exception</span></span>, <span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">pt_regs</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">regs</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_skipexception" title="Link to this definition">¶</a><br /></dt>
<dd><p>(optional) exit kgdb_handle_exception early</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">exception</span></code></dt><dd><p>Exception vector number</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span> <span class="pre">*regs</span></code></dt><dd><p>Current <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span></code>.</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>On some architectures it is required to skip a breakpoint
exception when it occurs after a breakpoint has been removed.
This can be implemented in the architecture specific portion of kgdb.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_breakpoint">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_breakpoint</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_breakpoint" title="Link to this definition">¶</a><br /></dt>
<dd><p>compiled in breakpoint</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">void</span></code></dt><dd><p>no arguments</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>This will be implemented as a static inline per architecture. This
function is called by the kgdb core to execute an architecture
specific trap to cause kgdb to enter the exception processing.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_arch_init">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_arch_init</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_arch_init" title="Link to this definition">¶</a><br /></dt>
<dd><p>Perform any architecture specific initialization.</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">void</span></code></dt><dd><p>no arguments</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>This function will handle the initialization of any architecture
specific callbacks.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_arch_exit">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_arch_exit</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_arch_exit" title="Link to this definition">¶</a><br /></dt>
<dd><p>Perform any architecture specific uninitalization.</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">void</span></code></dt><dd><p>no arguments</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>This function will handle the uninitalization of any architecture
specific callbacks, for dynamic registration and unregistration.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.pt_regs_to_gdb_regs">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">pt_regs_to_gdb_regs</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">unsigned</span></span><span class="w"> </span><span class="kt"><span class="pre">long</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">gdb_regs</span></span>, <span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">pt_regs</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">regs</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.pt_regs_to_gdb_regs" title="Link to this definition">¶</a><br /></dt>
<dd><p>Convert ptrace regs to GDB regs</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">unsigned</span> <span class="pre">long</span> <span class="pre">*gdb_regs</span></code></dt><dd><p>A pointer to hold the registers in the order GDB wants.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span> <span class="pre">*regs</span></code></dt><dd><p>The <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span></code> of the current process.</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>Convert the pt_regs in <strong>regs</strong> into the format for registers that
GDB expects, stored in <strong>gdb_regs</strong>.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.sleeping_thread_to_gdb_regs">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">sleeping_thread_to_gdb_regs</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">unsigned</span></span><span class="w"> </span><span class="kt"><span class="pre">long</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">gdb_regs</span></span>, <span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">task_struct</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">p</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.sleeping_thread_to_gdb_regs" title="Link to this definition">¶</a><br /></dt>
<dd><p>Convert ptrace regs to GDB regs</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">unsigned</span> <span class="pre">long</span> <span class="pre">*gdb_regs</span></code></dt><dd><p>A pointer to hold the registers in the order GDB wants.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">task_struct</span> <span class="pre">*p</span></code></dt><dd><p>The <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">task_struct</span></code> of the desired process.</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>Convert the register values of the sleeping process in <strong>p</strong> to
the format that GDB expects.
This function is called when kgdb does not have access to the
<code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span></code> and therefore it should fill the gdb registers
<strong>gdb_regs</strong> with what has been saved in <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">thread_struct</span></code>
thread field during switch_to.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.gdb_regs_to_pt_regs">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">gdb_regs_to_pt_regs</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">unsigned</span></span><span class="w"> </span><span class="kt"><span class="pre">long</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">gdb_regs</span></span>, <span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">pt_regs</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">regs</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.gdb_regs_to_pt_regs" title="Link to this definition">¶</a><br /></dt>
<dd><p>Convert GDB regs to ptrace regs.</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">unsigned</span> <span class="pre">long</span> <span class="pre">*gdb_regs</span></code></dt><dd><p>A pointer to hold the registers we’ve received from GDB.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span> <span class="pre">*regs</span></code></dt><dd><p>A pointer to a <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span></code> to hold these values in.</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>Convert the GDB regs in <strong>gdb_regs</strong> into the pt_regs, and store them
in <strong>regs</strong>.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_arch_handle_exception">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_arch_handle_exception</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">vector</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">signo</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">err_code</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">remcom_in_buffer</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">remcom_out_buffer</span></span>, <span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">pt_regs</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">regs</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_arch_handle_exception" title="Link to this definition">¶</a><br /></dt>
<dd><p>Handle architecture specific GDB packets.</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">vector</span></code></dt><dd><p>The error vector of the exception that happened.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">signo</span></code></dt><dd><p>The signal number of the exception that happened.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">err_code</span></code></dt><dd><p>The error code of the exception that happened.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*remcom_in_buffer</span></code></dt><dd><p>The buffer of the packet we have read.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*remcom_out_buffer</span></code></dt><dd><p>The buffer of <code class="docutils literal notranslate"><span class="pre">BUFMAX</span></code> bytes to write a packet into.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span> <span class="pre">*regs</span></code></dt><dd><p>The <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span></code> of the current process.</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>This function MUST handle the ‘c’ and ‘s’ command packets,
as well packets to set / remove a hardware breakpoint, if used.
If there are additional packets which the hardware needs to handle,
they are handled here. The code should return -1 if it wants to
process more packets, and a <code class="docutils literal notranslate"><span class="pre">0</span></code> or <code class="docutils literal notranslate"><span class="pre">1</span></code> if it wants to exit from the
kgdb callback.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_arch_handle_qxfer_pkt">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_arch_handle_qxfer_pkt</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">remcom_in_buffer</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">remcom_out_buffer</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_arch_handle_qxfer_pkt" title="Link to this definition">¶</a><br /></dt>
<dd><p>Handle architecture specific GDB XML packets.</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*remcom_in_buffer</span></code></dt><dd><p>The buffer of the packet we have read.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*remcom_out_buffer</span></code></dt><dd><p>The buffer of <code class="docutils literal notranslate"><span class="pre">BUFMAX</span></code> bytes to write a packet into.</p>
</dd>
</dl>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_call_nmi_hook">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_call_nmi_hook</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ignored</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_call_nmi_hook" title="Link to this definition">¶</a><br /></dt>
<dd><p>Call <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">kgdb_nmicallback()</span></code> on the current CPU</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">void</span> <span class="pre">*ignored</span></code></dt><dd><p>This parameter is only here to match the prototype.</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>If you’re using the default implementation of <a class="reference internal" href="#c.kgdb_roundup_cpus" title="kgdb_roundup_cpus"><code class="xref c c-func docutils literal notranslate"><span class="pre">kgdb_roundup_cpus()</span></code></a>
this function will be called per CPU. If you don’t implement
<a class="reference internal" href="#c.kgdb_call_nmi_hook" title="kgdb_call_nmi_hook"><code class="xref c c-func docutils literal notranslate"><span class="pre">kgdb_call_nmi_hook()</span></code></a> a default will be used.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_roundup_cpus">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_roundup_cpus</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_roundup_cpus" title="Link to this definition">¶</a><br /></dt>
<dd><p>Get other CPUs into a holding pattern</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">void</span></code></dt><dd><p>no arguments</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>On SMP systems, we need to get the attention of the other CPUs
and get them into a known state. This should do what is needed
to get the other CPUs to call <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">kgdb_wait()</span></code>. Note that on some arches,
the NMI approach is not used for rounding up all the CPUs. Normally
those architectures can just not implement this and get the default.</p>
<p>On non-SMP systems, this is not called.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_arch_set_pc">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_arch_set_pc</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">pt_regs</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">regs</span></span>, <span class="kt"><span class="pre">unsigned</span></span><span class="w"> </span><span class="kt"><span class="pre">long</span></span><span class="w"> </span><span class="n"><span class="pre">pc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_arch_set_pc" title="Link to this definition">¶</a><br /></dt>
<dd><p>Generic call back to the program counter</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span> <span class="pre">*regs</span></code></dt><dd><p>Current <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">pt_regs</span></code>.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">unsigned</span> <span class="pre">long</span> <span class="pre">pc</span></code></dt><dd><p>The new value for the program counter</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>This function handles updating the program counter and requires an
architecture specific implementation.</p>
</div></blockquote>
</div>
<dl class="c function">
<dt class="sig sig-object c" id="c.kgdb_arch_late">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_arch_late</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.kgdb_arch_late" title="Link to this definition">¶</a><br /></dt>
<dd><p>Perform any architecture specific initialization.</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Parameters</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">void</span></code></dt><dd><p>no arguments</p>
</dd>
</dl>
<p><strong>Description</strong></p>
<blockquote>
<div><p>This function will handle the late initialization of any
architecture specific callbacks. This is an optional function for
handling things like late initialization of hw breakpoints. The
default implementation does nothing.</p>
</div></blockquote>
</div>
<dl class="c struct">
<dt class="sig sig-object c" id="c.kgdb_arch">
<span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_arch</span></span></span><a class="headerlink" href="#c.kgdb_arch" title="Link to this definition">¶</a><br /></dt>
<dd><p>Describe architecture specific values.</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Definition</strong>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>struct kgdb_arch {
unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
unsigned long flags;
int (*set_breakpoint)(unsigned long, char *);
int (*remove_breakpoint)(unsigned long, char *);
int (*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
void (*disable_hw_break)(struct pt_regs *regs);
void (*remove_all_hw_break)(void);
void (*correct_hw_break)(void);
};
</pre></div>
</div>
<p><strong>Members</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">gdb_bpt_instr</span></code></dt><dd><p>The instruction to trigger a breakpoint.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">flags</span></code></dt><dd><p>Flags for the breakpoint, currently just <code class="docutils literal notranslate"><span class="pre">KGDB_HW_BREAKPOINT</span></code>.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">set_breakpoint</span></code></dt><dd><p>Allow an architecture to specify how to set a software
breakpoint.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">remove_breakpoint</span></code></dt><dd><p>Allow an architecture to specify how to remove a
software breakpoint.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">set_hw_breakpoint</span></code></dt><dd><p>Allow an architecture to specify how to set a hardware
breakpoint.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">remove_hw_breakpoint</span></code></dt><dd><p>Allow an architecture to specify how to remove a
hardware breakpoint.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">disable_hw_break</span></code></dt><dd><p>Allow an architecture to specify how to disable
hardware breakpoints for a single cpu.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">remove_all_hw_break</span></code></dt><dd><p>Allow an architecture to specify how to remove all
hardware breakpoints.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">correct_hw_break</span></code></dt><dd><p>Allow an architecture to specify how to correct the
hardware debug registers.</p>
</dd>
</dl>
</div>
<dl class="c struct">
<dt class="sig sig-object c" id="c.kgdb_io">
<span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">kgdb_io</span></span></span><a class="headerlink" href="#c.kgdb_io" title="Link to this definition">¶</a><br /></dt>
<dd><p>Describe the interface for an I/O driver to talk with KGDB.</p>
</dd></dl>
<div class="kernelindent docutils container">
<p><strong>Definition</strong>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>struct kgdb_io {
const char *name;
int (*read_char) (void);
void (*write_char) (u8);
void (*flush) (void);
int (*init) (void);
void (*deinit) (void);
void (*pre_exception) (void);
void (*post_exception) (void);
struct console *cons;
};
</pre></div>
</div>
<p><strong>Members</strong></p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">name</span></code></dt><dd><p>Name of the I/O driver.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">read_char</span></code></dt><dd><p>Pointer to a function that will return one char.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">write_char</span></code></dt><dd><p>Pointer to a function that will write one char.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">flush</span></code></dt><dd><p>Pointer to a function that will flush any pending writes.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">init</span></code></dt><dd><p>Pointer to a function that will initialize the device.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">deinit</span></code></dt><dd><p>Pointer to a function that will deinit the device. Implies that
this I/O driver is temporary and expects to be replaced. Called when
an I/O driver is replaced or explicitly unregistered.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">pre_exception</span></code></dt><dd><p>Pointer to a function that will do any prep work for
the I/O driver.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">post_exception</span></code></dt><dd><p>Pointer to a function that will do any cleanup work
for the I/O driver.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">cons</span></code></dt><dd><p>valid if the I/O device is a console; else NULL.</p>
</dd>
</dl>
</div>
</section>
<section id="kgdboc-internals">
<h3>kgdboc internals<a class="headerlink" href="#kgdboc-internals" title="Link to this heading">¶</a></h3>
<section id="kgdboc-and-uarts">
<h4>kgdboc and uarts<a class="headerlink" href="#kgdboc-and-uarts" title="Link to this heading">¶</a></h4>
<p>The kgdboc driver is actually a very thin driver that relies on the
underlying low level to the hardware driver having “polling hooks” to
which the tty driver is attached. In the initial implementation of
kgdboc the serial_core was changed to expose a low level UART hook for
doing polled mode reading and writing of a single character while in an
atomic context. When kgdb makes an I/O request to the debugger, kgdboc
invokes a callback in the serial core which in turn uses the callback in
the UART driver.</p>
<p>When using kgdboc with a UART, the UART driver must implement two
callbacks in the <a class="reference internal" href="../../driver-api/serial/driver.html#c.uart_ops" title="uart_ops"><code class="xref c c-struct docutils literal notranslate"><span class="pre">struct</span> <span class="pre">uart_ops</span></code></a>.
Example from <code class="docutils literal notranslate"><span class="pre">drivers/8250.c</span></code>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#ifdef CONFIG_CONSOLE_POLL
.poll_get_char = serial8250_get_poll_char,
.poll_put_char = serial8250_put_poll_char,
#endif
</pre></div>
</div>
<p>Any implementation specifics around creating a polling driver use the
<code class="docutils literal notranslate"><span class="pre">#ifdef</span> <span class="pre">CONFIG_CONSOLE_POLL</span></code>, as shown above. Keep in mind that
polling hooks have to be implemented in such a way that they can be
called from an atomic context and have to restore the state of the UART
chip on return such that the system can return to normal when the
debugger detaches. You need to be very careful with any kind of lock you
consider, because failing here is most likely going to mean pressing the
reset button.</p>
</section>
<section id="kgdboc-and-keyboards">
<h4>kgdboc and keyboards<a class="headerlink" href="#kgdboc-and-keyboards" title="Link to this heading">¶</a></h4>
<p>The kgdboc driver contains logic to configure communications with an
attached keyboard. The keyboard infrastructure is only compiled into the
kernel when <code class="docutils literal notranslate"><span class="pre">CONFIG_KDB_KEYBOARD=y</span></code> is set in the kernel configuration.</p>
<p>The core polled keyboard driver for PS/2 type keyboards is in
<code class="docutils literal notranslate"><span class="pre">drivers/char/kdb_keyboard.c</span></code>. This driver is hooked into the debug core
when kgdboc populates the callback in the array called
<span class="c-expr sig sig-inline c"><span class="n">kdb_poll_funcs</span><span class="p">[</span><span class="p">]</span></span>. The <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">kdb_get_kbd_char()</span></code> is the top-level
function which polls hardware for single character input.</p>
</section>
<section id="kgdboc-and-kms">
<h4>kgdboc and kms<a class="headerlink" href="#kgdboc-and-kms" title="Link to this heading">¶</a></h4>
<p>The kgdboc driver contains logic to request the graphics display to
switch to a text context when you are using <code class="docutils literal notranslate"><span class="pre">kgdboc=kms,kbd</span></code>, provided
that you have a video driver which has a frame buffer console and atomic
kernel mode setting support.</p>
<p>Every time the kernel debugger is entered it calls
<code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">kgdboc_pre_exp_handler()</span></code> which in turn calls <a class="reference internal" href="../../driver-api/tty/console.html#c.con_debug_enter" title="con_debug_enter"><code class="xref c c-func docutils literal notranslate"><span class="pre">con_debug_enter()</span></code></a>
in the virtual console layer. On resuming kernel execution, the kernel
debugger calls <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">kgdboc_post_exp_handler()</span></code> which in turn calls
<a class="reference internal" href="../../driver-api/tty/console.html#c.con_debug_leave" title="con_debug_leave"><code class="xref c c-func docutils literal notranslate"><span class="pre">con_debug_leave()</span></code></a>.</p>
<p>Any video driver that wants to be compatible with the kernel debugger
and the atomic kms callbacks must implement the <code class="docutils literal notranslate"><span class="pre">mode_set_base_atomic</span></code>,
<code class="docutils literal notranslate"><span class="pre">fb_debug_enter</span></code> and <code class="docutils literal notranslate"><span class="pre">fb_debug_leave</span> <span class="pre">operations</span></code>. For the
<code class="docutils literal notranslate"><span class="pre">fb_debug_enter</span></code> and <code class="docutils literal notranslate"><span class="pre">fb_debug_leave</span></code> the option exists to use the
generic drm fb helper functions or implement something custom for the
hardware. The following example shows the initialization of the
.mode_set_base_atomic operation in
drivers/gpu/drm/i915/intel_display.c:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>static const struct drm_crtc_helper_funcs intel_helper_funcs = {
[...]
.mode_set_base_atomic = intel_pipe_set_base_atomic,
[...]
};
</pre></div>
</div>
<p>Here is an example of how the i915 driver initializes the
fb_debug_enter and fb_debug_leave functions to use the generic drm
helpers in <code class="docutils literal notranslate"><span class="pre">drivers/gpu/drm/i915/intel_fb.c</span></code>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>static struct fb_ops intelfb_ops = {
[...]
.fb_debug_enter = drm_fb_helper_debug_enter,
.fb_debug_leave = drm_fb_helper_debug_leave,
[...]
};
</pre></div>
</div>
</section>
</section>
</section>
<section id="credits">
<h2>Credits<a class="headerlink" href="#credits" title="Link to this heading">¶</a></h2>
<p>The following people have contributed to this document:</p>
<ol class="arabic simple">
<li><p>Amit Kale <<a class="reference external" href="mailto:amitkale%40linsyssoft.com">amitkale<span>@</span>linsyssoft<span>.</span>com</a>></p></li>
<li><p>Tom Rini <<a class="reference external" href="mailto:trini%40kernel.crashing.org">trini<span>@</span>kernel<span>.</span>crashing<span>.</span>org</a>></p></li>
</ol>
<p>In March 2008 this document was completely rewritten by:</p>
<ul class="simple">
<li><p>Jason Wessel <<a class="reference external" href="mailto:jason.wessel%40windriver.com">jason<span>.</span>wessel<span>@</span>windriver<span>.</span>com</a>></p></li>
</ul>
<p>In Jan 2010 this document was updated to include kdb.</p>
<ul class="simple">
<li><p>Jason Wessel <<a class="reference external" href="mailto:jason.wessel%40windriver.com">jason<span>.</span>wessel<span>@</span>windriver<span>.</span>com</a>></p></li>
</ul>
</section>
</section>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©The kernel development community.
|
Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
& <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
|
<a href="../../_sources/process/debugging/kgdb.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>