forcing Eclipse to work with Linux kernel (indexing kernel source)

forcing Eclipse to work with Linux kernel (indexing kernel source)

When working with linux kernel, powerful editor with symbols referencing is a must. As I am an Eclipse fan, I spent a lot of time trying to force it to cooperate with kernel. After some struggling I had found a great tutorial, that helped me a lot: http://simonkagstrom.livejournal.com/31079.html. Simon Kågström did a great job there (especially with the perl script), however there are few things I would do other way, e.g. I would not setup a project in kernel's directory, as it makes it even more messy.
So here is "my way" of making Eclipse and kernel come together.

When Eclipse tries to run the indexer on linux kernel it will most likely run out of memory. To let it use some more memory, start it with -vmargs -Xmx650M paramters (256MB is default, 650MB proved to be enough), and continue with this tutorial.

    1. Create a C Project, using File>>New>>C Project. Choose appropriate project name and set Project type as Makefile project. Locate your project in folder of your choice- it does not have to be kernel directory. Hit Next.
    2. Tick defualt, and go to Advanced settings... of your new project.
    3. In new window goto C/C++ General>>Indexer, and turn indexing off (just for now, before we'll do some tweaking). Confirm with OK.
    4. It is time to add source files to your project. Tap right mouse button on project's name in C/C++ Projects tree, and select New>>Folder. We'll create a link to kernel source code now (which I assume, already exists on your filesystem). To do it, click >>Advanced, and tick Link to folder in the file system. Browse to your kernel directory, and click Finish. This way Eclipse project with it's settings is stored in one place, and pure source code (with git repository, probably) in another.
    5. Once your source code is here, it's time to do some cleaning. Browse your source code tree to /arch/ and select all architectures you won't use (I selected all but ARM). Tap RMB on folders you selected, and choose Exclude from build..." from context menu. Tick configs you'll use (Default in our case), and press OK. You'll notice that all that's left in treeview is your architecture's directory. Fear not- folders that are gone, are not deleted, but just filtered out.
      Repeat this step for /arch/arm/ folder either, excluding all mach-{foo} folders that don't fit your architecture (I had left only mach-omap2 folder).
    6. Hit RMB on your project name, choose Properties, go to C/C++ General>>Paths and symbols>>Symbols, and add __KERNEL__ symbol with value set to 1, by clicking Add... Remember to check Add to all alnguages, to make this symbol visible in Assembly/C/C++ languages.

      This step will not only make __KERNEL__ symbol symbol visible in all languages. When this symbol is added there is one extremely important thing happening under the hood of .cproject file (configuration file of your project) - three sections of symbols are created, and will be filled in during next step.
    7. Now comes the tricky part. To make Eclipse be really smart, and to let it know defines from autoconf.h (which are altered during make menuconfig), one has to type those defines into Eclipse config manually, or run a script from the attachments section (once again- thanks to Simon Kågström). It takes two arguments, where first one is path to autoconf.h file in kernel directory, and the second one is path to your project's directory. Go python, go!
      nazgee @nazgee -desktop :~ $ python autoconf -to -eclipse .py ~ /linux -omap - 2.6 / include /linux /autoconf .h ~ /eclipse_ws /oe_kernel /

      NOTE: You'll have to repeat this step each time you change something in kernel config (e.g. by make menuconfig), so it would be reasonable to create a script, that takes no params, and calls abovementioned .py script with hardcoded parameters (typing in those paths might be annoying).

    8. Time to check if everything went well in previous point. Once again, press RMB on your project name, choose Properties, go to C/C++ General>>Paths and symbols>>Symbols, and check if some kernel CONFIG_{foo} symbols appeared in Assembly/C/C++ languages.
      If it's there - you are half way home, if it's not... Refresh your project, relaunch Eclipse, goto previous point and try again. Maybe try to check .cproject file in your project's directory for entries like this:
      <listOptionValue builtIn = "false" value = "AUTOCONF_INCLUDED=1" /> <!--GENERATED -->
      <listOptionValue builtIn = "false" value = "CONFIG_USB_MUSB_HDRC=1" /> <!--GENERATED -->
      <listOptionValue builtIn = "false" value = "CONFIG_VIDEO_V4L1_COMPAT=1_COMPAT 1" /> <!--GENERATED -->
      <listOptionValue builtIn = "false" value = "CONFIG_UBIFS_FS_ZLIB=1" /> <!--GENERATED -->
      <listOptionValue builtIn = "false" value = "CONFIG_OMAP_MCBSP=1" /> <!--GENERATED -->

      Eventually, it should work, so don't give up. (AFAIK it works from the first try, most of the times)
    9. Go to C/C++ General>>Paths and symbols>>Inludes tab and hit Add. Tick Add to all alnguages, press workspace and add /include/ folder. When you're done, add your arch/{architecture}/mach-{foo} directory either.
    10. Finally, goto C/C++ General>>Indexer, and turn back indexing on. Use Fast C/C++ Indexer, with no files indexed up-front. Press OK.

      It's time for a coffee break now. Be patient.

你可能感兴趣的:(eclipse)