http://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source

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 Oxygen 4.7.2 + CDT 9.4.0, 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. Note: At this point, latest Eclipse versions (e.g. Oxygen) will aggressively start indexing your project, which can make Eclipse painfully slow for the rest of the configuration steps below -- especially if the desire is to only index a small relevant part of the kernel. To mitigate that, temporarily disable indexing now by opening C/C++ General section, click on Indexer, click on Enable project-specific settings, then unmark the Enable indexer option.
  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/linux/kconfig.h" into the File text box. Note 1: For older kernels (e.g. 4.1.12, 4.2.7, or less), selecting "include/generated/autoconf.h" works better. In newer kernels, selecting kconfig.h is better as this file includes <generated/autoconf.h> and also makes sure that tests such as IS_ENABLED(option) are correctly expanded by the CDT scanner. Note 2: For kernels older than 2.6.33, 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. Click on Paths and Symbols on the left.
  22. Select the Includes tab and then select GNU C
  23. Click Add...
  24. Click Workspace... then select your kernel's include, and include/uapi directories
  25. Do another Add, Workspace and add both arch/architecture/include, and arch/architecture/include/uapi directories. e.g., arch/powerpc/include and arch/powerpc/include/uapi (The UAPI directories are due to the kernel's user/kernel header split covered here in-detail)
  26. Click the # Symbols tab
  27. Click Add...
  28. Set the name to __KERNEL__
  29. Set the value to 1 and click OK
  30. Click the Source Location tab
  31. Click the plus sign next to your project name.
  32. Select the Filter item and click Edit Filter...
  33. 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)
  34. Click OK and OK again to dismiss that dialog.
  35. Under C/C++ General, select Preprocessor Include Paths, Macros etc.
  36. Click the Providers tab and select CDT GCC Built-in Compiler Settings
  37. Uncheck Use global provider shared between projects
  38. Append -nostdinc to the curretly-existing Command to get compiler specs. The kernel is a free-standing environment by ISO C99 definition. That is, it does not want to be polluted, and obviously cannot work with, the "host" header files and libraries.
  39. Also append -iwithprefix include to the Command to get compiler specs above. Rationale is, -nostdinc above asked gcc to not search the standard system directories for header files. But the Linux Kernel depends on GCC-provided "freestanding environment" headers like stdarg.h, stdbool.h, etc., and which are typically hosted by GCC under /lib/gcc/<arch>/<version>/include. Thus the append.
  40. Check Allocate console in the Console View so you can see that this is working
  41. Click OK on the Properties dialog.
  42. Note: If you temporarily disabled indexing as earlier recommended. This is the right time to re-enable it. Under C/C++ General, click on Indexer, and mark the Enable indexer option.
  43. Click Finish on the C Project dialog.
  44. The Project will index automatically.
  45. On a platter drive indexing will take upwards of 20 minutes to complete, on a SSD indexing will take about 5 minutes 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.
  4. For some people, Eclipse may fail to index the kernel with a out of memory error. The fix seems to be to start eclipse with the arguments: eclipse -vmargs -Xmx650M

how to use Eclipse for kernel development的更多相关文章

  1. 使用 Eclipse C/C++ Development Toolkit 开发应用程序

    使用 Eclipse C/C++ Development Toolkit 开发应用程序 (转) 来自http://blog.csdn.net/favory/article/details/189080 ...

  2. How to Install Eclipse C/C++ Development Tool--转

    http://www3.ntu.edu.sg/home/ehchua/programming/howto/EclipseCpp_HowTo.html Eclipse 4.3 (Kepler) for ...

  3. Eclipse安装Database Development插件。

        早期版本的Eclipse,自带Database Development,用着挺方便的,可是自己的最新版Eclipse反而没有.于是乎钻研了下,找到了安装方法.和汉化包安装很类似: 菜单栏里选择 ...

  4. eclipse preference plugin development store and get

    eclipse plugin development: E:\workspaces\Eclipse_workspace_rcp\.metadata\.plugins\org.eclipse.pde.c ...

  5. 搭建基于qemu + eclipse的kernel调试环境(by quqi99)

    作者:张华  发表于:2016-02-06版权声明:能够随意转载.转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) 使用q ...

  6. <<Linux kernel development>> Process Management

    The Process On modern operating systems,processes provide two virtualizations:a virtualized processo ...

  7. Linux Kernel Development有关内存管理

    1 Pages Page的概念来源为处理器Processor的部件MMU(Memory Management Unit),MMU通过设置好的页表(通过设置CR3寄存器,指向页目录所在的物理内存)对内存 ...

  8. Ubuntu(Linux)使用Eclipse搭建C/C++编译环境

    转自:http://www.cppblog.com/kangnixi/archive/2010/02/10/107636.html 首先是安装Eclipse,方法有两种:       第一种是通过Ub ...

  9. Android SDK +Eclipse+ADT+CDT+NDK 开发环境在windows 7下的搭建

    Android SDK+Eclipse+ADT+CDT+NDK 开发环境在windows 7下的搭建 这几天一直在研究 Android SDK  C/C++平台的搭建,尽管以前有成功在Windows ...

随机推荐

  1. java开发简易计算器

    所选用的编译工具为NetBeans /* * To change this license header, choose License Headers in Project Properties. ...

  2. windows下安装cygwin及配置(转)

    reference:https://cygwin.com/install.html 对比:MinGW vs. CygWin    https://www.cnblogs.com/findumars/p ...

  3. byte[]->new String(byte[]) -> getByte()引发的不一致问题

    今天接短信接口,短信接口提供了sdk,我们可以直接用sdk发送请求然后发送对应短信. 但是想使用我们平台自定义的httpUtil实现. 然而忙了1天半,才解决这个问题,还是我同事帮忙找出问题并解决的. ...

  4. MAC开发配置--Node和Npm

    前往Node官网下载最新的长期支持版本Node https://nodejs.org/zh-cn/download/   默认安装目录为:     •    Node.js v10.14.2 to / ...

  5. Asp.Net对Json字符串的解析和应用

    using System.Web.Script.Serialization; protected void Page_Load(object sender,EventArgs e) { //构建jso ...

  6. 70 多表查询的分组F 聚合 Q 查询

    聚合查询和分组查询 聚合 aggregate()是QuerySet 的一个终止子句,意思是说,它返回一个包含一些键值对的字典.键的名称是聚合值的标识符,值是计算出来的聚合值.键的名称是按照字段和聚合函 ...

  7. REST easy with kbmMW #21 – Delphi client stubs

    在之前的博文中,我提到新的存根生成器框架具有生成Delphi客户端存根所需的功能,使得开发Delphi智能客户端非常容易,完全支持编译时的类型检查和IDE类/属性帮助. 我没想到会把它包含在即将发布的 ...

  8. python scrapy爬虫数据库去重方法

    1. scrapy对request的URL去重 yield scrapy.Request(url, self.parse, dont_filter=False) 注意这个参数:dont_filter= ...

  9. 阻止ARP欺骗

    利用Look N Stop防火墙,防止arp欺骗 阻止网络执法官控制 网络执法官是利用的ARp欺骗的来达到控制目的的. ARP协议用来解析IP与MAC的对应关系,所以用下列方法可以实现抗拒网络执法官的 ...

  10. Python基础5--字符串

    1 find().rfind().index().rindex().count() s = "this apple is red apple" s.find("apple ...