toolchain/share/doc/gdb/Optimized-Code.html

84 lines
4.1 KiB
HTML

<html lang="en">
<head>
<title>Optimized Code - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="prev" href="Data.html#Data" title="Data">
<link rel="next" href="Macros.html#Macros" title="Macros">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Optimized-Code"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Macros.html#Macros">Macros</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Data.html#Data">Data</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
<hr>
</div>
<h2 class="chapter">11 Debugging Optimized Code</h2>
<p><a name="index-optimized-code_002c-debugging-834"></a><a name="index-debugging-optimized-code-835"></a>
Almost all compilers support optimization. With optimization
disabled, the compiler generates assembly code that corresponds
directly to your source code, in a simplistic way. As the compiler
applies more powerful optimizations, the generated assembly code
diverges from your original source code. With help from debugging
information generated by the compiler, <span class="sc">gdb</span> can map from
the running program back to constructs from your original source.
<p><span class="sc">gdb</span> is more accurate with optimization disabled. If you
can recompile without optimization, it is easier to follow the
progress of your program during debugging. But, there are many cases
where you may need to debug an optimized version.
<p>When you debug a program compiled with &lsquo;<samp><span class="samp">-g -O</span></samp>&rsquo;, remember that the
optimizer has rearranged your code; the debugger shows you what is
really there. Do not be too surprised when the execution path does not
exactly match your source file! An extreme example: if you define a
variable, but never use it, <span class="sc">gdb</span> never sees that
variable&mdash;because the compiler optimizes it out of existence.
<p>Some things do not work as well with &lsquo;<samp><span class="samp">-g -O</span></samp>&rsquo; as with just
&lsquo;<samp><span class="samp">-g</span></samp>&rsquo;, particularly on machines with instruction scheduling. If in
doubt, recompile with &lsquo;<samp><span class="samp">-g</span></samp>&rsquo; alone, and if this fixes the problem,
please report it to us as a bug (including a test case!).
See <a href="Variables.html#Variables">Variables</a>, for more information about debugging optimized code.
<ul class="menu">
<li><a accesskey="1" href="Inline-Functions.html#Inline-Functions">Inline Functions</a>: How <span class="sc">gdb</span> presents inlining
<li><a accesskey="2" href="Tail-Call-Frames.html#Tail-Call-Frames">Tail Call Frames</a>: <span class="sc">gdb</span> analysis of jumps to functions
</ul>
</body></html>