简体   繁体   English

如何调试使用Makefile编译的C代码

[英]How to Debug a C code that is compiled using a Makefile

I am asked to debug a C code containing a number of .c files and is complied using a Makefile on a Redhat Linux system. 我被要求调试包含许多.c文件的C代码,并在Redhat Linux系统上使用Makefile进行编译。 I want to debug that whole code. 我想调试整个代码。 How to go about it? 怎么做呢? What changes do i need to make in the Makefile? 我需要在Makefile中进行哪些更改?

I am using gcc as the compiler. 我正在使用gcc作为编译器。

If you're using GCC as compiler add to the CFLAGS variable the -g option. 如果您使用GCC作为编译器,则将-g选项添加到CFLAGS变量中。 Then you'll be able to debug the resulting executable using the gdb command. 然后,您可以使用gdb命令调试生成的可执行文件。

First you need to add the flag "-g" during compilation(make this change in the makefile.if already present then no need). 首先,您需要在编译期间添加标志“ -g”(在makefile中进行此更改。如果已经存在,则不需要)。 this will open up the symbols for debugging the code. 这将打开用于调试代码的符号。

use the debugging tools available like gdb, dbx, mdb which ever is available in your system. 使用系统中可用的调试工具,例如gdb,dbx,mdb。

many resources are available for debugging. 许多资源可用于调试。 one of them is here 其中之一在这里

在makefile中添加-g选项,以便将来调用gdb调试器。在gdb上进行调试的方式类似于:gdb yourprogram,然后您将被重定向到另一个接口。键入“ run yourarguments”以开始调试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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