views:

1437

answers:

3

Hi:

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: http://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

A: 

I have been doing some embedded linux development. Including kernel module development and have imported the entire linux kernel source code into Eclipse, as a separate project. I have been building the kernel itself outside of Eclipse(so far), but I don't any reason why I shouldn't be able to set up the build environment within Eclipse to build the kernel. For my projects, as long as I setup the PATH properties to point to the appropriate linux source include directories, it seems to be pretty good about name completion for struct fields, etc.

I can't really comment, on if it is picking up the correct defines and not greying out the correspond sections, as I haven't really paid to much attention to the files within the kernel itself.(so far)

I was also wondering about using Netbeans as a linux 'C' IDE, as I do prefer Netbean's for Java GUI development.

simon
A: 

I think this would work (done each step for various projects):

[1] Modify kernel build scripts to leave .d files. By default they are removed. [2] Log the build process to a file. [3] Write a script to parse the build log. [3.1] From the build log, you know every .c files. [3.2] From the .c file, you know which is the corresponding .d file. [3.3] Look into .d files to find out all the included .h files. [3.4] Form a complete .c and .h file list. [4] Now create a new dir, and use "ln -s" or "ln" to pick files of interest.

Now, create a Netbeans project for existing source code in the [4]. Configure code assistance to use make-log file. You should see exactly the effective source code as when you build it at [2].

Some explanations to the above steps:

At [2], do a real build so the log file contains the exact files and flags of interest. Later netbeans will be able to use the exact flags to parse.

At [4], pick only the files you want to see. Incorporating the whole kernel tree into netbeans will be unpractical.

There is a trick to parsing .d files: Many of the depended items are not real paths to a .h file, they are a modified entry for part of the linux config sections in the auto config file. You may need to reverse the modification to figure out which is the real header file.

Actually there is a topic on netbeans site. This is the discussion url: http://forums.netbeans.org/ntopic3075.html . And there is a wiki page linked from the discussion: wiki.netbeans.org/CNDLinuxKernel . Basically it asks you to prefix make with CFLAGS="-g3 -gdwarf-2" .

Minghua
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.
red.october
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