


全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Software is like sex: its better when its free.Using Cscope on large projects (example: the Linux kernel)Cscope can be a particularly useful tool if you need to wade into a large code base. You can save yourself a lot of time by being able to do fast, targeted searches rather than randomly grepping through the source files by hand (especially since grep starts to take a while with a truly large code base). In this tutorial youll learn how to set up Cscope with a large project. Well use as our example the Linux kernel source code, but the basic steps are the same for any other large project, including C+ or Java projects. 1. Get the source. First get the source code. You can download the Linux kernel source from . For the rest of this tutorial, Ill assume youve downloaded Linux 2.4.18 and installed it into /home/jru/linux-2.4.18. Note: Make sure youve got enough disk space: the kernel tarball alone is 30 MB, it expands into 150 MB of source code, and the Cscope database well generate will gobble up another 20-100+ MB (depending on how much of the kernel code you decide to include in the database). You can put the Cscope database on a different disk partition than the source code if you need to. 2. Figure out where you want to put your Cscope database files. Ill assume youll use /home/jru/cscope as the directory to store your database and associated files. 3. Generate cscope.files with a list of files to be scanned. For some projects, you may want to include every C source file in the projects directories in your Cscope database. In that case you can skip this step, and just use cscope -R in the projects top-level directory to build your Cscope database. But if theres some code that you wish to exclude, and/or your project contains C+ or Java source code (by default Cscope only parses files with the .c, .h, .y, or .l extensions), youll need to generate a file called cscope.files, which should contain the name of all files that you wish to have Cscope scan (one file name per line). Youll probably want to use absolute paths (at least if youre planning to use the Cscope database within an editor), so that you can use the database from directories other than the one you create. The commands I show will first cd to root, so that find prints out absolute paths. For many projects, your find command may be as simple as cd / find /my/project/dir -name *.java /my/cscope/dir/cscope.filesFor the Linux kernel, its a little trickier, since we want to exclude all the code in the docs and scripts directories, plus all of the architecture and assembly code for all chips except for the beloved Intel x86 (which Im guessing is the architecture youre interested in). Additionally, Im excluding all kernel driver code in this example (they more than double the amount of code to be parsed, which bloats the Cscope database, and they contain many duplicate definitions, which often makes searching harder. If you are interested in the driver code, omit the relevant line below, or modify it to print out only the driver files youre interested in): LNX=/home/jru/linux-2.4.18 cd / find $LNX -path $LNX/arch/* ! -path $LNX/arch/i386* -prune -o -path $LNX/include/asm-* ! -path $LNX/include/asm-i386* -prune -o -path $LNX/tmp* -prune -o -path $LNX/Documentation* -prune -o -path $LNX/scripts* -prune -o -path $LNX/drivers* -prune -o -name *.chxsS -print /home/jru/cscope/cscope.filesWhile find commands can be a little tricky to write, for large projects they are much easier than editing a list of files manually, and you can also cut and paste a solution from someone else. 4.Generate the Cscope database. Now its time to generate the Cscope database: 5. cd /home/jru/cscope # the directory with cscope.files6. cscope -b -q -kThe -b flag tells Cscope to just build the database, and not launch the Cscope GUI. The -q causes an additional, inverted index file to be created, which makes searches run much faster for large databases. Finally, -k sets Cscopes kernel mode-it will not look in /usr/include for any header files that are #included in your source files (this is mainly useful when you are using Cscope with operating system and/or C library source code, as we are here). On my 900 MHz Pentium III system (with a standard IDE disk), parsing this subset of the Linux source takes only 12 seconds, and results in 3 files (cscope.out, cscope.in.out, and cscope.po.out) that take up a total of 25 megabytes. 7.Using the database. If you like to use vim or emacs/xemacs, I recommend that you learn how to run Cscope within one of these editors, which will allow you to run searches easily within your editor. We have a tutorial for Vim, and emacs users will of course be clever enough to figure everything out from the helpful comments in the cscope/contrib/xcscope/ directory of the Cscope distribution. Otherwise, you can use the standalone Cscope curses-based GUI, which lets you run searches, then launch your favorite editor (i.e., whatever $EDITOR is set to in your environment, or vi by default) to open on the exact line of the search result. If you use the standalone Cscope browser, make sure to invoke it via cscope -dThis tells Cscope not to regenerate the database. Otherwise youll have to wait while Cscope checks for modified files, which can take a while for large projects, even when no files have changed. If you accidentally run cscope, without any flags, you will also cause the database to be recreated from scratch without the fast index or kernel modes being used, so youll probably need to rerun your original cscope command above to correctly recreate the database. 8.Regenerating the database when
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 统编版语文六年级上册 第三单元 习作-让生活更美好 +公开课一等奖创新教学设计
- 备战2026年高考高中语文必修下课文中的文化常识梳理
- 先兆流产教学课件
- 电缆计量规则解读
- 恒星脉动观测数据-洞察及研究
- 转个人公积金办理合同5篇
- 内控管理提升课件设计
- 元音字母e的课件
- 内容生产加工安全培训课件
- 创业团队的组建课件
- 护士长笔试题库及答案
- 2025年辅警招聘考试试题库(含答案)
- 精神运动康复
- 2025年陕西省中考数学试题卷(含答案详解)
- 2025年中小学生国防知识竞赛题库及答案
- 机械制图选择题试题库及答案
- 湖南省科技创新惠企助企政策汇编 2025
- DB45∕T 2746-2023 国家储备林培育技术规程
- 医保基金监管培训课件
- 药厂变更管理培训
- 体育安全与急救知识培训
评论
0/150
提交评论