Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I enter commands to a gdb prompt while debugging with Eclipse CDT?

I'm using Eclipse (Helios SR1) CDT for my C++ development. Eclipse interfaces with GDB for debugging, but I can't figure out how to manually enter commands to GDB while debugging through the Eclipse interface. For example, it would be nice to be able to enter p myVar instead of having to click and scroll through the local variables window.

Note: The only reason I'd like to use the Eclipse interface for debugging is because I like how it shows the code that is being stepped through. So if anyone has an alternative to suggest that would allow me to view the code that's being stepped through, please suggest! (I've used DDD, but I don't especially like it.)

like image 431
synaptik Avatar asked Apr 16 '12 16:04

synaptik


People also ask

How do I run a command in GDB?

Use the run command to start your program under GDB. You must first specify the program name (except on VxWorks) with an argument to GDB (see section Getting In and Out of GDB), or by using the file or exec-file command (see section Commands to specify files).

What is the command to debug using GDB?

l command: Use gdb command l or list to print the source code in the debug mode. Use l line-number to view a specific line number (or) l function to view a specific function. bt: backtrack – Print backtrace of all stack frames, or innermost COUNT frames.

How do I use GDB on Windows?

Starting GDBIn the windows command console, type arm-none-eabi-gdb and press Enter. You can do this from any directory. If you're unsure how to open the Windows command console, see Running OpenOCD on Windows. You can also run GDB directly from "Run" in the Start menu.


2 Answers

It is actually very simple.

Start debugging (eclipse will switch to Debug Perspective). Then make sure Console View is shown. If it's not show it (Window->Show view...). In that view you will find "Display selected console" icon. Select down arrow next to it an select console named "gdb" (not gdb traces!).

What you enter in this console is forwarded directly to gdb (you can use all gdb commands).

like image 153
dbrank0 Avatar answered Oct 12 '22 22:10

dbrank0


If you are not debugging under Windows, you could try the gdb TUI. It's a little awkward to get used to, and is sometimes buggy, but in general it works fairly well. You can see the code being stepped through in one window while still being able to enter commands.

Assuming your version of gdb was built with the --enable-tui configure option, simply fire up gdb and press C-x C-a to enter the TUI. Then, to make sure you can see the code and command windows, press C-x 2 (for two-window layout) It's been a while since I've had to use the TUI, but it should work for your requirements.

like image 21
multipleinterfaces Avatar answered Oct 12 '22 23:10

multipleinterfaces