Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use cscope?

Tags:

c

linux

vim

cscope

I am using cscope to get familiar with all the keywords used in socket programming. I went to the directory with c files. I used cscope. and then I searched for AF_INET. I got this :

#define AF_FILE         PF_FILE
#define AF_INET         PF_INET
#define AF_AX25         PF_AX25

This was a full page. I only published part of it. Now I want to know from where this PF_INET is coming? what command I should use. I have seen a guy to double click on PF_INEt and using some command to find it. I don't know what the command is? Kindly help me in this.

The second thing is when i quit the page with :q command. I come to this page :

Global definition: AF_INET

  File     Line
0 socket.h 119 #define AF_INET PF_INET










Find this C symbol:
Find this global definition:
Find functions called by this function:
Find functions calling this function:
Find this text string:
Change this text string:
Find this egrep pattern:
Find this file:
Find files #including this file:

here the cursor is blinking at 0. If I want to search again something, how I will do? How to navigate from here. I tried to google it but unable to understand anything from the tutoials. Please help me in this regard as I am complete noob to linux operating system and c programming. Thanks in advance.

like image 669
narayanpatra Avatar asked Sep 30 '10 06:09

narayanpatra


People also ask

How do I search cscope?

Select the type of search that you'd like to perform, type in your search term and hit Enter. At the top of the screen Cscope will display a list of results with the file, function, and line where the search term was found.

How do I get out of cscope?

Exit cscope. If the first character of the text for which you are searching matches one of these commands, you can escape the command by entering a \ (backslash) before the character. Now move the cursor to the fifth menu item, Find this text string, enter the text out of storage, and press the Return key.


2 Answers

I agree that cscope documentation is not very clear.

Use tab to move to the interactive part. Type your symbol name in “find this C symbol” or “Find this egrep pattern” and validate pressing RETURN.

If you want to call it from vim, type :help if_cscop.txt; hoping it helps!

:cscope add your_cscope_database
:cscope find s [your_symbol]

This will make a new quickfix list. use :cn and :cp to navigate, :cnf and :cpf to navigate from file to file in the results, and :colder and :cnewer to restore previous quickfix lists.

like image 151
Benoit Avatar answered Oct 09 '22 09:10

Benoit


To exit from cscope interactive prompt, type Ctrl-d. If you just want to rebuild cscope's database, and not invoke cscope's interactive prompt, pass it the -b option. I usually invoke cscope as cscope -bcqR.

As for jumping around in vim using cscope, it really depends on your vim config.

Most probably, jump to tag (Ctrl-]) will use cscope first, then ctags (see :help cst and :help csto). Use Ctrl-T to go back.

There are some useful mappings for cscope that you can find by typing :help cscope-suggestions in vim. After adding those mappings to your .vimrc, you will be able to jump to symbols using Ctrl-_ s, the calling function using Ctrl-_ c, etc...

You can access vim's cscope documentation by typing :help cscope.

like image 27
ninjalj Avatar answered Oct 09 '22 10:10

ninjalj