How to use GDB to debug a big project?

眉间皱痕 提交于 2019-12-11 00:22:12

问题


Now I have a c language project which include three directories /bin, /inc and /src. All of header files (.h) are included in /inc and all of source(.c) files are stored in /src, i.e. a.c, b.c, c.c..., the final generated executable file will locate in /bin.

after compling with makefile, all of obj files will be generated in /src/obj like a.o, b.o, c.o, d....! Moreover an final.exe executable file will be generated in the /bin directory.

Now if I want to debug it with GDB, how can I do it???

To debug those obj files in /src/obj? or somewhat else?

Many thanks for the kind help!


回答1:


You can either debug an application by starting it with GDB

%> gdb <your_executable>

or what is usually easier is to start your application and then attach the debugger to the process using the PID.

%> gdb -p <pid>

For command line options, just type gdb -h and while running inside of gdb help is always available by typing "help" on the gdb command line.

Here is a quick cheat sheet and a tutorial site on some common commands.

As Arkaitz mentioned, be sure to compile your code so that it has the necessary debug information included in the executable.

If debugging from the command line is a bit daunting, there are some UIs available that use GDB. I do a lot of my debugging in Eclipse using gdb.

Once you get started down the gdb path, I'm sure you'll have more questions and I encourage you to ask those more specific questions on SO.

Good luck.




回答2:


What is the problem with gdb bin/binary.exe? If you compiled correctly and placed -g -ggdb in the compile flags GDB should have enough info to display inlined code



来源:https://stackoverflow.com/questions/1715053/how-to-use-gdb-to-debug-a-big-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!