为 Linux 内核开发设置 Netbeans/Eclipse
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1500707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting up Netbeans/Eclipse for Linux Kernel Development
提问by red.october
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:
我正在做一些 Linux 内核开发,我正在尝试使用 Netbeans。尽管声明支持基于 Make 的 C 项目,但我无法创建功能齐全的 Netbeans 项目。尽管编译时 Netbeans 会分析使用完整调试信息编译的内核二进制文件。问题包括:
- 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
- 文件被错误排除:项目中某些文件错误地显示为灰色,这意味着 Netbeans 不认为它们应该包含在项目中,而实际上它们已编译到内核中。主要问题是 Netbeans 会遗漏这些文件中存在的任何定义,例如数据结构和函数,还会遗漏宏定义。
- 找不到定义:不言自明 - 通常,Netbeans 找不到某些东西的定义。这部分是上述问题的结果。
- 找不到头文件:不言自明
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.
我想知道是否有人成功地为 Linux 内核开发设置了 Netbeans,如果是,他们使用了哪些设置。最终,我希望 Netbeans 能够解析 Makefile(首选)或从二进制文件中提取调试信息(不太理想,因为这会显着减慢编译速度),并自动确定实际编译了哪些文件以及哪些宏实际上是定义的。然后,基于此,我希望能够找到任何数据结构,变量,函数等的定义并具有完整的自动完成功能。
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
- 我对涉及 Vim/Emacs 的解决方案不感兴趣。我知道有些人喜欢他们,但我不是其中之一。
- 正如标题所暗示的那样,我也很高兴知道如何设置 Eclipse 来做我需要的事情
- 虽然我更喜欢完美的覆盖,但只有百万分之一的定义显然没有问题
SO's useful "Related Questions" feature has informed me that the following question is related: https://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.
SO 有用的“相关问题”功能告诉我以下问题是相关的:https: //stackoverflow.com/questions/149321/what-ide-would-be-good-for-linux-kernel-driver-development。阅读后,问题更多是 IDE 之间的比较,而我正在寻找如何设置特定 IDE。即便如此,用户 Wade Mealing 似乎在使用 Eclipse 进行此类开发方面具有一定的专业知识,因此我当然会感谢他(当然还有您的所有)回答。
Cheers
干杯
采纳答案by JesperE
Eclipse seems to be pretty popular for Linux kernel development:
Eclipse 似乎在 Linux 内核开发中非常流行:
回答by minghua
I previously wrote up an answer. Now I come up with all the details of the solution and would like to share it. Unfortunately stackoverflow does not allow me to edit the previous answer. So I write it up in this new answer.
我之前写过一个答案。现在我想出了解决方案的所有细节,并想分享它。不幸的是,stackoverflow 不允许我编辑以前的答案。所以我把它写在这个新答案中。
It involves a few steps.
它涉及几个步骤。
[1] The first step is to modify linux scripts to leave dep files in. By default after using them in the build, those dep files are removed. Those dep files contains exact dependency information about which other files a C file depends. We need them to create a list of all the files involved in a build. Thus, modify files under linux-x.y.z/scripts to make them not to remove the dep files like this:
[1] 第一步是修改linux脚本,保留dep文件。默认情况下,在构建中使用它们后,这些dep文件将被删除。这些 dep 文件包含有关 C 文件所依赖的其他文件的确切依赖信息。我们需要它们来创建构建中涉及的所有文件的列表。因此,修改 linux-xyz/scripts 下的文件,使它们不会像这样删除 dep 文件:
linux-3.1.2/scripts
Kbuild.include: echo do_not_rm1 rm -f $(depfile);
Makefile.build: echo do_not_rm2 rm -f $(depfile);
The other steps are detailed in my github code project file https://github.com/minghuascode/Nbk/blob/master/note-nbkparse. Roughly you do:
其他步骤在我的 github 代码项目文件https://github.com/minghuascode/Nbk/blob/master/note-nbkparse 中有详细说明。大致上你这样做:
[2] Configure with your method of configuration, but be sure use "O=" option to build the obj files into a separate directory.
[2] 使用您的配置方法进行配置,但请确保使用“O=”选项将 obj 文件构建到单独的目录中。
[3] Then use the same "O=" option and "V=1" option to build linux, and save make output into a file.
[3] 然后使用相同的“O=”选项和“V=1”选项构建linux,并将make输出保存到文件中。
[4] Run my nbkparse script from the above github project. It does: [4.1] Read in the make log file, and the dep files. Generate a mirroring command. [4.2] Run the mirroring command to hard-link the relevant source files into a separate tree, and generate a make-log file for NetBeans to use.
[4] 从上面的 github 项目运行我的 nbkparse 脚本。它的作用是: [4.1] 读入 make 日志文件和 dep 文件。生成镜像命令。[4.2] 运行镜像命令将相关源文件硬链接到一个单独的树中,并生成一个make-log文件供NetBeans使用。
Now create a NetBeans C project using the mirrored source tree and the generated log file. NetBeans should be able to resolve all the kernel symbols. And you will only see the files involved in the build.
现在使用镜像源树和生成的日志文件创建一个 NetBeans C 项目。NetBeans 应该能够解析所有内核符号。并且您只会看到构建中涉及的文件。
回答by Nicholas
The Eclipse wiki has a page about this: HowTo use the CDT to navigate Linux kernel source
Eclipse wiki 有一个关于此的页面:HowTo use the CDT to navigation Linux kernel source
回答by Minghua
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.
[1] 修改内核构建脚本以保留 .d 文件。默认情况下,它们被删除。[2] 将构建过程记录到文件中。[3] 编写脚本解析构建日志。[3.1] 从构建日志中,您知道每个 .c 文件。[3.2] 从.c 文件,你知道哪个是对应的.d 文件。[3.3] 查看 .d 文件以找出所有包含的 .h 文件。[3.4] 形成完整的.c 和.h 文件列表。[4] 现在创建一个新目录,并使用“ln -s”或“ln”选择感兴趣的文件。
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].
现在,为 [4] 中的现有源代码创建一个 Netbeans 项目。配置代码帮助以使用 make-log 文件。当您在 [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.
在 [2] 处,进行真正的构建,以便日志文件包含感兴趣的确切文件和标志。稍后 netbeans 将能够使用确切的标志进行解析。
At [4], pick only the files you want to see. Incorporating the whole kernel tree into netbeans will be unpractical.
在 [4] 处,仅选择您想查看的文件。将整个内核树合并到 netbeans 中是不切实际的。
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.
解析 .d 文件有一个技巧:许多依赖项不是 .h 文件的真实路径,它们是自动配置文件中部分 linux 配置部分的修改条目。您可能需要反向修改才能确定哪个是真正的头文件。
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" .
实际上,netbeans 站点上有一个主题。这是讨论网址:http: //forums.netbeans.org/ntopic3075.html。并且有一个从讨论中链接的 wiki 页面:wiki.netbeans.org/CNDLinuxKernel。基本上它要求您在 make 前加上 CFLAGS="-g3 -gdwarf-2" 。
回答by fredk
I found this link very helpful in setting up proper indexing in Eclipse. It requires running a script to alter Eclipse environment to match your kernel options, in my case
我发现此链接对于在 Eclipse 中设置正确的索引非常有帮助。就我而言,它需要运行脚本来更改 Eclipse 环境以匹配您的内核选项
$ autoconf-to-eclipse.py ./include/generated/autoconf.h .
$ autoconf-to-eclipse.py ./include/generated/autoconf.h 。
An illustrated guide to indexing the linux kernel in eclipse
回答by simon
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.
我一直在做一些嵌入式linux开发。包括内核模块开发,并将整个linux内核源代码导入Eclipse,作为一个单独的项目。我一直在 Eclipse 之外构建内核本身(到目前为止),但我没有任何理由不能在 Eclipse 中设置构建环境来构建内核。对于我的项目,只要我将 PATH 属性设置为指向适当的 linux 源包含目录,结构字段等的名称完成似乎就很好。
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.
我也想知道如何使用 Netbeans 作为 linux 'C' IDE,因为我更喜欢 Netbean 的 Java GUI 开发。