<p>
Frustrated by gdb tutorials that are either too complicated or too simple? I think this might be an actually-useful tutorial to help you see how and why gdb can be useful.  Anyway, it's the path I followed to finding a use for the mysterious gdb, so maybe it will work for you.
</p>

<p>
To follow along with this episode, here's some simple yet buggy code. This compiles but crashes when run.
</p>

<pre><code>
#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;  // rand
#include &lt;stdio.h&gt;  // printf

using namespace std;

int main () {

srand (time(NULL));
int penguin = rand() % 8;
cout &lt;&lt; &quot;This is a message from your friendly coder\n&quot; &lt;&lt; endl;
int kiwi = 3;

printf("penguin is set to is %s\n", penguin);
printf("kiwi is set to is %s\n", kiwi);

 return 0;
} // main
</code>
</pre>

<p>
To compile it and see it crash, do this:
</p>

<pre><code>
$ g++ example.cpp
$ ./a.out
</code></pre>

<p>
To compile it with debug symbols so you can step through it in gdb, do this:
</p>

<pre><code>
$ g++ -g -o debugtest example.cpp
$ gdb debugtest
</code></pre>

<p>
You can now follow along with this tutorial.
</p>

<p>
<em>For extra credit, try compiling this with clang++ instead&#33;</em>
</p>



