Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The first step is to compile your program with <code>-g</code> to include debugging information within the executable:</p> <pre><code>g++ -g -o myprog.exe mycode.cpp </code></pre> <p>Then the program can be loaded into <code>gdb</code>:</p> <pre><code>gdb myprog.exe </code></pre> <p>A few commands to get you started:</p> <ul> <li><code>break main</code> will cause the debugger to break when <code>main</code> is called. You can also break on lines of code with <code>break FILENAME:LINENO</code>. For example, <code>break mycode.cpp:4</code> breaks execution whenever the program reaches line 4 of <code>mycode.cpp</code>.</li> <li><code>start</code> starts the program. In your case, you need to set breakpoints before starting the program because it exits quickly.</li> </ul> <p>At a breakpoint:</p> <ul> <li><code>print VARNAME</code>. That's how you print values of variables, whether local, static, or global. For example, at the <code>for</code> loop, you can type <code>print temp</code> to print out the value of the <code>temp</code> variable.</li> <li><code>step</code> This is equivalent to "step into".</li> <li><code>next</code> or <code>adv +1</code> Advance to the next line (like "step over"). You can also advance to a specific line of a specific file with, for example, <code>adv mycode.cpp:8</code>.</li> <li><code>bt</code> Print a backtrace. This is a stack trace, essentially.</li> <li><code>continue</code> Exactly like a "continue" operation of a visual debugger. It causes the program execution to continue until the next break point or the program exits.</li> </ul> <p>The best thing to read is the <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/" rel="noreferrer">GDB users' manual</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload