<tfoot id='oAwYf'></tfoot>

    <legend id='oAwYf'><style id='oAwYf'><dir id='oAwYf'><q id='oAwYf'></q></dir></style></legend>
  1. <small id='oAwYf'></small><noframes id='oAwYf'>

  2. <i id='oAwYf'><tr id='oAwYf'><dt id='oAwYf'><q id='oAwYf'><span id='oAwYf'><b id='oAwYf'><form id='oAwYf'><ins id='oAwYf'></ins><ul id='oAwYf'></ul><sub id='oAwYf'></sub></form><legend id='oAwYf'></legend><bdo id='oAwYf'><pre id='oAwYf'><center id='oAwYf'></center></pre></bdo></b><th id='oAwYf'></th></span></q></dt></tr></i><div id='oAwYf'><tfoot id='oAwYf'></tfoot><dl id='oAwYf'><fieldset id='oAwYf'></fieldset></dl></div>

        <bdo id='oAwYf'></bdo><ul id='oAwYf'></ul>

      如何使用 MinGW gdb 调试器在 Windows 中调试 C++ 程序

      时间:2023-05-23
        <tfoot id='6AUPe'></tfoot>

            <legend id='6AUPe'><style id='6AUPe'><dir id='6AUPe'><q id='6AUPe'></q></dir></style></legend>
              <i id='6AUPe'><tr id='6AUPe'><dt id='6AUPe'><q id='6AUPe'><span id='6AUPe'><b id='6AUPe'><form id='6AUPe'><ins id='6AUPe'></ins><ul id='6AUPe'></ul><sub id='6AUPe'></sub></form><legend id='6AUPe'></legend><bdo id='6AUPe'><pre id='6AUPe'><center id='6AUPe'></center></pre></bdo></b><th id='6AUPe'></th></span></q></dt></tr></i><div id='6AUPe'><tfoot id='6AUPe'></tfoot><dl id='6AUPe'><fieldset id='6AUPe'></fieldset></dl></div>
                <bdo id='6AUPe'></bdo><ul id='6AUPe'></ul>

                <small id='6AUPe'></small><noframes id='6AUPe'>

                  <tbody id='6AUPe'></tbody>

                本文介绍了如何使用 MinGW gdb 调试器在 Windows 中调试 C++ 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我已经查找了有关此的文档,但一无所获.我安装了 MinGW,效果很好.我只是不知道如何使用调试器.

                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.

                给定一些简单的代码,比如在一个名为mycode.cpp"的文件中:

                Given some simple code, say in a file called "mycode.cpp":

                int main()
                {
                    int temp = 0;
                
                    for (int i = 0; i < 5; ++i)
                        temp += i;
                
                    return 0;
                }
                

                ...我将如何调试它.我在 Windows 中使用 MinGW 和 GDB 调试代码的命令是什么?我可以像在 Visual Studio 中一样通过命令行单步执行代码吗?如果是这样,我使用什么命令来做到这一点?

                ...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?

                是否有使用 GDB 的教程?我找不到任何东西,但如果有人能指导我找到一个,那也太棒了.我厌倦了编写大量 std::cout 语句来调试复杂代码.

                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.

                推荐答案

                第一步是使用 -g 编译您的程序,以在可执行文件中包含调试信息:

                The first step is to compile your program with -g to include debugging information within the executable:

                g++ -g -o myprog.exe mycode.cpp
                

                然后程序就可以加载到gdb中:

                Then the program can be loaded into gdb:

                gdb myprog.exe
                

                一些让您入门的命令:

                • break main 将在调用 main 时导致调试器中断.您还可以使用 break FILENAME:LINENO 中断代码行.例如,只要程序到达 mycode.cpp 的第 4 行,break mycode.cpp:4 就会中断执行.
                • start 启动程序.在您的情况下,您需要在启动程序之前设置断点,因为它会快速退出.
                • break main will cause the debugger to break when main is called. You can also break on lines of code with break FILENAME:LINENO. For example, break mycode.cpp:4 breaks execution whenever the program reaches line 4 of mycode.cpp.
                • start starts the program. In your case, you need to set breakpoints before starting the program because it exits quickly.

                在断点处:

                • 打印 VARNAME.这就是您打印变量值的方式,无论是局部的、静态的还是全局的.例如,在 for 循环中,您可以键入 print temp 以打印出 temp 变量的值.
                • step 这相当于步入".
                • nextadv +1 前进到下一行(如step over").您还可以使用例如 adv mycode.cpp:8 前进到特定文件的特定行.
                • bt 打印回溯.这本质上是一个堆栈跟踪.
                • continue 与可视化调试器的继续"操作完全一样.它使程序继续执行,直到下一个断点或程序退出.
                • print VARNAME. That's how you print values of variables, whether local, static, or global. For example, at the for loop, you can type print temp to print out the value of the temp variable.
                • step This is equivalent to "step into".
                • next or adv +1 Advance 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.
                • bt Print a backtrace. This is a stack trace, essentially.
                • continue Exactly like a "continue" operation of a visual debugger. It causes the program execution to continue until the next break point or the program exits.

                最好阅读GDB 用户手册.

                这篇关于如何使用 MinGW gdb 调试器在 Windows 中调试 C++ 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何传递参数并将标准输入从文件重定向到在 下一篇:如何在 C++ 中跟踪内存分配(尤其是新建/删除)

                相关文章

                最新文章

                  <tfoot id='SBLGY'></tfoot>

                1. <i id='SBLGY'><tr id='SBLGY'><dt id='SBLGY'><q id='SBLGY'><span id='SBLGY'><b id='SBLGY'><form id='SBLGY'><ins id='SBLGY'></ins><ul id='SBLGY'></ul><sub id='SBLGY'></sub></form><legend id='SBLGY'></legend><bdo id='SBLGY'><pre id='SBLGY'><center id='SBLGY'></center></pre></bdo></b><th id='SBLGY'></th></span></q></dt></tr></i><div id='SBLGY'><tfoot id='SBLGY'></tfoot><dl id='SBLGY'><fieldset id='SBLGY'></fieldset></dl></div>

                2. <small id='SBLGY'></small><noframes id='SBLGY'>

                  <legend id='SBLGY'><style id='SBLGY'><dir id='SBLGY'><q id='SBLGY'></q></dir></style></legend>

                      <bdo id='SBLGY'></bdo><ul id='SBLGY'></ul>