Debug c++ in cmd windows 10
I've never used a debugger and the time has come to give them a try. MinGW appears to come with GDB which I've been trying to use. Supposdly running gdb from the command line and typing
Starting program: C:\MinGW\bin\myprog.exe MyProg.exe [New Thread 1828.0xd8c] Error opening file. [Inferior 1 (process 1828) exited with code 02]
How to proceed or what's an easier way?
In particular I'm trying to flush out undefined behavior.
asked Oct 4, 2013 at 8:36
14.2k35 gold badges107 silver badges188 bronze badges
Since your program terminates, you'll need to set a breakpoint to see anything. Try
answered Oct 4, 2013 at 8:48
luser droogluser droog
18.7k3 gold badges51 silver badges102 bronze badges
Well, the easiest way would be to use an IDE, actually. You might want to give code::blocks a try - very easy to use, configures everything for you on installation (just make sure to pick a compiler - don't worry, it'll prompt you) and there, you're all set and ready to go. As it's multi-platform, it doesn't really lock you into windows either, and gives you very powerful (and, I guess more importantly, convenient) possibilities of graphical debugging.
answered Oct 4, 2013 at 8:39
6455 silver badges22 bronze badges
pass the binary with gdb
then set breakpoint to main
Then run your program in gdb
then break point hits use 'n' or 'next' to step to different lines
Use 's' for stepping into function and 'p' printing var value
answered Oct 4, 2013 at 9:08
Sohil OmerSohil Omer
1,1717 silver badges14 bronze badges
I would suggest , as a beginner start off with Visual Studio. It has a very good and easy to use debugger. Just create a break point in the line from which you want to start debugging (click on the left bar beside the line or right click and create a break point). Once your break points are set you can just simply run the program in debug mode and the execution of the program will halt in the point where the break was created.
At this point you should be able to view all valuable information about the execution of the program. You can use F10 to continue the execution step or F11 to step inside the execution tree.
The debugger as many other advanced features like break on condition , hit count etc but you can start off with it's basic functionality.
answered Oct 4, 2013 at 10:33
8332 gold badges18 silver badges41 bronze badges
If I compiled a program like this:
I could then debug the executable
Since you're having issues
answered Sep 29, 2021 at 15:38
How to debug in cmd Windows 10?
Debug syntax After debug starts, type "?" to display a list of debugging commands. To get out of debugging mode, you need to type "Q" and press Enter . To execute the debug routine, you need to type "G" and press Enter .
How to debug through cmd?
To activate the debugger at the command prompt.
Choose Debug Next. The debugger is now active and is waiting to attach to a session..
Select a session, and then choose Debug. The debugger is now active and attached to the selected session..
How to debug C code in Windows?
Debugging C programs.
To compile the program, use: gcc -g -Wall *. c . ... .
Now enter gdb with the command gdb a. out ..
At the gdb prompt, enter run . ... .
You can enter where , and gdb will show the current stack of subroutine calls, and the line number for each. ... .
Type quit to exit gdb and return to the shell prompt..
How to debug in terminal C?
How to Debug C Program using gdb in 6 Simple Steps.
Write a sample C program with errors for debugging purpose. ... .
Compile the C program with debugging option -g. ... .
Launch gdb. ... .
Set up a break point inside C program. ... .
Execute the C program in gdb debugger. ... .
Printing the variable values inside gdb debugger..