在Linux 2.6驱动程序模块Makefile中创建调试目标 [英] Creating a debug target in Linux 2.6 driver module makefile
问题描述
我试图在命令行上执行"make debug",它将使用-DDEBUG_OUTPUT定义构建我的驱动程序模块,这将导致某些代码段被编译.
I'm trying to be able to execute "make debug" at the command line and it will build my driver module with the -DDEBUG_OUTPUT define, which will cause certain sections of code to be compiled in.
在2.4内核makefile中,这非常容易.我只是创建一个debug:目标,并在该目标的cc编译命令参数中包括"-DDEBUG_OUTPUT".容易.
In 2.4 kernel makefiles, this is pretty easy. I just create a debug: target and included "-DDEBUG_OUTPUT" in the cc compilation command arguments for that target. Easy.
不幸的是(对我而言),2.6彻底改变了模块的编译方式,我似乎只能找到琐碎的全部"和干净"示例,这些示例并未显示在编译时添加自定义定义.
Unfortunately (for me), 2.6 completely changed how modules are compiled, and I can ONLY seem to find the trivial "all" and "clean" examples, which don't show adding custom defines at compilation time.
我尝试过:
debug:
make -C $(KERNEL_DIR) SUBDIRS='pwd' -DDEBUG_OUTPUT modules
并收到来自make的投诉.
and got a complaint from make.
我也尝试过:
.PHONY:调试
debug:
make -C $(KERNEL_DIR) SUBDIRS='pwd' EXTRA_CFLAGS="$(EXTRA_CFLAGS) -DDEBUG_OUTPUT" modules
,但看不到EXTRA_CFLAGS包含的内容.从命令行输出中可以看到,它确实将-D正确地附加到了现有EXTRA_CFLAGS上,该EXTRA_CFLAGS包括-I代表include dir.但是,驱动程序文件现在无法编译,因为无法找到包含目录...因此以某种方式无法看到EXTRA_CFLAGS包含的内容.
but it is not seeing what EXTRA_CFLAGS contains. I can see from the command line output that it does correctly append the -D onto the existing EXTRA_CFLAGS, which includes the -I for includes dir. However, the driver file won't compile now because it cannot find the includes dir...so somehow it is not seeing what EXTRA_CFLAGS contains.
推荐答案
-D"选项不是要传递给make的:它是C预处理程序(cpp)选项.
A "-D" option is not meant to be passed to make: it is a C preprocesseor (cpp) option.
要为您的构建定义DEBUG_OUTPUT,您必须将以下行添加到您的Kbuild文件中:
To define DEBUG_OUTPUT for your build you have to add the following line to your Kbuild file:
EXTRA_CFLAGS = -DDEBUG_OUTPUT
此后,您可以像往常一样拨打电话:
Afterwards you can call, as usual:
make -C $(KERNEL_DIR) M=`pwd`
如果您不想编辑Kbuild文件,则可以有一个如下的调试目标:
If you don't want to edit the Kbuild file, you can have a debug target like this:
INCLUDES="-Imy_include_dir1 -Imy_include_dir2"
.PHONY: debug
debug:
$(MAKE) -C $(KDIR) M=`pwd` EXTRA_CFLAGS="$(INCLUDES) -DDEBUG_OUTPUT"
EDIT#2:
MY_CFLAGS=-DFOO -DBAR -Imydir1
all:
$(MAKE) -C $(KDIR) M=`pwd` EXTRA_CFLAGS="$(MY_CFLAGS)"
debug: MY_CFLAGS+=-DDEBUG_OUTPUT
debug:
$(MAKE) -C $(KDIR) M=`pwd` EXTRA_CFLAGS="$(MY_CFLAGS)"
这篇关于在Linux 2.6驱动程序模块Makefile中创建调试目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!