DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Browsing through your code with cscope

Step 3: locate the code

Now you can begin to identify the problem that is causing the error message out of storage to be printed. You have invoked cscope, and the cross-reference table has been built. The cscope menu of tasks appears on the screen:

   cscope                   			Press the ? key for help
   

Find this C symbol: Find this global definition: Find functions called by this function: Find functions calling this function: Find this text string: Change this text string: Find this egrep pattern: Find this file: Find files #including this file:

The cscope Menu of Tasks

Press the <RETURN> or <Enter> key to move the cursor down the screen (with wraparound at the bottom of the display), and <Ctrl-p> to move the cursor up; or use the up (<UP ARROW>) and down (<DOWN ARROW>) arrow keys if your keyboard has them. You can

manipulate the menu, and perform other tasks, with the following single-key commands:

<TAB> move to next input field
<RETURN> move to next input field
<Ctrl-n> move to next input field
<Ctrl-p> move to previous input field
<Ctrl-y> search with the last pattern typed
<Ctrl-b> move to previous input field
  and search pattern
<Ctrl-f> recall next input field and
  search pattern
<Ctrl-c> toggle ignore/use letter case
  when searching (a search
  for FILE will match, for
  example, File and file
  when ignoring letter case)
<Ctrl-r> rebuild the cross-reference
<!> start an interactive shell
  (type <Ctrl-d> to return to cscope)
<Ctrl-l> redraw the screen
<?> display list of commands
<Ctrl-d> exit cscope

Menu Manipulation Commands

If the first character of the text for which you are searching matches one of these commands, you can escape the command by entering a backslash (<\>) before the character.

Now move the cursor to the fifth menu item, Find this text string, enter the text out of storage, and press the <RETURN> key:

   cscope 						Press the ? key for help
   

Find this C symbol: Find this global definition: Find functions called by this function: Find functions calling this function: Find this text string: out of storage Change this text string: Find this egrep pattern: Find this file: Find files #including this file:

Requesting a Search for a Text String


NOTE: Follow the same procedure to perform any other task listed in the menu except the sixth, Change this text string. Because this task is slightly more complex than the others, there is a different procedure for performing it. For a description of how to change a text string, see ``Examples''.

cscope searches for the specified text, finds one line that contains it, and reports its finding as follows:

   Text string: out of storage
   

File Line 1 alloc.c 63 (void) fprintf(stderr, "\\n%s: out of storage\\n", argv0);

Find this C symbol: Find this global definition: Find functions called by this function: Find functions calling this function: Find this text string: Change this text string: Find this egrep pattern: Find this file: Find files #including this file:

cscope Lists Lines Containing the Text String

After cscope shows you the results of a successful search, you have several options. You may want to change the lines or examine the code surrounding it in the editor. Or, if cscope has found so many lines that a list of them will not fit on the screen at once, you may want to look at the next part of the list. You can even

filter out unwanted lines from the list cscope has found. The following table shows the commands available after cscope has found the specified text:

1-9 edit the file referenced by this line (the
  number you type corresponds to an item
  in the list of lines printed by cscope)
space bar display next set of matching lines
+ display next set of matching lines
Ctrl-v display next set of matching lines
- display previous set of matching lines
Ctrl-e edit displayed files in order
> write the list of lines being displayed to a file
>> append the list of lines being displayed to a file
< read lines from a file
^ filter all lines through a shell command,
  replacing the lines originally found with the output of the
  shell command
| pipe all lines to a shell command, displaying the
  output of the shell command without changing
  the list of lines found

Commands for Use after Initial Search

If the first character of the text for which you are searching matches one of these commands, you can escape the command by entering a backslash before the character.

Now examine the code around the newly found line. Enter 1 (the number of the line in the list). The editor will be invoked with the file alloc.c; the cursor will be at the beginning of line 63 of alloc.c:

   {
           return(alloctest(realloc(p, (unsigned) size)));
   }
   

/* check for memory allocation failure */

static char * alloctest(p) char *p; { if (p == NULL) { (void) fprintf(stderr, "\\n%s: out of storage\\n", argv0); exit(1); } return(p); } ~ ~ ~ ~ ~ ~ ~ "alloc.c" 67 lines, 1283 characters

