Hacker Public Radio

HPR4042: Debugging directly in vim


Listen Later

Debug directly in vim
TL;DL you can use gdb directly from vim without installing any
extensions. Just compile your program with debug options and do:
:packadd termdebug
:TermdebugCommand path-to-my-program
Now the actual notes:
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.
This is not a good overview of gdb, I don't think, for
that I would recommend episode
415 on Klaatu's Gnu World Order podcast.
The program that we build up to is this:
// file: main.c
#include <stdio.h>
#include <string.h>
void greet(char* greeting)
{
- int end = strlen(greeting);
+ int end = strlen(greeting) - 1;
if (greeting[end] == '
')
printf("%s", greeting);
else
printf("%s
", greeting);
}
int main ()
{
greet( "Hello world!
");
return 0;
}
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.
Once the debugger is launched within vim, termdebug offers a few ways
to control the debugging, namely:
:Source - focus on source window. :Gdb -
focus on debugger window. :Program - focus on program
output window :Break - introduce a break point in line
under the cursor (in the source window) :Clear - clear the
break point in the line under the cursor. :Evaluate - show
the value of the expression under the cursor.
... And a good deal more, if you're interested just have a gander at
:help termdebug.
I hope this helps someone make their debugging experience slightly
less painful, as it has helped me recently :)
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

289 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

373 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

653 Listeners

Curious Cases by BBC Radio 4

Curious Cases

826 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

422 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,035 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

181 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,800 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

139 Listeners

What the Hack? by DeleteMe

What the Hack?

221 Listeners