在 Linux 2.6 驱动程序模块 makefile 中创建调试目标
我试图能够在命令行执行“make debug”,它将使用 -DDEBUG_OUTPUT 定义构建我的驱动程序模块,这将导致代码的某些部分被编译。
在 2.4 内核 makefile 中,这很漂亮简单的。我只是创建一个 debug: 目标,并在该目标的 cc 编译命令参数中包含“-DDEBUG_OUTPUT”。简单的。
不幸的是(对我来说),2.6 完全改变了模块的编译方式,我似乎只能找到微不足道的“全部”和“干净”示例,这些示例没有显示在编译时添加自定义定义。
我尝试了这个:
debug:
make -C $(KERNEL_DIR) SUBDIRS='pwd' -DDEBUG_OUTPUT modules
并收到了来自 make 的投诉。
我也尝试过:
.PHONY: debug
debug:
make -C $(KERNEL_DIR) SUBDIRS='pwd' EXTRA_CFLAGS="$(EXTRA_CFLAGS) -DDEBUG_OUTPUT" modules
但它没有看到 EXTRA_CFLAGS 包含的内容。我可以从命令行输出中看到它确实将 -D 正确附加到现有的 EXTRA_CFLAGS 上,其中包括用于包含目录的 -I 。但是,驱动程序文件现在无法编译,因为它找不到包含目录...所以不知何故它看不到 EXTRA_CFLAGS 包含的内容。
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.
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.
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.
I tried this:
debug:
make -C $(KERNEL_DIR) SUBDIRS='pwd' -DDEBUG_OUTPUT modules
and got a complaint from make.
I've also tried:
.PHONY: debug
debug:
make -C $(KERNEL_DIR) SUBDIRS='pwd' EXTRA_CFLAGS="$(EXTRA_CFLAGS) -DDEBUG_OUTPUT" modules
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“-D”选项并不意味着要传递给 make:它是一个 C 预处理器 (cpp) 选项。
要为您的构建定义 DEBUG_OUTPUT,您必须将以下行添加到您的 Kbuild 文件中:
之后您可以像往常一样调用:
编辑:如果您不想编辑 Kbuild 文件,您可以有一个这样的调试目标:
编辑#2:
A "-D" option is not meant to be passed to make: it is a C preprocesseor (cpp) option.
To define DEBUG_OUTPUT for your build you have to add the following line to your Kbuild file:
Afterwards you can call, as usual:
EDIT: If you don't want to edit the Kbuild file, you can have a debug target like this:
EDIT#2: