Skip to Main Content
The Art of Debugging with GDB, DDD, and Eclipse
book

The Art of Debugging with GDB, DDD, and Eclipse

by Norman Matloff, Peter Jay Salzman
September 2008
Intermediate to advanced content levelIntermediate to advanced
280 pages
6h 31m
English
No Starch Press
Content preview from The Art of Debugging with GDB, DDD, and Eclipse

Extended GDB Example

This has been a lot of information, so a short example of setting breakpoints that you can follow along with is warranted. Consider the following multi-file C code:

main.c

#include <stdio.h>
void swap(int *a, int *b);

int main(void)
{
   int i = 3;
   int j = 5;

   printf("i: %d, j: %d\n", i, j);
   swap(&i, &j);
   printf("i: %d, j: %d\n", i, j);

   return 0;
}

swapper.c

void swap(int *a, int *b)
{
   int c = *a;
   *a = *b;
   *b = c;
}

Compile this code and run GDB on the executable:

$ gcc -g3 -Wall -Wextra -c main.c swapper.c
$ gcc -o swap main.o swapper.o
$ gdb swap

Note

This is the first time in this book that we've compiled a multi-file C program, so a word is in order. The first line of the compilation process (above) produces two ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning x64 Assembly Programming: From Novice to AVX Professional

Beginning x64 Assembly Programming: From Novice to AVX Professional

Jo Van Hoey
Command-Line Rust

Command-Line Rust

Ken Youens-Clark
Modern CMake for C++

Modern CMake for C++

Rafał Świdziński

Publisher Resources

ISBN: 9781593271749Errata Page