Setting up Netbeans/Eclipse for Linux Kernel Development

11,343

Solution 1

Eclipse seems to be pretty popular for Linux kernel development:

Solution 2

I previously wrote up an answer. Now I come up with all the details of the solution and would like to share it. Unfortunately stackoverflow does not allow me to edit the previous answer. So I write it up in this new answer.

It involves a few steps.


[1] The first step is to modify linux scripts to leave dep files in. By default after using them in the build, those dep files are removed. Those dep files contains exact dependency information about which other files a C file depends. We need them to create a list of all the files involved in a build. Thus, modify files under linux-x.y.z/scripts to make them not to remove the dep files like this:

linux-3.1.2/scripts

Kbuild.include: echo do_not_rm1 rm -f $(depfile);
Makefile.build: echo do_not_rm2 rm -f $(depfile);

The other steps are detailed in my github code project file https://github.com/minghuascode/Nbk/blob/master/note-nbkparse. Roughly you do:

[2] Configure with your method of configuration, but be sure use "O=" option to build the obj files into a separate directory.

[3] Then use the same "O=" option and "V=1" option to build linux, and save make output into a file.

[4] Run my nbkparse script from the above github project. It does: [4.1] Read in the make log file, and the dep files. Generate a mirroring command. [4.2] Run the mirroring command to hard-link the relevant source files into a separate tree, and generate a make-log file for NetBeans to use.


Now create a NetBeans C project using the mirrored source tree and the generated log file. NetBeans should be able to resolve all the kernel symbols. And you will only see the files involved in the build.

Solution 3

The Eclipse wiki has a page about this: HowTo use the CDT to navigate Linux kernel source

Share:
11,343
red.october
Author by

red.october

Updated on July 05, 2022

Comments

  • red.october
    red.october almost 2 years

    I'm doing some Linux kernel development, and I'm trying to use Netbeans. Despite declared support for Make-based C projects, I cannot create a fully functional Netbeans project. This is despite compiling having Netbeans analyze a kernel binary that was compiled with full debugging information. Problems include:

    • files are wrongly excluded: Some files are incorrectly greyed out in the project, which means Netbeans does not believe they should be included in the project, when in fact they are compiled into the kernel. The main problem is that Netbeans will miss any definitions that exist in these files, such as data structures and functions, but also miss macro definitions.
    • cannot find definitions: Pretty self-explanatory - often times, Netbeans cannot find the definition of something. This is partly a result of the above problem.
    • can't find header files: self-explanatory

    I'm wondering if anyone has had success with setting up Netbeans for Linux kernel development, and if so, what settings they used. Ultimately, I'm looking for Netbeans to be able to either parse the Makefile (preferred) or extract the debug information from the binary (less desirable, since this can significantly slow down compilation), and automatically determine which files are actually compiled and which macros are actually defined. Then, based on this, I would like to be able to find the definitions of any data structure, variable, function, etc. and have complete auto-completion.

    Let me preface this question with some points:

    • I'm not interested in solutions involving Vim/Emacs. I know some people like them, but I'm not one of them.
    • As the title suggest, I would be also happy to know how to set-up Eclipse to do what I need
    • While I would prefer perfect coverage, something that only misses one in a million definitions is obviously fine

    SO's useful "Related Questions" feature has informed me that the following question is related: https://stackoverflow.com/questions/149321/what-ide-would-be-good-for-linux-kernel-driver-development. Upon reading it, the question is more of a comparison between IDE's, whereas I'm looking for how to set-up a particular IDE. Even so, the user Wade Mealing seems to have some expertise in working with Eclipse on this kind of development, so I would certainly appreciate his (and of course all of your) answers.

    Cheers

  • red.october
    red.october almost 14 years
    Thanks for your advice. I've tried something similar with make-log files, but in the end it still exhibited the same problems. And using those CFLAGS you specified would be a PITA because it increases the compile-time by a lot.
  • Minghua
    Minghua almost 14 years
    It should work based on past experience. Will give it a try. Though some symbols are sometimes missing and appear again that is purely a Netbeans internal issue.
  • minghua
    minghua about 12 years
    Here I created a script to generate the make-log file suitable for NetBeans to read and interpret from the make output and the dep files. Yes you need to modify linux makefiles to leave the dep files in. It works very well for me (almost no missing symbols). The steps are a bit lengthy but once you've done it once everything will be straightforward. Wish this help.