How to use cscope?
Asked Answered
G

3

16

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?

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?

Giltedged answered 30/9, 2010 at 6:2 Comment(1)
Just one quick and useful tip: Cscope uses vi as the default editor. Which means no colors, no syntax highlighting... To change that and use VIM instead: export CSCOPE_EDITOR=vimAdrianneadriano
N
18

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.

Newmown answered 30/9, 2010 at 6:8 Comment(2)
Thanks a lot buddy. I got the answer for my second question. but can you tell me how to directly search that word as I mentioned in my question, double click on the word and give a command to find that word. What that command is?Giltedged
in Vim? Do not double-click. Put your cursor on that word, and type :cscope find s <CTRL-R><CTRL-W><enter>. You can remap it with :noremap <F3> :cscope find s <C-r><c-w><cr> (this will map F3 to it).Newmown
F
15

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.

Falcone answered 2/10, 2010 at 13:33 Comment(0)
H
10

I mostly use the following. These are very basic to understand the cscope.

  1. cscope -R Then you get options.
  2. Press down arrow. Then you will move to your required option. Type whatever you want at the respective option.
  3. From the search result. Use the up and down arrows. Then press the enter to see the detailed file.
  4. :q to exit from the file.
  5. Press Tab to come to the cscope options.
  6. ctrl + d to exit from the cscope.
Hypotonic answered 7/3, 2018 at 10:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.