用eclipse浏览linux内核

原创 2015年11月18日 12:23:28

原链接 https://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source


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 Juno 4.2.2 + CDT 8.1.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. Open the C/C++ General selection on the left.
  12. Click on Preprocessor Include Paths
  13. Select GNU C in the Languages list
  14. Select CDT User Setting Entries in the Setting Entries list
  15. 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 kernels older than 2.6.33, the location of autoconf.h is include/linux/autoconf.h)
  16. Also add any other macros files you are using.
  17. Click on Indexer
  18. Checkmark the Enable project specific setttings box.
  19. Uncheck Index source files not included in the build
  20. Click on Paths and Symbols on the left.
  21. Select the Includes tab and then select GNU C
  22. Click Add...
  23. Click Workspace... then select your kernel's include, and include/uapi directories
  24. 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)
  25. Click the # Symbols tab
  26. Click Add...
  27. Set the name to __KERNEL__
  28. Set the value to 1 and click OK
  29. Click the Source Location tab
  30. Click the plus sign next to your project name.
  31. Select the Filter item and click Edit Filter...
  32. 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)
  33. Click OK and OK again to dismiss that dialog.
  34. Under C/C++ General, select Preprocessor Include Paths, Macros etc.
  35. Click the Providers tab and select CDT GCC Built-in Compiler Settings
  36. Uncheck Use global provider shared between projects
  37. Add -nostdinc to the Command to get compiler specs
  38. Check Allocate console in the Console View so you can see that this is working
  39. Click OK on the Properties dialog.
  40. Click Finish on the C Project dialog.
  41. The Project will index automatically.
  42. 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

Linux 内核开发 - Eclipse内核开发环境搭建

翻译这篇文章的时候,我也想过可能会有高手说,内核开发用vi就足够了,还用什么eclipse,当然对于内核中函数特别了解的人确实如此,但是对于新 手,每使用一个函数,就要去查找一下函数的定义,实在是非常...
  • judyge
  • judyge
  • 2015年10月22日 16:21
  • 493

使用eclipse查看linux内核源码

由于需要在ubuntu下查看linux的内核源码,一开始用souceInsight,感觉不好用,后来换成eclipse,感觉还是不错的样子~~ 开始导入: 1.首先我们到Window->Pref...
  • huanghai381
  • huanghai381
  • 2016年04月05日 16:59
  • 2762

eclipse 阅读linux 内核

Linux kernel development and debugging using Eclipse CDT February 11th, 2011 by Atul Sharma This bl...
  • bugouyonggan
  • bugouyonggan
  • 2014年03月18日 13:32
  • 3958

在 Eclipse 中打开本地文件浏览器的方法

Run —- External Tools —- External Tools Configurations1.在 program 下面新建一个工具;Run —- External Tools —- ...
  • qq_27373045
  • qq_27373045
  • 2015年08月13日 12:52
  • 698

安装eclipse文件目录浏览插件

转载自:http://blog.csdn.net/xuefeng0707/article/details/8841035 EasyExplore的作用是:在Eclipse中,能够容易的打开任意文...
  • lkx94
  • lkx94
  • 2016年11月11日 10:58
  • 242

vim 配置方便浏览linux内核文件

1.安装ctags+cscope 2.下载vim插件 Source Explorer/NERD Tree/Tag List      网址:www.vim.org    Scrips-->Bo...
  • u010346967
  • u010346967
  • 2015年04月29日 11:27
  • 873

利用Eclipse搭建Linux内核开发环境

利用Eclipse搭建Linux内核开发环境正文  时光流逝,记得十年前还是个游手好闲的少年,无聊时觉得应该分析一下Linux内核源码,没有别的动机,只觉得这样很酷。   没有任何项目经验的话,突然...
  • aggresss
  • aggresss
  • 2017年08月02日 17:06
  • 1846

eclipse 调试linux 内核

搭建Eclipse+QEMU+GDB调试Linux Kernel环境 0.前言 本文讲述搭建环境的关键环节,相应的工具及版本如下: JDK:1.6.0_45 Eclipse:eclipse...
  • linuxarmsummary
  • linuxarmsummary
  • 2014年11月29日 16:11
  • 5208

Eclipse浏览项目的问题

show view 里面 有 还有个问题 :打开文件位置没找到 求告知 projectexplore 和  packageexplore  projectexplore  显示的样式...
  • xzl1991818
  • xzl1991818
  • 2016年01月12日 11:09
  • 127

linux内核结构图

为了能更好的学习驱动开发,最近开始学习linux内核结构的内容,找了很久看到一个感觉很有意思的结构框图,收下!...
  • zhangxiaopeng0829
  • zhangxiaopeng0829
  • 2012年04月30日 21:07
  • 1481
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:用eclipse浏览linux内核
举报原因:
原因补充:

(最多只允许输入30个字)