Reputation: 9025
I followed this guide to configure Eclipse as IDE for Linux Kernel editing/navigation. It generally works, but Eclipse fails to understand the macro KBUILD_MODNAME
: I use the macro pci_register_driver
, which is defined as:
#define pci_register_driver(driver) \
__pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
in include/linux/pci.h
.
How do I make Eclipse to know this token?
Upvotes: 3
Views: 993
Reputation: 11
[everything below is based on kernel 4.15.0]
Forming of KBUILD_MODNAME
can be understood by looking into ‘scripts’ folder of kernel sources:
From 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)))
from 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)
from Kbuild.include:
# 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=))))
With all that, you can basically define KBUILD_MODNAME
in ‘Objects and Symbols’ to be set to your module name as you define it in your Makefile. Things are a little bit more tricky if you have multiple modules built in a single project...
After solving that you will notice that Eclipse indexer still throws out warnings at you (I assume you are building external module with MODULE
defined in ‘Objects and Symbols’)
Those are symbols used by kernel module loading/unloading system so Eclipse can know nothing of them. Unfortunately, as of today (Eclipse 4.8.0 with CDT 9.5.2) I cannot configure Code Analysis to exclude those symbols from warnings, so have to suppress warnings putting following to the lines of code where you define module initialization:
// @suppress("Unused static function") @suppress("Unused function declaration")
Upvotes: 1