<h1 id="debug-directly-in-vim">Debug directly in vim</h1>
<p>TL;DL you can use gdb directly from vim without installing any
extensions. Just compile your program with debug options and do:</p>
<pre><code>    :packadd termdebug
    :TermdebugCommand path-to-my-program</code></pre>
<h3 id="now-the-actual-notes">Now the actual notes:</h3>
<p>If you actually listened to the show, I am sorry for how long it took
me to realize that I was compiling without debug flags.</p>
<p>This is not a good overview of <code>gdb</code>, I don't think, for
that I would recommend <a href="https://gnuworldorder.info/#415">episode
415 on Klaatu's Gnu World Order podcast</a>.</p>
<p>The program that we build up to is this:</p>
<pre><code>// file: main.c
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

void greet(char* greeting)
{
-    int end = strlen(greeting);
+    int end = strlen(greeting) - 1;
    if (greeting[end] == &#39;
&#39;)
        printf(&quot;%s&quot;, greeting);
    else
        printf(&quot;%s
&quot;, greeting);
}

int main ()
{
    greet( &quot;Hello world!
&quot;);
    return 0;
}</code></pre>
<p>Where we use gdb to find out that we are checking one character past
the end in the if-condition rather than the last character, this then
results in a double new-line.</p>
<p>Once the debugger is launched within vim, termdebug offers a few ways
to control the debugging, namely:</p>
<p><code>:Source</code> - focus on source window. <code>:Gdb</code> -
focus on debugger window. <code>:Program</code> - focus on program
output window <code>:Break</code> - introduce a break point in line
under the cursor (in the source window) <code>:Clear</code> - clear the
break point in the line under the cursor. <code>:Evaluate</code> - show
the value of the expression under the cursor.</p>
<p>... And a good deal more, if you're interested just have a gander at
<code>:help termdebug</code>.</p>
<p>I hope this helps someone make their debugging experience slightly
less painful, as it has helped me recently :)</p>
