cscope info

Ed Sutter els at emailbox.hdtv.lucent.com
Wed Jul 30 12:17:09 UTC 2003


Folks,
If anyone out there uses cscope (priceless tool IMHO), here is
a quick script to "help" get an accurate file list started
(thanks Chris Johns)...

   NM --line-numbers BUILD_IMAGE | \
      awk "/ / { if (\$4) print \$4; }" | \
      sed 's/\:.*//p' | sort -u >cscope.files

where...
NM is the target-specific symbol-table-generator (e.g. powerpc-rtems-nm)
BUILD_IMAGE is the name of the executable image (e.g. some elf file)
that contains the symobl table.

Note that this isn't perfect for several reasons (so please improve it and
share it!)...
1. The output of the --line-numbers option to NM does not build the
   relative paths properly (not sure why).  For example, one entry in the
   output may be:
   ../../../../../rtems-4.6.0pre4/c/src/lib/libbsp/powerpc/gen405/startup/bspclean.c
   but the preceding "../../../../.." may not be right.

2. This only includes the files that actually originate symbols, so no header files
   are in this list.  One crude way to add headers is to just use find...
   find BASEDIR -name '*.h' >>cscope.files
   (where BASEDIR is top level of your RTEMS tree).
   Bad thing about this is that it pulls in ALL header files, so the output must
   be parsed.  A more accurate list of headers could probably be derived from
   the output of "gcc -MM" (used to build a file dependency list), but I haven't
   done that yet.


Good & bad...
Cscope is a really nice tool as long as it is given the proper set of source
files.  The "NM --line-numbers" helps to make sure that the .c & .s files in
the list are the right ones.
The messy part is that it isn't perfect, there is still a lot of hacking that
needs to be done on the file list... adjust the relative path of the files
(mentioned above) and remove the .h files that are not part of your target build.

Despite this required bit of manual labor, it still is a good start for creating an
accurate file list for cscope.

By the way, for those who use CTAGS, this file list can then be used to build the 
tags file.  If you use Exuberant Ctags, then the line:
   ctags -L cscope.files --file-tags=yes -n 
builds a complete tag list that includes filenames.

If interested, cscope and exuberant ctags are at sourceforge
Ed



More information about the users mailing list