简体   繁体   中英

How to debug a C program

I am using Linux , GCC and C .

I have a make file.

I want to debug my module. I don't want to debug a single file, I want to debug the whole module.

How can I do it?

Compile your code with the -g flag, and then use the gdb debugger. Documentation for gdb is here , but in essence:

gcc -g -o prog myfile.c another.c

and then:

gdb prog

If you want a user-friendly GUI for gdb, take a look at DDD or Insight .

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

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

ps as wasatz mentioned- DDD is great - for visualizing the contents of arrays/matrices, and - imo - especially if you have linked lists

You can use gdb-based simple and useful GUI "Nemiver". It can debug your whole module comprising many source files.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM