Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr3284 :: Introduction to gdb

A really friendly introduction to Gnu Debugger

<< First, < Previous, , Latest >>

Hosted by Klaatu on 2021-03-04 is flagged as Clean and is released under a CC-BY-SA license.
programming, cpp, gdb, gcc. (Be the first).
The show is available on the Internet Archive at: https://archive.org/details/hpr3284

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:23:40

Compilers - how they work.

In this series we examine how compilers work

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.

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


#include <iostream>
#include <stdlib.h>  // rand
#include <stdio.h>  // printf

using namespace std;

int main () {

srand (time(NULL));
int penguin = rand() % 8;
cout << "This is a message from your friendly coder\n" << 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

To compile it and see it crash, do this:


$ g++ example.cpp
$ ./a.out

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


$ g++ -g -o debugtest example.cpp
$ gdb debugtest

You can now follow along with this tutorial.

For extra credit, try compiling this with clang++ instead!


Comments

Subscribe to the comments RSS feed.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?