cscope: How to use cscope to search for a symbol using command line?

后端 未结 2 1975
借酒劲吻你
借酒劲吻你 2021-02-09 04:55

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 pos

相关标签:
2条回答
  • 2021-02-09 05:16

    You can call cscope with the -R version for recursive searching. For example:

    cscope -d -f/path/to/cscope.out -R -L1 some_symbol
    

    (searches for the definition of some_symbol)

    cscope -d -f/path/to/cscope.out -R -L3 some_symbol
    

    (shows all locations where some_symbol is called)

    You can omit the -f option if cscope.out is located in the current working directory.

    Note that the above call yield zero results for an indexed symbol if -R is omitted. Very old cscope versions don't support -R. For example, version 15.8a does support it.

    The list of possible values for -L is:

    0: Find this C symbol
    1: Find this definition
    2: Find functions called by this function
    3: Find functions calling this function
    4: Find this text string
    6: Find this egrep pattern
    7: Find this file
    8: Find files #including this file
    9: Find places where this symbol is assigned a value
    

    The -R option can also be used when creating the cscope.out file, e.g.:

    cscope -bR
    
    0 讨论(0)
  • 2021-02-09 05:30

    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:
    
    0 讨论(0)
提交回复
热议问题