All the cscope tutorials I found online talk about how to use the interactive mode of cscope to search for symbols in editors such as vim and emacs. But I think it should be possible to issue a command in terminal to do something like
cscope -d -some_options <my symbol>
And I should be able to see a list of results in stdout, instead of having to enter the ncurse UI and do everything there. I think this is possible because the "only" frontend cbrowser can do things like that in its TclTK UI. But the code unfortunately is quite beyond me.
However, I found no documentation about this capability.
Am I dreaming or is there an undocumented way of doing this?
Thanks!
UPDATE
Some progress: If I make a small project of a few files with sub-dir structure. Then rici's answer works out of the box. With a bigger project (thousands of files with complex folder structure). Even with a cscope.out and cscope.files present at the root of the project folder (also my current working directory), I got nothing from the same command and same symbol. I suspect that there is a scalability issue with the command. I also tried command
cat cscope.files | xargs cscope -d -L1 <symbol> -i
to no avail.
UPDATE
Extremely bizarre! I tried to use some other symbols. Turned out that the particular symbol I was searching for cannot be shown using the command line. But all other symbols I tried worked. And cbrowser has no problem finding that "failed" symbol. Anyways, I was just in bad luck. I'll ask a separate question about this anomaly in command line.
I marked rici's answer as correct.
You are probably looking for this:
cscope -L1<symbol>
You could use -d
as well, although if you're modifying the files, it's good for cscope to update it's database.
-L
means "execute a single line-oriented command", and the following digit (1
in this case), which could also have been written as a separate option, is the specific command, which the manpage confusingly calls a "field". The "fields" are given by the interactive cscope prompt; I added the digit for convenience. "this" refers to the text which follows the digit; remember that it's a pattern so you don't necessarily have to type the full symbol.
0 Find this C symbol:
1 Find this function definition:
2 Find functions called by this function:
3 Find functions calling this function:
4 Find this text string:
5 Change this text string:
6 Find this egrep pattern:
7 Find this file:
8 Find files #including this file: