When I generate Linux kernel cscope database by issuing make cscope
I get database file along with a list of files with relative path. This is a problem for me because later on when I attach that external kernel's database in vim editor from whatever directory but kernel's I can easily search for specific symbol BUT I can't open file that symbol is contained in.
I've written the next bash script
#!/bin/bash
SNAME="$0"
SNAME=${SNAME##*/}
function usage()
{
echo Generate Linux kernel cscope database
echo "Usage: $SNAME [PATH]"
echo -n "You must provide this script with an ABSOLUTE path of your "
echo "kernel's root directory"
}
if [[ -z "$1" ]]; then
usage
exit -1
fi
KDIR="$1"
echo -n "Collecting a list of files... "
if find "$KDIR" -path "${KDIR}/arch/*" ! -path "${KDIR}/arch/x86*" -prune -o \
-path "${KDIR}/include/asm-*" \
! -path "${KDIR}/include/asm-generic*" \
! -path "${KDIR}/include/asm-x86*" -prune -o \
-path "${KDIR}/tmp*" -prune -o \
-path "${KDIR}/Documentation*" -prune -o \
-path "${KDIR}/scripts*" -prune -o \
-name "*.[chxsS]" -print > cscope.files; then
echo done
else
echo failed
fi
echo -n "Building cscope database... "
cscope -k -qb && echo done || echo failed
that collects all files I need (x86/x86_64 architecture) using absolute path and then I successfully build cscope database manually. But I think it must be some easier way to accomplish this. Maybe some Makefile's target like make cscope_abs
or make cscope_ext
that I have not found yet.
Any suggestions?
cscope is an interactive program that locates specified elements of code in C, lex, or yacc source files. With cscope, you can search and edit your source files more efficiently than you could with a typical editor.
There are a few easy steps required to start using Cscope. First, you need to tell it where all of your source code files are. Second, you need to generate the Cscope database. Finally, you can launch the Cscope browser to search for functions and symbols in your source code.
cscope is a programming tool which works in console mode, text-based interface, that allows computer programmers or software developers to search source code of the programming language C, with some support for C++ and Java.
First, it is simpler to create a cscope database specific to a particular architecture as follows : In Linux kernel's top folder, run
ARCH=x86 make cscope
This creates a cscope with relative paths. Now you can ask vim to interpret the paths relative to the location of the cscope.out file in one of two ways:
Way 1 : Use cscoperelative
. Output of :help csre
:
If 'cscoperelative' is set, then in absence of a prefix given to cscope
(prefix is the argument of -P option of cscope), basename of cscope.out
location (usually the project root directory) will be used as the prefix
to construct an absolute path. The default is off. Note: This option is
only effective when cscope (cscopeprg) is initialized without a prefix
path (-P). Examples: >
:set csre
:set nocsre
Way 2 : (From Aaron Hs' answer in this question) When adding the cscope database in vim, specify base location. Example:
:cs add <base_location>/cscope.out <base_location>/
From vim's help page for cscope add:
USAGE :cs add {file|dir} [pre-path] [flags]
[pre-path] is the pathname used with the -P command to cscope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With