Skip to main content
Jump to: navigation, search

Difference between revisions of "HowTo use the CDT to navigate Linux kernel source"

(Updated for Eclipse Juno and CDT 8: Discovery Options has been deprecated in favor of Preprocessor Include Paths.)
Line 3: Line 3:
 
Anyway, as you do these steps, I think you may understand how they assist the indexer to do a good job for the Linux kernel source.
 
Anyway, as you do these steps, I think you may understand how they assist the indexer to do a good job for the Linux kernel source.
  
''Disclaimer: these steps were developed for Eclipse 3.5.1 + CDT 6.0.0.''
+
''Disclaimer: these steps were last updated for Eclipse Juno + CDT 8.0.2, and originally developed for Eclipse 3.5.1 + CDT 6.0.0.''
  
 
#Download and install Eclipse plus the CDT.  
 
#Download and install Eclipse plus the CDT.  
Line 16: Line 16:
 
#Click '''Advanced settings...''' and a Properties dialog will pop up.
 
#Click '''Advanced settings...''' and a Properties dialog will pop up.
 
#Select '''Resource''' on the left, and then in the '''Text file encoding''' section, select '''Other''' and '''ISO-8859-1''' in the box, then click '''Apply'''
 
#Select '''Resource''' on the left, and then in the '''Text file encoding''' section, select '''Other''' and '''ISO-8859-1''' in the box, then click '''Apply'''
#Select '''C/C++ Build''' on the left.
 
#Click on '''Discovery Options'''
 
#At the bottom of the screen where it says '''Compiler invocation arguments''', insert "{{Code|-include include/generated/autoconf.h}}" at the beginning of that line.  Also insert any other compiler options you may need that are not the default, such as "-m64" (Note: for older kernels [pre-2.6.36?], the location of autoconf.h is {{Code|include/linux/autoconf.h}})
 
#You may also need to change the compiler command from gcc to whatever compiler you are using (e.g. you are using a cross compiler).
 
 
#Open the '''C/C++ General''' selection on the left.
 
#Open the '''C/C++ General''' selection on the left.
 +
#Click on '''Preprocessor Include Paths'''
 +
#Select '''GNU C''' in the '''Languages''' list
 +
#Select '''CDT User Setting Entries''' in the '''Setting Entries''' list
 +
#Click on '''Add...'''. Choose '''Preprocessor Macros File''' from the top left dropdown, '''Project Path''' from the top right dropdown, and enter "{{Code|include/generated/autoconf.h}}" into the '''File''' text box. (Note: for older kernels [pre-2.6.36?], the location of autoconf.h is {{Code|include/linux/autoconf.h}})
 +
#Also add any other macros files you are using.
 
#Click on '''Indexer'''
 
#Click on '''Indexer'''
 
#Checkmark the '''Enable project specific setttings''' box.
 
#Checkmark the '''Enable project specific setttings''' box.
Line 46: Line 47:
 
Notes:
 
Notes:
  
# Adding {{Code|include}} and {{Code|arch/}}''architecture''{{Code|/include}} only gets you a couple of the common include paths.  To fully index all of the kernel, you would have to add dozens of paths, unfortunately.  Header ({{Code|.h}}) files are not present only in include directories.  For this reason, I advise against using PTP's remote indexing capability for the linux kernel, because what happens is that it will report thousands of errors in locating header files, and the process of reporting those errors over a possibly long-latency link, will cause the indexing to take many hours.
+
# Adding {{Code|include}} and {{Code|arch/}}''architecture''{{Code|/include}} only gets you a couple of the common include paths.  To fully index all of the kernel, you would have to add dozens of paths, unfortunately.  For this reason, I advise against using PTP's remote indexing capability for the linux kernel, because what happens is that it will report thousands of errors in locating header files, and the process of reporting those errors over a possibly long-latency link, will cause the indexing to take many hours.
# If you change any of your CONFIG_* settings, in order for Eclipse to recognize those changes, you must do a "build" from within Eclipse.  Note, this does ''not'' mean to re-build the index; this means to build the kernel, by having Eclipse invoke make (this is normally bound to the Ctrl-B key in Eclipse).  Only after a build operation, will Eclipse regenerate the compilation #defines it uses when analyzing the source during indexing and editing.
+
# If you change any of your CONFIG_* settings, in order for Eclipse to recognize those changes, you may need to do a "build" from within Eclipse.  Note, this does ''not'' mean to re-build the index; this means to build the kernel, by having Eclipse invoke make (this is normally bound to the Ctrl-B key in Eclipse).  Eclipse should automatically detect changes to include/generated/autoconf.h, reread the compilation #defines it uses, and reindex.
 
