Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force return with a specific value while debugging in Eclipse CDT

I'm debugging some C++ code in Eclipse configured with a MinGW gdb configuration.

When running gdb directly in a shell, I can return from a function immediately, and tell it what value the function should return, with for example return 3.

How do I do that while debugging in Eclipse rather than running gdb outside of Eclipse in a shell window?

like image 238
Ben Avatar asked Aug 17 '26 08:08

Ben


1 Answers

Eclipse CDT does not provide that feature in the UI with a button or similar. Feel free to enter a feature request, or even better a patch.

However, you can of type return 3 in the GDB input console in CDT without having to leave the Eclipse environment. Here are some instructions I wrote for a related (but not duplicate) question that shows you how to use the console.

Console

The console view allows you to enter GDB commands in standard GDB syntax.

To use the Console:

  1. Select the gdb item in the Debug View

enter image description here

  1. The Console view will now display the interface to GDB:

enter image description here

  1. Type commands to GDB, e.g. print i + j or p i - j (p is short for print):

enter image description here

Other Hints when using the Console

  • You can "pin" the console so that it stays the selected console top with this button on the toolbar: enter image description here

  • You can switch console with this drop-down:

enter image description here

  • You can open a second console, e.g. one for GDB interaction and one for output of your program with this button:

enter image description here

like image 184
Jonah Graham Avatar answered Aug 20 '26 04:08

Jonah Graham