全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年房地产行业物业管理升级水平考试-物业行业监管(信用体系)政策应用考核试卷
- 2025年学前教育普惠性发展专项能力测试-普惠性幼儿园“家长学校”课程设计与实施考核试卷
- 2025年化妆品个护行业绿色环保产品创新研究报告及未来发展趋势预测
- 2025年义务教育学校债务化解情况督导评估考核试卷
- 2025年化妆品行业品牌营销与绿色化妆品发展报告
- 2026西藏银行校园招聘12人笔试考试参考题库及答案解析
- 2025江苏南京智慧交通公司职业经理人招聘1人笔试考试备考试题及答案解析
- 2025云南玉溪市元江县民政局招聘城镇公益性岗位人员2人考试笔试参考题库附答案解析
- 2025福建三明永安市贡川镇人民政府招聘编外聘用驾驶员2人笔试考试参考试题及答案解析
- 2026年水利部长江水利委员会事业单位公开招聘(第一批)考试笔试模拟试题及答案解析
- DB45∕T 1098-2024 橡胶沥青路面施工技术规范
- 直播中控培训课件
- 粉末喷塑工艺培训课件
- 上市公司关务管理制度
- 2024年上海松江区工作者招聘笔试真题
- 洗车行安全管理制度
- 细胞库建立管理制度
- 北京开放大学2025年《企业统计》形考作业1答案
- 临床技术操作规范麻醉学分册
- 医院应急预案管理和演练制度
- 贵州省贵阳市云岩区2024-2025学年上学期八年级数学期末试题卷(原卷版+解析版)
评论
0/150
提交评论