DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Using programming tools

Using cscope

The purpose of cscope is to build a database containing information about functions, function calls, macros, and variables. cscope allows you to look at functions and examine the lines of code around those functions. In the testcase.c example, all the functions are contained in the one file. If, however, functions that are called from testcase.c were located in other files (excluding system library functions), cscope would allow you to look directly at those functions without exiting cscope. While using cscope on testcase.c might not be extremely helpful, it may still be of interest.

To examine the functions within testcase.c, run cscope as follows:

   cscope testcase.c
To move the cursor to a menu option, press the <Return> key. To examine the function main, move the cursor to "List functions called by this function:", enter main, and press <Return>:
   cscope                                Press the ? key for help
   

List references to this C symbol: Edit this function or #define: List functions called by this function: main List functions calling this function: List lines containing this text string: Change this text string: List file names containing this text string:

The display lists the three functions called by main: gets, GetWords and PrintWords. Displayed along with the function names is the source code line that contains the function.
   Functions called by this function: main
   

File Function Line 1 testcase.c gets 85 while(gets(buf) != (char *)NULL) { 2 testcase.c GetWords 86 WordCount = GetWords(buf); 3 testcase.c PrintWords 87 PrintWords(WordCount, match); }

List references to this C symbol: Edit this function or #define: List functions called by this function: GetWords List functions calling this function: List lines containing this text string: Change this text string: List file names containing this text string:

By examining the GetWords function, we can move deeper into the code:
   Functions called by this function: GetWords

File Function Line 1 testcase.c strlen 45 int end = strlen(buf); 2 testcase.c isspace 55 if (!isspace(*cp)) { 3 testcase.c isspace 61 if (isspace(*cp)) {

List references to this C symbol: Edit this function or #define: List functions called by this function: List functions calling this function: List lines containing this text string: Change this text string: List file names containing this text string:

In analyzing the results, we see that GetWords calls three functions displayed with their line numbers in the source code.

Using cscope is particularly helpful when examining a large or complex program that has many files that span several directories. For more information, see ``C programmer's productivity tools'' and cscope(CP).


Next topic: Using lint
Previous topic: Using cb

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003