我跟着this guide将Eclipse配置为用于Linux内核编辑/导航的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知道这个令牌?
答案 0 :(得分:1)
[以下所有内容均基于内核4.15.0]
通过查看内核源代码的“ scripts”文件夹,可以了解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
,就像在Makefile中定义模块名称一样。如果您在一个项目中构建了多个模块,则事情会变得有些棘手...
解决之后,您会注意到Eclipse indexer仍然向您抛出警告(我假设您正在使用“对象和符号”中定义的MODULE
构建外部模块)
这些是内核模块加载/卸载系统使用的符号,因此Eclipse对其一无所知。不幸的是,从今天开始(带有CDT 9.5.2的Eclipse 4.8.0),我无法将代码分析配置为从警告中排除这些符号,因此必须禁止警告,将其放在定义模块初始化的代码行中:
// @suppress("Unused static function") @suppress("Unused function declaration")