Use VIM to see Code: Cscope

Source: Internet
Author: User
Tags postgresql

Original address: Use VIM to see the code: Cscope Author: Bean_lee


Vim+cscope+ctags is linux to see the Code tool, online search vim tutorial A large pile, a lot of talk is good, unfortunately they have not learned. Good morning, my old chief pogo would once taught me once, ctags I was a learning about, cscope can only be regarded as entry-level level, such as viewing a function call, but also to use: CS Find C function This relatively slow method.     I am lazy, spent too little time in mastering tools, so I am not a good programmer. Cscope exist so that Vim has the ability to match the source insight, then the large engineering documents how to use Cscope it.
Recently in See PostgreSQL source code, we know, PostgreSQL source belongs to a large project, SRC below a lot of directories, different directories under a lot of documents. Many tutorials on how to build a Csope database are the following methods, taking my PostgreSQL as an example) root@manu:/usr/local/src/pgsrc/postgresql-9.2.3/src# CSCOPE-RBQ
root@manu:/usr/local/src/pgsrc/postgresql-9.2.3/src# ll ...-rw-r--r--1 root root 2138112 March 23:35 cscope.in.out    -rw-r--r--1 root 19451512 March 23:35 cscope.out-rw-r--r--1 root 14147844 March 23:35 cscope.po.out ..... This approach brings problems (or maybe I am a little bit more shallow), what will be the problem.
Before we do that, we'll start with the following cscope application instructions: Execute on the VIM command line: CS Help


CS Show is to display the currently available database, CS Add is to add a database. Let's take a look at the root@manu:/usr/local/src/pgsrc/postgresql-9.2.3/src# CD backend/storage/file/
root@manu:/usr/local/src/pgsrc/postgresql-9.2.3/src/backend/storage/file# VI FD.C


We performed the Add Cscope test database operation in the VIM command line mode: CS Add/usr/local/src/pgsrc/postgresql-9.2.3/src/cscope.out:cs Show can see the following DB connection: It is still normal, when we use: CS find to look up the relationship between function calls: For example, when I read the Closeallvfds function implementation, I care about who called the FD.C in the Closeallvfds this function.           : CS Find C is to do this live, please see the above help. The result is not found.
We have not already added the database, why did not find it. The reason is that when we generate cscope.out, the paths are relative paths.           For large projects, how do we use cscope to do the function jump between files. The following is a recommended method for official documentation: Using Cscope on large projects (example:the Linux kernel), the English cheese can go directly to the original, do not listen to my wordy.
1 Set up Cscope directory, I am in my own home directory to store the Cscope database directory: root@manu:~/cscope# ll total dosage drwxr-xr-x 2 root 4096 March 00:49./drwxr- Xr-x Manu Manu 12288 March 31 00:48. /2 Create a script to do things to build the Cscope database root@manu:~/cscope# cat/usr/bin/makecscope.sh
#!/bin/sh

Usage ()
{
echo "Usage:makecscope src_path project_name"
echo "I'll create Cscope db in ~/cscope/project_name"
}
If [$#-ne 2]
Then
Usage
Exit
Fi

Src_path=$1
Cscope_path=/home/manu/cscope/$2

Mkdir-p $CSCOPE _path
CD $CSCOPE _path
Find $SRC _path-name "*.h"-o-name "*.c"-o-name "Makefile"-o-name "Makefile" > Cscope.files
Cscope-bkq-i./cscope.files

We have built an SH script to do this, the SH script will accept two parameters the source path: The script searches for the name of all the. C. h Makefile Makefile file items under the source code path: The script creates a directory in the ~/cscope directory with the name of the second parameter, and generates Cscope database into the directory we put this makecscope.sh script into the/usr/bin/directory, we can execute this script under any path.
3 Create Cscope database for any project, we still take PostgreSQL as an example: root@manu:~/cscope# makecscope.sh/usr/local/src/pgsrc/postgresql-9.2.3/src/ Postgres

I created the Cscope database for all C-File headers and makefile files under/usr/local/src/pgsrc/postgresql-9.2.3/src/and placed the database under the ~/cscope/postgres path. root@manu:~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.