/usr/share/doc/xorg/howto/use-gdb.html is in xserver-xorg 1:7.6+12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.6.6" />
<title>How to use gdb</title>
<link rel="stylesheet" href="../xsf.css" type="text/css" />
<script type="text/javascript" src="../asciidoc-xhtml11.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install(2);
/*]]>*/
</script>
</head>
<body class="article">
<div id="header">
<h1><a href="../index.html">XSF</a> / How to use gdb</h1>
<span id="author">Cyril Brulebois</span><br />
<span id="email"><tt><<a href="mailto:kibi@debian.org">kibi@debian.org</a>></tt></span><br />
<div id="toc">
<div id="toctitle">Table of Contents</div>
<noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="_foreword">Foreword</h2>
<div class="sectionbody">
<div class="paragraph"><p>One should note that X is responsible for VT switching, meaning
switching between an X session and console terminals. In other words,
<tt>Ctrl+Alt+Fn</tt> is handled by X. If X is stopped, for example because
it’s running under <tt>gdb</tt>, one can no longer switch to another
VT. That’s why we’re recommending using a second machine to debug
X. Nevertheless, here are some instructions to attempt debugging X
with a single machine.</p></div>
<div class="sect2">
<h3 id="_one_machine_approach">One-machine approach</h3>
<div class="paragraph"><p>This is a <em>post-mortem</em> approach. The idea is to run X with the
<tt>-core</tt> option. Once it dies, a core file (<tt>/etc/X11/core</tt>) is
generated, and can be loaded from <tt>gdb</tt>.</p></div>
<div class="paragraph"><p>Follow these steps:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Getting a core file.
</p>
</li>
<li>
<p>
Loading a core file.
</p>
</li>
<li>
<p>
Displaying/saving a backtrace.
</p>
</li>
</ol></div>
</div>
<div class="sect2">
<h3 id="_two_machine_approach">Two-machine approach</h3>
<div class="paragraph"><p>You pay the “need a second machine” price, but that buys you
interactivity. Just log into the first machine from the second one,
using <tt>ssh</tt>.</p></div>
<div class="paragraph"><p>Follow these steps:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Attaching/Starting X from gdb.
</p>
</li>
<li>
<p>
Displaying/saving a backtrace.
</p>
</li>
</ol></div>
</div>
<div class="sect2">
<h3 id="_needed_packages">Needed packages</h3>
<div class="paragraph"><p>Obviously, <tt>gdb</tt> is needed; <tt>xserver-xorg-core-dbg</tt> contains the
debugging symbols for the server itself. Other needed packages can be
determined by looking at the backtrace. <strong>FIXME: More info about
that.</strong></p></div>
<div style="page-break-after:always"></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_actual_gdb_work">Actual gdb work</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_getting_a_core_file">Getting a core file</h3>
<div class="ulist"><ul>
<li>
<p>
Using <tt>gdm3</tt>: The idea is to tweak the daemon’s
<tt>LocalXserverCommand</tt> setting, adding the <tt>-core</tt> option. As of
<tt>gdm3 2.30</tt>, the defaults can be found in
<tt>/usr/share/gdm/gdm.schemas</tt>. Sample <tt>/etc/gdm3/daemon.conf</tt>
excerpt:
</p>
</li>
</ul></div>
<div class="listingblock">
<div class="content">
<pre><tt>[daemon]
LocalXserverCommand=/usr/bin/Xorg -br -verbose -audit 0 -novtswitch -core</tt></pre>
</div></div>
<div class="ulist"><ul>
<li>
<p>
Using <tt>kdm</tt>: One should look for the <tt>ServerArgsLocal</tt> variable in
the <tt>/etc/kde4/kdm/kdmrc</tt> file, and add <tt>-core</tt> there. Example:
</p>
</li>
</ul></div>
<div class="listingblock">
<div class="content">
<pre><tt>ServerArgsLocal=-br -nolisten tcp -core</tt></pre>
</div></div>
<div class="ulist"><ul>
<li>
<p>
Using <tt>xdm</tt>: It’s sufficient to add <tt>-core</tt> to the command
configured through <tt>/etc/X11/xdm/Xservers</tt>, for example:
</p>
</li>
</ul></div>
<div class="listingblock">
<div class="content">
<pre><tt>:0 local /usr/bin/X :0 vt7 -nolisten tcp -core</tt></pre>
</div></div>
</div>
<div class="sect2">
<h3 id="_loading_a_core_file">Loading a core file</h3>
<div class="paragraph"><p>That’s trivial, one just needs to pass both the core file and the path
to the binary:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt># gdb -c /etc/X11/core /usr/bin/Xorg</tt></pre>
</div></div>
<div class="paragraph"><p>Now <tt>gdb</tt> is ready to display backtraces.</p></div>
</div>
<div class="sect2">
<h3 id="_attaching_x_from_gdb">Attaching X from gdb</h3>
<div class="paragraph"><p>The way of starting X doesn’t really matter, as <tt>gdb</tt> makes it
possible to attach a running process. If there’s a single X instance
running, that will do the job:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt># gdb attach $(pidof X)
[---GDB starts---]
(gdb) handle SIGPIPE nostop
(gdb) cont</tt></pre>
</div></div>
<div class="paragraph"><p>If there are several instances, one can use <tt>ps aux</tt> to determine the
PID of the appropriate instance (2nd column → <tt>$pid</tt>), and then attach
it:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt># gdb attach $pid
[---GDB starts---]
(gdb) handle SIGPIPE nostop
(gdb) cont</tt></pre>
</div></div>
</div>
<div class="sect2">
<h3 id="_starting_x_from_gdb">Starting X from gdb</h3>
<div class="paragraph"><p>In case X crashes at start-up, one can start X from <tt>gdb</tt> in the
following way. In this example, the only parameter is the display, but
more parameters can be added.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt># gdb --args Xorg :0
[---GDB starts---]
(gdb) handle SIGPIPE nostop
(gdb) run</tt></pre>
</div></div>
</div>
<div class="sect2">
<h3 id="_what_is_sigpipe">What is SIGPIPE?</h3>
<div class="paragraph"><p><tt>SIGPIPE</tt> is a signal that can reach the X server quite easily,
especially when performing a VT switch, or refreshing large parts of
the screen. That’s why we ask <tt>gdb</tt> not to stop when such a signal is
caught, thanks to the <tt>handle SIGPIPE nostop</tt> command.</p></div>
</div>
<div class="sect2">
<h3 id="_how_to_display_a_backtrace">How to display a backtrace?</h3>
<div class="paragraph"><p>Once X is crashed, for example because it received a <tt>SIGSEGV</tt>
(segmentation fault, usually because of a NULL pointer dereference),
or a <tt>SIGBUS</tt>, one gets back to the <tt>gdb</tt> prompt. One can then request
a backtrace (<tt>bt</tt>) or a full backtrace (<tt>bt full</tt>). The latter is what
developers are usually interested in, because variable values are also
available.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>(gdb) bt
(gdb) bt full</tt></pre>
</div></div>
</div>
<div class="sect2">
<h3 id="_how_to_save_a_backtrace">How to save a backtrace?</h3>
<div class="paragraph"><p>To save a recording of the gdb session to a file (<tt>gdb.txt</tt> by
default):</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>(gdb) set logging on</tt></pre>
</div></div>
<div class="paragraph"><p>To save in a different file, use this instead:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>(gdb) set logging file my-file.txt
(gdb) set logging on</tt></pre>
</div></div>
<div class="paragraph"><p>Once logging is enabled, you can request a (full) backtrace using the
previous commands.</p></div>
</div>
</div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated 2011-06-06 07:22:56 UTC
</div>
</div>
</body>
</html>
|