[wwwdocs] segfault.html
Kelley Cook
KelleyCook@comcast.net
Fri Jan 31 22:10:00 GMT 2003
On Thu, 16 Jan 2003 10:21:24 -0800, Janis Johnson wrote:
> o The DOCTYPE stuff isn't included in the files that are in
> wwwdocs/htdocs, but is added by a tool before they are copied to
> the web pages.
> o The web pages themselves don't specify styles; Gerald can provide
> more information about that.
> o Web pages don't generally say who wrote them, although that info
> can be in the CVS log.
> o The title is rather long; how about "How to Debug a GCC Seg Fault."
How is this version?
<html>
<head>
<title>
How to debug a GCC Segmentation fault
</title>
</head>
<body>
<h1>
How to debug a GCC Segmentation fault
</h1>
<hr />
<p>
Configure GCC with <code>--enable-checking</code>. Compile
it with
<code>-g</code> so that you can use gdb.
</p>
<p>
Compile your test case with <code>-v -da -Q</code>.
</p>
<ul>
<li>
<code>-Q</code> will show which function in the test case is
causing
it to crash.
</li>
<li>
<code>-v</code> shows how `cc1' was invoked (useful for
invoking cc1
manually in gdb).
</li>
<li>
<code>-da</code> dumps the RTL to a file after each stage.
</li>
</ul>
<p>
Next, use gdb to get a stack trace. Compile the compiler
with
debugging enabled (<code>-g</code>), use the <code>-v</code>
option to see how cc1 is getting
invoked, and then do
</p>
<div style="margin-left: 40px;">
bash$ <code>gdb cc1</code><br />
gdb> <code>run <arguments></code><br />
… (it will stop at the Seg fault)<br />
gdb> <code>where</code><br />
…<br />
gdb> <code>list</code>
</div>
<p>
Print out the values of interesting variables (e.g. the ones in
the
statement which got a segmentation fault).
</p>
<p>
You can use the <code>pt</code> and <code>pr</code> macros from
the
gdbinit.in file to display them. For example, if there is a
value
of type <code>tree</code> named <code>t</code>, and a value of
type
<code>rtx</code> named <code>r</code>, you can use these
commands:
</p>
<div style="margin-left: 40px;">
gdb> <code>source .gdbinit</code><br />
gdb> <code>print t</code><br />
gdb> <code>pt</code><br />
gdb> <code>print r</code><br />
gdb> <code>pr</code><br />
gdb> <code>pt</code><br />
</div>
</body>
</html>
More information about the Gcc-patches
mailing list