Friday, November 2, 2012

Working with cscope (Code browsing tool)


what is cscope: 
A linux based code browsing tool  like source insight in windows

How to install :

type : $ sudo apt-get install cscope 

generating DB :
 android_source:~$cscope -R    (this will parse all the sub directories , cscope.out file will generate as a result)
 android_source:~$sh script.sh (run the attached script file which will generate DB for us ... check out the script file below)

How to use:
 android_source:~$ cscope -d

now you can enter which string you want to search or function etc 

imp.keys

ctrl+d : quit the cscope terminal
ctrl+j : find the definition
ctrl+t : last position
cscope -b : to rebuild the database

script file

#!/bin/bash

echo "Listing Android files ..."

find "$PWD/bionic"                                                          \
"$PWD/abi"                                                                  \
"$PWD/bootable"                                                             \
"$PWD/build"                                                                \
"$PWD/dalvik"                                                               \
"$PWD/development"                                                          \
"$PWD/device"                                                               \
"$PWD/external"                                                             \
"$PWD/frameworks"                                                           \
"$PWD/hardware"                                                             \
"$PWD/packages"                                                             \
"$PWD/system"                                                               \
"$PWD/vendor"                                                               \
-name '*.java' -print -o                                               \
-name '*.aidl' -print -o                                               \
-name '*.hpp' -print -o                                                \
-name '*.cpp'  -print -o                                               \
-name '*.xml'  -print -o                                               \
-name '*.mk'  -print -o                                                \
-name '*.[chxsS]' -print > cscope.files

echo "Listing Kernel files ..."
find  kernel                                                           \
-path "kernel/arch/*" -prune -o                                        \
-path "kernel/tmp*" -prune -o                                          \
-path "kernel/Documentation*" -prune -o                                \
-path "kernel/scripts*" -prune -o                                      \
-name "*.[chxsS]" -print >> cscope.files

find "$PWD/kernel/arch/arm/include/"                                        \
"$PWD/kernel/arch/arm/kernel/"                                              \
"$PWD/kernel/arch/arm/common/"                                              \
"$PWD/kernel/arch/arm/boot/"                                                \
"$PWD/kernel/arch/arm/lib/"                                                 \
"$PWD/kernel/arch/arm/mm/"                                                  \
"$PWD/kernel/arch/arm/mach-msm/" -name "*.[chxsS]" -print >> cscope.files

echo "Creating cscope DB ..."
/usr/bin/cscope -b -q -k
echo "Done"

No comments:

Post a Comment