简体   繁体   English

为Linux内核开发设置Netbeans / Eclipse

[英]Setting up Netbeans/Eclipse for Linux Kernel Development

I'm doing some Linux kernel development, and I'm trying to use Netbeans. 我正在做一些Linux内核开发,我正在尝试使用Netbeans。 Despite declared support for Make-based C projects, I cannot create a fully functional Netbeans project. 尽管宣布支持基于Make的C项目,但我无法创建功能齐全的Netbeans项目。 This is despite compiling having Netbeans analyze a kernel binary that was compiled with full debugging information. 这是尽管编译Netbeans分析使用完整调试信息编译的内核二进制文件。 Problems include: 问题包括:

  • 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. 错误地排除了文件:某些文件在项目中显示为灰色,这意味着Netbeans不相信它们应该包含在项目中,而实际上它们已编译到内核中。 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. 主要问题是Netbeans将错过这些文件中存在的任何定义,例如数据结构和函数,但也会错过宏定义。
  • cannot find definitions : Pretty self-explanatory - often times, Netbeans cannot find the definition of something. 找不到定义 :相当不言自明 - 通常,Netbeans找不到某些东西的定义。 This is partly a result of the above problem. 这部分是上述问题的结果。
  • can't find header files : self-explanatory 找不到头文件 :不言自明

I'm wondering if anyone has had success with setting up Netbeans for Linux kernel development, and if so, what settings they used. 我想知道是否有人在为Linux内核开发设置Netbeans方面取得了成功,如果是,那么他们使用了什么设置。 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. 最后,我正在寻找Netbeans能够解析Makefile(首选)或从二进制文件中提取调试信息(不太理想,因为这会大大减慢编译速度),并自动确定哪些文件实际编译了哪些文件宏实际上是定义的。 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. 然后,基于此,我希望能够找到任何数据结构,变量,函数等的定义,并具有完整的自动完成功能。

Let me preface this question with some points: 让我先谈谈这个问题:

  • I'm not interested in solutions involving Vim/Emacs. 我对涉及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 正如标题所示,我也很高兴知道如何设置Eclipse以满足我的需求
  • While I would prefer perfect coverage, something that only misses one in a million definitions is obviously fine 虽然我更喜欢完美的报道,但是只错过百万分之一的定义显然很好

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 . SO的有用“相关问题”功能告诉我,以下问题是相关的: 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. 在阅读它之后,问题更多的是IDE之间的比较,而我正在寻找如何设置特定的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. 即便如此,用户Wade Mealing似乎在使用Eclipse进行此类开发方面具有一些专业知识,所以我当然会感谢他(当然还有你所有的)答案。

Cheers 干杯

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. 不幸的是,stackoverflow不允许我编辑以前的答案。 So I write it up in this new answer. 所以我在这个新答案中写下来。

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. [1]第一步是修改linux脚本以保留dep文件。默认情况下,在构建中使用它们后,将删除这些dep文件。 Those dep files contains exact dependency information about which other files a C file depends. 这些dep文件包含有关C文件所依赖的其他文件的确切依赖关系信息。 We need them to create a list of all the files involved in a build. 我们需要它们来创建构建中涉及的所有文件的列表。 Thus, modify files under linux-xyz/scripts to make them not to remove the dep files like this: 因此,修改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 . 其他步骤在我的github代码项目文件https://github.com/minghuascode/Nbk/blob/master/note-nbkparse中有详细说明。 Roughly you do: 大概你这样做:

[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. [4]从上面的github项目运行我的nbkparse脚本。 It does: [4.1] Read in the make log file, and the dep files. 它确实:[4.1]读取make日志文件和dep文件。 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.2]运行mirroring命令将相关源文件硬链接到单独的树中,并生成供NetBeans使用的make-log文件。


Now create a NetBeans C project using the mirrored source tree and the generated log file. 现在使用镜像源树和生成的日志文件创建NetBeans C项目。 NetBeans should be able to resolve all the kernel symbols. NetBeans应该能够解析所有内核符号。 And you will only see the files involved in the build. 而且您只会看到构建中涉及的文件。

Eclipse wiki有一个关于此的页面:如何使用CDT来导航Linux内核源代码

I have been doing some embedded linux development. 我一直在做一些嵌入式linux开发。 Including kernel module development and have imported the entire linux kernel source code into Eclipse, as a separate project. 包括内核模块开发并将整个linux内核源代码导入到Eclipse中,作为一个单独的项目。 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. 我一直在Eclipse之外构建内核(到目前为止),但我没有任何理由为什么我不能在Eclipse中设置构建环境来构建内核。 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. 对于我的项目,只要我将PATH属性设置为指向相应的linux源包含目录,对于struct字段的名称完成似乎相当不错等。

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开发。

I think this would work (done each step for various projects): 我认为这会奏效(为各种项目完成每一步):

[1] Modify kernel build scripts to leave .d files. [1]修改内核构建脚本以保留.d文件。 By default they are removed. 默认情况下,它们会被删除 [2] Log the build process to a file. [2]将构建过程记录到文件中。 [3] Write a script to parse the build log. [3]编写一个脚本来解析构建日志。 [3.1] From the build log, you know every .c files. [3.1]从构建日志中,您知道每个.c文件。 [3.2] From the .c file, you know which is the corresponding .d file. [3.2]从.c文件中,您知道哪个是相应的.d文件。 [3.3] Look into .d files to find out all the included .h files. [3.3]查看.d文件以找出所有包含的.h文件。 [3.4] Form a complete .c and .h file list. [3.4]形成一个完整的.c和.h文件列表。 [4] Now create a new dir, and use "ln -s" or "ln" to pick files of interest. [4]现在创建一个新目录,并使用“ln -s”或“ln”来选择感兴趣的文件。

Now, create a Netbeans project for existing source code in the [4]. 现在,在[4]中为现有源代码创建一个Netbeans项目。 Configure code assistance to use make-log file. 配置代码帮助以使用make-log文件。 You should see exactly the effective source code as when you build it at [2]. 在[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. 在[2],做一个真正的构建,以便日志文件包含感兴趣的确切文件和标志。 Later netbeans will be able to use the exact flags to parse. 后来的netbeans将能够使用确切的标志进行解析。

At [4], pick only the files you want to see. 在[4]处,只选择您想要查看的文件。 Incorporating the whole kernel tree into netbeans will be unpractical. 将整个内核树合并到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. 解析.d文件有一个技巧:许多依赖的项目不是.h文件的真实路径,它们是自动配置文件中部分linux配置部分的修改条目。 You may need to reverse the modification to figure out which is the real header file. 您可能需要反转修改以确定哪个是真正的头文件。

Actually there is a topic on netbeans site. 实际上netbeans网站上有一个话题。 This is the discussion url: http://forums.netbeans.org/ntopic3075.html . 这是讨论网址: http//forums.netbeans.org/ntopic3075.html And there is a wiki page linked from the discussion: wiki.netbeans.org/CNDLinuxKernel . 并且讨论中链接了一个wiki页面:wiki.netbeans.org/CNDLinuxKernel。 Basically it asks you to prefix make with CFLAGS="-g3 -gdwarf-2" . 基本上它要求你使用CFLAGS =“ - g3 -gdwarf-2”作为前缀。

I found this link very helpful in setting up proper indexing in Eclipse. 我发现这个链接非常有助于在Eclipse中设置正确的索引。 It requires running a script to alter Eclipse environment to match your kernel options, in my case 在我的例子中,它需要运行一个脚本来改变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 在eclipse中索引linux内核的插图指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM