How do I debug a C program in Mint?

Forum rules
Before you post please read how to get help
Post Reply
User avatar
0x2620
Level 3
Level 3
Posts: 117
Joined: Mon Jan 09, 2017 3:17 pm

How do I debug a C program in Mint?

Post by 0x2620 »

I'm a Java programmer by training, trying to teach myself C. I currently use medit and compile programs manually. What are my options for debugging a C program and inspecting the state of variables at various times?

User avatar
Flemur
Level 17
Level 17
Posts: 7540
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: How do I debug a C program in Mint?

Post by Flemur »

Code: Select all

$ cc -g program.c
$ gdb a.out
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?

dong
Level 1
Level 1
Posts: 7
Joined: Mon Apr 16, 2018 10:31 pm

Re: How do I debug a C program in Mint?

Post by dong »

debug is OK.
"A computer is like air conditioning. It becomes useless when you open Windows." - Linus Torvalds

User avatar
xenopeek
Level 24
Level 24
Posts: 24279
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How do I debug a C program in Mint?

Post by xenopeek »

Indeed, gdb is the debugger you'll likely want to use. IDEs like GNOME Builder (for writing Gtk programs, like for Cinnamon, MATE and Xfce) or Qt Creator (for writing Qt programs, like for KDE) come with builtin gdb integration. You may find modules to add gdb integration available for other IDEs, like for Eclipse.

You can also run gdb standalone from the terminal as noted above. Going through its documentation https://www.gnu.org/software/gdb/documentation/ or getting a good book on it will undoubtedly help you make the most of it.

A friendly option is to use gdbgui, which you start from the terminal just like gdb, but it opens a page in your web browser where you get a GUI to interact with gdb. More info here https://github.com/cs01/gdbgui/

If you're writing very big and complex programs, Valgrind may also be useful tool. You can use it for profiling your programs and finding performance bottlenecks and track down memory management and threading bugs. You could also just switch from programming in C to programming in Rust of course, which is memory and thread safe by design.
Image

Post Reply

Return to “Scripts & Bash”