Linux 如何让Eclipse识别KBUILD_MODNAME?

Linux 如何让Eclipse识别KBUILD_MODNAME?,linux,eclipse,linux-kernel,linux-device-driver,Linux,Eclipse,Linux Kernel,Linux Device Driver,我随后将Eclipse配置为Linux内核编辑/导航的IDE。它通常可以工作,但Eclipse无法理解宏KBUILD\u MODNAME:我使用宏pci\u寄存器\u驱动程序,该驱动程序定义为: #define pci_register_driver(driver) \ __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) 在中包括/linux/pci.h 如何让Eclipse知道这个令牌?[下面的所有内容都基于内

我随后将Eclipse配置为Linux内核编辑/导航的IDE。它通常可以工作,但Eclipse无法理解宏
KBUILD\u MODNAME
:我使用宏
pci\u寄存器\u驱动程序
,该驱动程序定义为:

#define pci_register_driver(driver)     \
    __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
中包括/linux/pci.h


如何让Eclipse知道这个令牌?

[下面的所有内容都基于内核4.15.0]

通过查看内核源的“脚本”文件夹,可以理解
KBUILD\u 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.com的内容包括:

# filename of target with directory and extension stripped
basetarget = $(basename $(notdir $@))
from: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\u MODNAME
,以便在Makefile中定义模块名称时将其设置为模块名称。如果您在一个项目中构建了多个模块,那么事情就有点棘手了

解决这个问题后,您会注意到Eclipse indexer仍然会向您发出警告(我假设您正在使用“对象和符号”中定义的
module
构建外部模块)

  • 问题描述:未使用的静态函数“\uuuExitTest”
  • 问题描述:未使用的静态函数“\uuu inittest”
  • 问题描述:函数“cleanup_module”的未使用声明
  • 问题描述:函数“init_module”的未使用声明
这些是内核模块加载/卸载系统使用的符号,因此Eclipse对它们一无所知。不幸的是,到目前为止(Eclipse 4.8.0和CDT 9.5.2),我无法配置代码分析以从警告中排除这些符号,因此必须抑制警告,将以下内容放在定义模块初始化的代码行中:

// @suppress("Unused static function") @suppress("Unused function declaration")

据我所知,他们提供了唯一的可能性,你浏览现有的东西。因此,您可能必须在索引之前使用新添加的模块构建内核,如上述指南中所建议的那样。您可以为Eclipse索引器定义宏,以便准确定义
KBUILD\u MODNAME
应该是什么。它将作为一个define传递给Eclipse索引器——基本上是这样的:
-DKBUILD\u MODNAME=您想要的任何内容
。有关如何操作的说明,请参见我的详细答案:。