Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General > LinuxAnswers Discussion
User Name
LinuxAnswers Discussion This forum is to discuss articles posted to LinuxAnswers.


  Search this Thread
Old 02-26-2015, 04:48 PM   #1
Registered: Sep 2010
Distribution: Used Debian since Sarge. (~2005)
Posts: 373

Rep: Reputation: 21
Getting started using the GDB debugger to debug C/C++ source.

A new la entry has been added:

Getting started using the GDB debugger to debug C/C++ source.

This howto is intended for anyone who never succeeded to use gdb successfully.
gdb, being a CLI application, may not appeal to the eye, but my experience in using it, has proven that it is a very good debugger.

Step 1:
Compile your source code using the g++/gcc -g option.
Old 02-27-2015, 08:43 AM   #2
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,416
Blog Entries: 13

Rep: Reputation: 4522Reputation: 4522Reputation: 4522Reputation: 4522Reputation: 4522Reputation: 4522Reputation: 4522Reputation: 4522Reputation: 4522Reputation: 4522Reputation: 4522
I like what you've written and I'm a proponent of using GDB as well.

You should make that a blog entry.

Another thing you should note in there if you agree, is that GDB can be used through emacs. I don't use it much that way but it acts more like a real debugger and one can use the mouse for things directly within the screen, plus there are menus also accessible via the mouse. You also can pull up child windows for things like the stack and watch variables, memory views, etc.
  1. Edit a simple C source in emacs
  2. Issue compile command at the prompt, default is "make -k", just change that to be: gcc -ggdb -o <exe-name> <source-name>, this part is not necessary, but you can compile within emacs and a benefit is that you can browse for next error using the editor where it jumps right to each error and corrects line alignment if you edit/fix problems
  3. Issue debug command "gdb" at the prompt, it allows you to enter in options, but usually will pick good defaults and detect the executable file matching your source, especially if you compiled with it.
  4. From within the debugger you can do things like mouse left click near the left border of a source line to make a breakpoint, there are menu options to go, step, step-over, step-in, look at data, open sub-windows for things like watches, stack and so forth.
For those who can type and remember stuff, it's not always the best. Plus on a target system which may or may not have a display manager, knowing command line GDB is best.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
gdb, debug with separate debug file and different source dir problem a4z Programming 5 10-17-2014 02:55 AM
LXer: How to debug a C/C++ program with GDB command-line debugger LXer Syndicated Linux News 0 09-30-2014 11:42 AM
Getting started with an open source project (Cortex-m debugger) Palmitoxico Linux - General 8 09-26-2014 09:13 AM
debug library source in GDB/DDD knobby67 Programming 1 08-25-2009 03:24 PM
GDB debugger breakpoints cleopard Programming 1 05-07-2008 04:15 PM > Forums > Linux Forums > Linux - General > LinuxAnswers Discussion

All times are GMT -5. The time now is 08:26 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration