How to use gdb with gui to debug c program. gdb is very strong debug tool. gdb tool comes with very simple inbuilt graphical user interface. In this article we will learn how to use gdb with its inbuilt gui.

how to use gdb with gui to debug c program

( Step 1) Let us create a simple C program as shown below.


// sample code for gdb gui
void learngdb_with_gui() {

	printf("Learn with care \n");
	for (int i = 0; i < 4; i++) {
		printf("gdb = %d\n", i);


int main() {
	// call
	return 0;


Step 2) build sample code ( file: sample.c)

bosch@bosch-Inspiron-N5050:~$ gcc -g -std=c99 sample.c -o sample

Note: To debug c/cpp program compile with -g option is necessary. After running above command ( step 2) , our executable or binary file sample would be created inside current working directory. to know the current working directory run pwd command on linux terminal.

Step 3) Run gdb with binary sample to debug with GUI

bosch@bosch-Inspiron-N5050:~$ gdb --tui sample

After running above command you will get gdb running with your binary file sample with a simple screen on top of the terminal screen. simply debug your program. when we do break and execute next command on gdb , you can see highlighted code executing on screen.

Video tutorial for how to use gdb with gui to debug c program

Related Contents to follow