我按照本指南配置Eclipse编辑/导航的IDE。它通常可以工作,但是Eclipse无法理解宏KBUILD_MODNAME:我使用宏pci_register_driver,它被定义为:
#define pci_register_driver(driver) \
__pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)在include/linux/pci.h中。
我如何使Eclipse知道这个令牌?
发布于 2018-08-01 07:02:03
下面的所有内容都是基于内核4.15.0
可以通过查看内核源代码的“脚本”文件夹来理解KBUILD_MODNAME的形成:
来自Makefile.lib:
# These flags are needed for modversions and compiling, so we define them here
# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
# end up in (or would, if it gets compiled in)
# Note: Files that end up in two or more modules are compiled without the
# KBUILD_MODNAME definition. The reason is that any made-up name would
# differ in different configs.
name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
modname_flags = $(if $(filter 1,$(words $(modname))),\
-DKBUILD_MODNAME=$(call name-fix,$(modname)))来自Makefile.build:
# Default for not multi-part modules
modname = $(basetarget)
$(multi-objs-m) : modname = $(modname-multi)
$(multi-objs-m:.o=.i) : modname = $(modname-multi)
$(multi-objs-m:.o=.s) : modname = $(modname-multi)
$(multi-objs-m:.o=.lst) : modname = $(modname-multi)
$(multi-objs-y) : modname = $(modname-multi)
$(multi-objs-y:.o=.i) : modname = $(modname-multi)
$(multi-objs-y:.o=.s) : modname = $(modname-multi)
$(multi-objs-y:.o=.lst) : modname = $(modname-multi)来自Kbuild.include:
# filename of target with directory and extension stripped
basetarget = $(basename $(notdir $@))来自: Makefile.lib
# Finds the multi-part object the current object will be linked into
modname-multi = $(sort $(foreach m,$(multi-used),\
$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))有了所有这些,您基本上可以在“对象和符号”中定义KBUILD_MODNAME,并将其设置为模块名称,就像在生成文件中定义它一样。如果您在一个项目中构建了多个模块,那么事情就会更加棘手.
在解决了这个问题之后,您会注意到Eclipse仍然会向您发出警告(我假设您正在构建外部模块,其中MODULE定义在“对象和符号”中)
这些符号是内核模块加载/卸载系统使用的符号,因此Eclipse对它们一无所知。不幸的是,截至今天(Eclipse 4.8.0和CDT 9.5.2),我无法配置代码分析以将这些符号排除在警告之外,因此必须禁止向定义模块初始化的代码行中放置警告:
// @suppress("Unused static function") @suppress("Unused function declaration")https://stackoverflow.com/questions/28697678
复制相似问题