# The background color of "Quick Context View" will be dark if the Ambiance theme in Ubuntu is selected.
 
# The background color of "Quick Context View" will be dark if the Ambiance theme in Ubuntu is selected.
  
  
 
Corey Ashford [mailto:cjashfor@us.ibm.com cjashfor@us.ibm.com]
 
Corey Ashford [mailto:cjashfor@us.ibm.com cjashfor@us.ibm.com]
 +
Updated by Nicholas Walton [mailto:nicholas.walton+eclipse@gmail.com nicholas.walton@gmail.com]

Revision as of 19:56, 16 August 2012

Here are some steps that I've found to get the CDT to work well with the Linux kernel source. If you exclude some of these steps, it may still work to a large degree, but some things may not work exactly right; for example it may find the wrong include file for a C file.

Anyway, as you do these steps, I think you may understand how they assist the indexer to do a good job for the Linux kernel source.

Disclaimer: these steps were last updated for Eclipse Juno + CDT 8.0.2, and originally developed for Eclipse 3.5.1 + CDT 6.0.0.

  1. Download and install Eclipse plus the CDT.
  2. Configure and build your kernel to define CONFIG_* and generate autoconf.h. This can be done before or after downloading and installing Eclipse.
  3. Ensure that you have the right kernel source (e.g. make sure you are on the right git branch). If you check out another branch later, that's ok, but you will need to re-index the source, and that takes about 20 minutes.
  4. Start up Eclipse.
  5. Click File->New->C Project
  6. Fill in a project name like my_kernel
  7. Uncheck the Use default location box and type in the root directory of your kernel into the Location box.
  8. In the Project type: pane, click the Makefile project and select Empty Project
  9. On the right side, select Linux GCC
  10. Click Advanced settings... and a Properties dialog will pop up.
  11. Select Resource on the left, and then in the Text file encoding section, select Other and ISO-8859-1 in the box, then click Apply
  12. Open the C/C++ General selection on the left.
  13. Click on Preprocessor Include Paths
  14. Select GNU C in the Languages list
  15. Select CDT User Setting Entries in the Setting Entries list
  16. Click on Add.... Choose Preprocessor Macros File from the top left dropdown, Project Path from the top right dropdown, and enter "include/generated/autoconf.h" into the File text box. (Note: for older kernels [pre-2.6.36?], the location of autoconf.h is include/linux/autoconf.h)
  17. Also add any other macros files you are using.
  18. Click on Indexer
  19. Checkmark the Enable project specific setttings box.
  20. Uncheck Index source files not included in the build
  21. Clear out the Files to index up-front box.
  22. Click on Paths and Symbols on the left.
  23. Select the Includes tab and then select GNU C
  24. Click Add...
  25. Click Workspace... then select your kernel's include directory
  26. Do another Add, Workspace and add arch/architecture/include, e.g., arch/powerpc/include
  27. Click the # Symbols tab
  28. Click Add...
  29. Set the name to __KERNEL__
  30. Set the value to 1 and click OK
  31. Click the Source Location tab
  32. Click the twisty for your project.
  33. Select the Filter item and click Edit Filter...
  34. Click Add Multiple... and then select all of the arch/* directories in your kernel source that will not be used (i.e. all the ones that are not for the architecture you are using)
  35. Click OK and OK again to dismiss that dialog.
  36. Click OK on the Properties dialog.
  37. Click Finish on the C Project dialog.
  38. Right click on the project and select Index then select Rebuild
  39. It will take about 20 minutes or so to complete.

Notes:

  1. Adding include and arch/architecture/include only gets you a couple of the common include paths. To fully index all of the kernel, you would have to add dozens of paths, unfortunately. For this reason, I advise against using PTP's remote indexing capability for the linux kernel, because what happens is that it will report thousands of errors in locating header files, and the process of reporting those errors over a possibly long-latency link, will cause the indexing to take many hours.
  2. If you change any of your CONFIG_* settings, in order for Eclipse to recognize those changes, you may need to do a "build" from within Eclipse. Note, this does not mean to re-build the index; this means to build the kernel, by having Eclipse invoke make (this is normally bound to the Ctrl-B key in Eclipse). Eclipse should automatically detect changes to include/generated/autoconf.h, reread the compilation #defines it uses, and reindex.
  3. The background color of "Quick Context View" will be dark if the Ambiance theme in Ubuntu is selected.


Corey Ashford cjashfor@us.ibm.com Updated by Nicholas Walton nicholas.walton@gmail.com

Copyright © Eclipse Foundation, Inc. All Rights Reserved.