【参考其他文章修改】DevC++使用调试的方法(可以不是项目,单个代码亲测可行)



1. 参考声明:

本文参考了以下文章:
主:https://blog.****.net/qq_38737992/article/details/77621299
https://blog.****.net/qq_43347097/article/details/97000762
https://blog.****.net/Liukairui/article/details/80916449
https://blog.****.net/zhangsmlyl/article/details/78941158

2. 主段落(转载)

使用以下方法可以对单个cpp代码调试。

     你遇到的问题是不是这样:

     【参考其他文章修改】DevC++使用调试的方法(可以不是项目,单个代码亲测可行)

    请 看下面的解决方法: 

        第一步:

                  【参考其他文章修改】DevC++使用调试的方法(可以不是项目,单个代码亲测可行)

          把产生调试信息由No 调成 Yes, 如上图。

         路径: 工具 --> 编译选项 --> 代码生成/优化 --> 连接器

       第二步:

                 【参考其他文章修改】DevC++使用调试的方法(可以不是项目,单个代码亲测可行)

      路径: 工具 --> 编译选项 (别忘了点那个对勾)

 

     

        

3. 解释 -g 命令的使用

如果想用调试器执行一个可执行文件, 在用gcc编译时必须加上-g选项:

gcc -o sum sum.c -g

加上-g选项以后,gcc在编译是会做以下额外的操作:

  1. 创建符号表,符号表包含了程序中使用的变量名称的列表。

  2. 关闭所有的优化机制,以便程序执行过程中严格按照原来的C代码进行。


原文链接:https://blog.****.net/zhangsmlyl/article/details/78941158

4. DevC++调试的原版说明

本段原文链接:https://blog.****.net/Liukairui/article/details/80916449


给一个原版说明:
How do I debug using Dev-C++?

First, make sure you are using a project.

Then go to Project Options - Compiler - Linker and set Generate debugging information to “yes”, and make sure you are not using any optimization options (they’re not good for debug mode). Also check the Parameters tab, make sure you don’t have any optimization options (like -O2 or -O3, but -O0 is ok because it means no optimization) or strip option (-s).
After that, do a full rebuild (Ctrl-F11), then set breakpoint(s) where you want the debugger to stop (otherwise it will just run the program). To set a breakpoint on a line, just click on the gutter (the gray band on the left), or press Ctrl-F5.

Now you are ready to launch the debugger, by pressing F8 or clicking the debug button. If everything goes well, the program will start, and then stop at the first breakpoint. Then you can step through the code, entering function calls, by pressing Shift-F7 or the “step into” button, or stepping over the function calls, by pressing F7 or the “next step” button. You can press Ctrl-F7 or the “continue” button to continue execution till the next breakpoint. At any time, you can add or remove breakpoints.

When the program stopped at a breakpoint and you are stepping through the code, you can display the values of various variables in your program by putting your mouse over them, or you can display variables and expressions by pressing F4 or the “add watch” button and typing the expression.

For more information refer to the help included with Dev-C++