Examining a Line of Code Found by cscope

You can see that the error message is generated when the variable p is NULL. To determine how an argument passed to alloctest() could have been NULL, you must first identify the functions that call alloctest().

Exit the editor by using normal quit conventions. You are returned to the menu of tasks. Now type alloctest after the fourth item, Find functions calling this function:

   Text string: out of storage
   

File Line 1 alloc.c 63 (void) fprintf(stderr, "\\n%s: out of storage\\n", argv0);

Find this C symbol: Find this global definition: Find functions called by this function: Find functions calling this function: alloctest Find this text string: Change this text string: Find this egrep pattern: Find this file: Find files #including this file:

Requesting a List of Functions That Call alloctest()


cscope finds and lists three such functions:

   Functions calling this function: alloctest
   

File Function Line 1 alloc.c mymalloc 33 return(alloctest(malloc((unsigned) size))); 2 alloc.c mycalloc 43 return(alloctest(calloc((unsigned) nelem, (unsigned) size))); 3 alloc.c myrealloc 53 return(alloctest(realloc(p, (unsigned) size)));

Find this C symbol: Find this global definition: Find functions called by this function: Find functions calling this function: Find this text string: Change this text string: Find this egrep pattern: Find this file: Find files #including this file:

cscope Lists Functions That Call alloctest()


Now you want to know which functions call mymalloc(). cscope finds ten such functions. It lists nine of them on the screen and instructs you to press the space bar to see the rest of the list:

   Functions calling this function: mymalloc
   

File Function Line 1 alloc.c stralloc 24 return(strcpy(mymalloc(strlen(s) + 1), s)); 2 crossref.c crossref 47 symbol = (struct symbol *) mymalloc(msymbols * sizeof(struct symbol)); 3 dir.c makevpsrcdirs 63 srcdirs = (char **) mymalloc(nsrcdirs * sizeof(char *)); 4 dir.c addincdir 167 incdirs = (char **) mymalloc(sizeof(char *)); 5 dir.c addincdir 168 incnames = (char **) mymalloc(sizeof(char *)); 6 dir.c addsrcfile 439 p = (struct listitem *) mymalloc(sizeof(struct listitem)); 7 display.c dispinit 87 displine = (int *) mymalloc(mdisprefs * sizeof(int )); 8 history.c addcmd 19 h = (struct cmd *) mymalloc(sizeof(struct cmd)); 9 main.c main 212 s = mymalloc((unsigned ) (strlen(reffile) + strlen(home) + 2));

* 9 more lines - press the space bar to display more * Find this C symbol: Find this global definition: Find functions called by this function: Find functions calling this function: Find this text string: Change this text string: Find this egrep pattern: Find this file: Find files #including this file:

cscope Lists Functions That Call mymalloc()


Because you know that the error message out of storage is generated at the beginning of the program, you can guess that the problem may have occurred in the function dispinit() (display initialization). To view dispinit(), the seventh function on the list, type 7:

   void
   dispinit()
   {
           /* calculate the maximum displayed reference lines */
           lastdispline = FLDLINE - 4;
           mdisprefs = lastdispline - REFLINE + 1;
           if (mdisprefs > 9) {
                   mdisprefs = 9;
           }
           /* allocate the displayed line array */
           displine = (int *) mymalloc(mdisprefs * sizeof(int));
   }
   ^L/* display a page of the references */
   

void display() { char file[PATHLEN + 1]; /* file name */ char function[PATLEN + 1]; /* function name */ char linenum[NUMLEN + 1]; /* line number */ int screenline; /* screen line number */ int width; /* source line display width */ register int i, j; "display.c" 622 lines, 14326 characters

Viewing dispinit() in the Editor

mymalloc() failed because it was called either with a very large number or a negative number. By examining the possible values of FLDLINE and REFLINE, you can see that there are scenarios in which the value of ``mdisprefs'' is negative.


Next topic: Step 4: edit the code
Previous topic: Step 2: invoke cscope

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004