Linux 如何调试 C 程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2590931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug a C program
提问by ambika
I am using Linux
, GCC
and C
.
我正在使用Linux
,GCC
和C
.
I have a make file.
我有一个制作文件。
I want to debugmy module. I don't want to debug a single file, I want to debug the whole module.
我想调试我的模块。我不想调试单个文件,我想调试整个模块。
How can I do it?
我该怎么做?
回答by ambika
回答by Mawg says reinstate Monica
I guess that you are building from the command line.
我猜你是从命令行构建的。
You might want to consider an IDE (Integrated Development Environment), such as KDevelop or Eclipse, etc (hint - Eclipse ... ECLPISE ... E C L I PS E).
您可能需要考虑使用 IDE(集成开发环境),例如 KDevelop 或 Eclipse 等(提示 - Eclipse ... ECLPISE ... ECLI PS E)。
Use an IDE to edit your code, refactor your code, examine your code - class tree, click a variable, class or function to jump to declaration, etc, etc
使用 IDE 编辑代码、重构代码、检查代码 - 类树、单击变量、类或函数以跳转到声明等
And - of course - to debug:
而且 - 当然 - 调试:
- run your code in the IDE
- set breakpoints to stop at particular lines
- or just step through, a line at a time
- examine the call stack to see how you go there
- examine the current values of variables, to understand your problem
- change the values of those variables and run to see what happens
- and more, more, more
- 在 IDE 中运行您的代码
- 设置断点以在特定行停止
- 或者只是一步一步,一次一行
- 检查调用堆栈,看看你是如何去那里的
- 检查变量的当前值,以了解您的问题
- 更改这些变量的值并运行以查看会发生什么
- 还有更多,更多,更多
p.s as wasatz mentioned- DDDis great - for visualizing the contents of arrays/matrices, and - imo - especially if you have linked lists
ps 正如 wasatz 提到的 - DDD很棒 - 用于可视化数组/矩阵的内容,以及 - imo - 特别是如果你有链表