Reputation: 5691
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?
Upvotes: 17
Views: 82426
Reputation: 1
This file should list all the source files that cscope
will analyze. You can generate it automatically with a command like this: bash find . -name "*.c" -o -name "*.h" -o -name "*.cpp" > cscope.files
- This command will include all .c
, .h
, and .cpp
files in your project. 3. Build the cscope
database: - Run the following command to build the cscope
database: bash cscope -b -q -k
- -b
: Build only (don’t launch the cscope
UI). - -q
: Create an inverted index to speed up searches. - -k
: Do not use the standard system include files. ### Using the cscope
Interactive Interface Once the database is built, you can start cscope
in interactive mode: bash cscope -d
- -d
: Use the existing database instead of building a new one. In the interactive interface, you can search for: 1. Find this C symbol: Looks up a symbol in the code. 2. Find this function definition: Locates the definition of a function. 3. Find functions called by this function: Lists functions called within a given function. 4. Find functions calling this function: Lists functions that call a specific function. 5. Find this text string: Searches for a text string. 6. Change this text string: Allows editing of text. 7. Find this egrep
pattern: Uses egrep
to search for a pattern. 8. Find this file: Locates a file. 9. Find files #including this file: Finds files that include a specific header file. ### Using cscope
Non-Interactively You can also use cscope
directly from the command line for quick searches without opening the interactive interface: bash cscope -d -L -s <symbol>
- -L
: Perform a search and print results. - -s <symbol>
: Replace <symbol>
with what you want to search. ### Integration with vim
cscope
integrates well with vim
if you want to use it within your editor: 1. Open vim
and run: vim :cs add cscope.out
2. Now you can use vim
commands like: - :cs find d <symbol>
to find the definition of a symbol. - :cs find c <symbol>
to find functions that call the symbol. - :cs find t <text>
to search for text strings. This setup allows for quick and efficient code navigation, especially in large codebases!
strong text
Upvotes: -1
Reputation: 103
I mostly use the following. These are very basic to understand the cscope.
cscope -R
Then you get options.:q
to exit from the file.Upvotes: 10
Reputation: 43688
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
.
Upvotes: 15
Reputation: 79155
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.
Upvotes: 19