I have looked for documentation on this and found nothing. I have MinGW installed and it works great. I just don't know how to use the debugger.
Given some simple code, say in a file called "mycode.cpp":
开发者_StackOverflow社区int main()
{
    int temp = 0;
    for (int i = 0; i < 5; ++i)
        temp += i;
    return 0;
}
...how would I debug this. What are the commands that I use to debug code with MinGW and GDB in windows? Can I step through the code via the command line like in Visual Studio? If so what commands do I use to do that?
Are there any tutorials for using GDB out there? I couldn't find any, but if anyone could direct me to one that would be great too. I'm tired of writing tons of std::cout statements to debug complex code.
The first step is to compile your program with -g to include debugging information within the executable:
g++ -g -o myprog.exe mycode.cpp
Then the program can be loaded into gdb:
gdb myprog.exe
A few commands to get you started:
- break mainwill cause the debugger to break when- mainis called. You can also break on lines of code with- break FILENAME:LINENO. For example,- break mycode.cpp:4breaks execution whenever the program reaches line 4 of- mycode.cpp.
- startstarts the program. In your case, you need to set breakpoints before starting the program because it exits quickly.
At a breakpoint:
- print VARNAME. That's how you print values of variables, whether local, static, or global. For example, at the- forloop, you can type- print tempto print out the value of the- tempvariable.
- stepThis is equivalent to "step into".
- nextor- adv +1Advance to the next line (like "step over"). You can also advance to a specific line of a specific file with, for example,- adv mycode.cpp:8.
- btPrint a backtrace. This is a stack trace, essentially.
- continueExactly like a "continue" operation of a visual debugger. It causes the program execution to continue until the next break point or the program exits.
The best thing to read is the GDB users' manual.
There are a few gdb guis for windows in this question windows version of the GDB frontend DDD
Although DDD hasn't been ported
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论