Getting Started With Debuggers

Getting Started With Debuggers
January 6, 2019 No Comments Uncategorized Zian Smith

Sometimes when writing complex C programs you need the assistance of a debugger. This post will not make you an expert, but it will introduce you to two popular debuggers known as Valgrind and GDB (GNU DeBugger).

You can find the source code and list of supported platforms at http://www.valgrind.org/info/platforms.html. The License is GPL.

If you’re on Debian or a Debian based OS such as Ubuntu, you can simply type: apt -y install valgrind

If you’re on Windows, you will probably need to find a binary (Valgrind is GNU/Linux focused).

Here we have a file created in nano that is the famous “Hello world!” C program.

We will compile this with:    gcc -std=c11 --pedantic -Wall example.c -o example

 

You will now have a C binary in the directory which you compiled example.c, we are going to open this with valgrind.

Try running:   valgrind -v example

You should see the following output. Executing valgrind ./example will yield similar results but will also display the output.

Now we will view the disassembly of the C program we created. Run:  gdb ./example

Run: start, then run disas, you should see the following:

Behold! The disassembly of your C Program!

 

Although this basic introduction won’t make you an expert overnight by any stretch of the imagination, hopefully it will get you started on your journey of learning to use debuggers. For more reading, you can check out the docs.

 

GDB Docs: https://www.gnu.org/software/gdb/documentation/

Valgrind Docs: http://valgrind.org/docs/

About The Author

Leave a reply

Your email address will not be published. Required fields are marked *