Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Netbeans/Eclipse for Linux Kernel Development

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

like image 633
red.october Avatar asked Sep 30 '09 21:09

red.october


2 Answers

Eclipse seems to be pretty popular for Linux kernel development:

  • http://cdtdoug.blogspot.com/2008/12/linux-kernel-debugging-with-cdt.html
  • http://jakob.engbloms.se/archives/338
  • http://revver.com/video/606464/debugging-the-linux-kernel-using-eclipsecdt-and-qemu/
like image 83
JesperE Avatar answered Sep 30 '22 12:09

JesperE


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.

like image 30
minghua Avatar answered Sep 30 '22 12:09

minghua