Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
773 views
in Technique[技术] by (71.8m points)

how can I display all function name from cscope database?

I am trying to find a way to dump ALL the functions name and it's path from cscope database. Is there a way to do that from cscope CLI?

Note: the cscope source code is available for download.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try the following:

cscope -R -L -2 ".*" | awk -F ' ' '{print $2 "#" $1}' | sort | uniq
  1. The command cscope -R -L -2 ".*" will output functions called by any function (see explanation of the options below). For each reference found, cscope outputs a line consisting of the file name, function name, line number, and line text, separated by spaces.
  2. Use awk to extract the function name $2 and file name $1 separated by #. Change $2, $1 and the separator # if you need other output fields or separator.
  3. Sort the output with sort.
  4. Get unique items with uniq.

cscope options (see http://cscope.sourceforge.net/cscope_man_page.html):

  • -R Recurse subdirectories for source files.

  • -L Do a single search with line-oriented output when used with the -num pattern option.

  • -2 ".*" Go to input field num (here 0-based field 2) and find pattern (here .* for all). You can see the input fields in cscope's screen mode. This may vary depending on the version you are using. The fields for version 15.8a under debian are:

    • 0: Find this C symbol:
    • 1: Find this global 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:

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...