How to Make Cscope Display Full File Paths During Search

How to make cscope display full file paths during search

Run cscope with args -pn

-pn Display the last n file path components instead of the default (1). Use 0 not to display the file name at all.

Running with cscope -p4 and searching for global definition of __switch_to results in

Global definition: __switch_to

File Line
0 arch/arm64/kernel/process.c 297 struct task_struct *__switch_to(struct task_struct *prev,
1 ia64/include/asm/switch_to.h 44 #define __switch_to(prev,next,last) do { \
2 arch/openrisc/kernel/process.c 202 struct task_struct *__switch_to(struct task_struct *old,
3 arch/powerpc/kernel/process.c 400 struct task_struct *__switch_to(struct task_struct *prev,
4 arch/sh/kernel/process_32.c 211 __switch_to(struct task_struct *prev, struct task_struct *next)
5 arch/um/kernel/process.c 80 void *__switch_to(struct task_struct *from, struct task_struct *to)
6 arch/x86/kernel/process_32.c 248 __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
7 arch/x86/kernel/process_64.c 272 __switch_to(struct task_struct *prev_p, struct task_struct *next_p)

Cscope relative path with parent directory display error

I found out later that its nothing to do with relative path, if the file is in dos line ending format, it is not displayed in cscope window. Use '!dos2unix %' from vi to overcome this error.

how can I display all function name from cscope database?

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:

print absolut path of symbolic links for Cscope

Use readlink or realpath should do the trick.

readlink -f symlinkName
realpath symlinkName

You can use them directly in your find command.
Example :

find . -exec realpath {} \;

How can I run cscope to search source code in an arbitrary location only and write the cross-reference files in another arbitrary location?

the trick here is knowing the cscope will also accept a list a sources files rather than searching on its own. So passing the list of files is the problem to solve.

find to the rescue.

cscope -b -f <path_to_refdir>/cscope.out `find <path_of_desired_src_tree> -name *.[chly]`

in your case

cscope -b -f work/cscope.out `find src/bar -name *.[chly]`


Related Topics



Leave a reply



Submit