How do I debug a C program in Mint?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
0x2620

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?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Flemur
Level 20
Level 20
Posts: 10097
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

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

Post by dong »

debug is OK.
User avatar
xenopeek
Level 25
Level 25
Posts: 29460
Joined: Wed Jul 06, 2011 3:58 am

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
Locked

Return to “Scripts & Bash”