Creation Zone

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 15 November 2004

UNIX/C: cscope - an interactive program examiner

Posted on 16:53 by Unknown


cscope is an interactive program that locates specified elements of code in C,

C++, lex, or yacc source files. cscope is a very useful utility to browse through

the source code tree of a large project. It is a text-mode screen-oriented utility.



When cscope is called for a set of C, C++, lex, or yacc source files, it builds a

symbol cross-reference table for the functions, function calls, macros, variables,

and preprocessor symbols in those files. You can then query that table about the

locations of symbols you specify.



At First, cscope presents a menu and asks you to choose the type of search you

would like to perform. You may, for instance, want cscope to find all the

functions that call a specified function. When it completes the search, cscope

prints a list. Each list entry contains the name of the file, the number of the line,

and the text of the line in which cscope has found the specified code. In our case,

the list also includes the names of the functions that call the specified function.

We now have the option of requesting another search or examining one of the

listed lines with the editor. If we choose the latter, cscope invokes the editor (vi)

for the file in which the line appears, with the cursor on that line. We can now

view the code in context and, if we wish, edit the file as any other file. By simply

using vi editor's edit keys we can either navigate through the code or return back

to the menu to request a new search.



Lets try building symbol cross-reference table & search for some symbols using

cscope



bpte4500s001:/sunbuild1/giri/testcases/cscope/%ls

hidden.cpp hidden.h hide.cpp htest.cpp test.h

testcase.cpp x.cpp x.h



bpte4500s001:/sunbuild1/giri/testcases/cscope/%which cscope

/home/sundev/S1S9/SUNWspro/bin/cscope


^^^^

cscope is part of Sun Studio Compiler Collection



By default, cscope builds a symbol cross-reference table for all the C, C++, lex,

and yacc source files in the current directory, and for any included header files in

the current directory or the standard place. So, if all the source files for the

program to be browsed are in the current directory, and if its header files are

there or in the standard place, invoke cscope without arguments




bpte4500s001:/sunbuild1/giri/testcases/cscope/%cscope

---------------------------------------------------------------------

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:

---------------------------------------------------------------------



cscope builds the symbol cross-reference table the first time it is used on the

source files for the program to be browsed. By default, the table is stored in the

file "cscope.out" in the current directory. On a subsequent invocation, cscope

rebuilds the cross-reference only if a source file has been modified or the list of

source files is different




bpte4500s001:/sunbuild1/giri/testcases/cscope/%ls

cscope.out hidden.cpp hidden.h hide.cpp

htest.cpp test.h testcase.cpp x.cpp x.h




bpte4500s001:/sunbuild1/giri/testcases/cscope/%file cscope.out

cscope.out: data



bpte4500s001:/sunbuild1/giri/testcases/cscope/%cat hidden.h

__declspec(dllexport) char *lastname(char *);

//char *lastname(char *);

__declspec(dllexport)

int agefunc();

__declspec(dllexport)

char firstchar(char *);



Now lets try to locate the function "lastname" using cscope



---------------------------------------------------------------------

C symbol: lastname



File Function Line

1 hidden.h __declspec 1 __declspec(dllexport) char *lastname(char *);







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:


---------------------------------------------------------------------



After cscope shows you the results of a successful search, you have several

options. You may want to change one of the lines or examine the code

surrounding it in the editor. Or, if cscope has found so many lines that a list of

them does not fit on the screen at once, you may want to look at the next part of

the list.



If you want to open up "hidden.h", just press 1; it opens up "hidden.h" in vi

editor. If more than one file has the designated symbol, we just need to press

the number that is besides the file name which we want to edit. If the search

yields more results and if all the results doesn't fit in a single screen, we need

to press "space bar" to go to the next screen. To go back to the previous screen,

we need to press "--"



NOTE:

If the source code of a project is spread over different directories we need to get

the list of files (with the path) and save the list in a file called "cscope.files".

Then run cscope to build the symbol cross-reference table & to show the menu.

Once the symbol cross-reference table is ready & if there are no changes in the

source code, invoke cscope with "-d" flag from subsequent executions. "-d"

instructs cscope not to update the cross-reference




bpte4500s001:/sunbuild1/giri/testcases/cscope/%ls -ld *

drwxrwxr-x 2 build engr 512 Nov 15 16:44 hidden

-rw-r--r-- 1 build engr 79 Nov 15 16:18 htest.cpp

drwxrwxr-x 2 build engr 512 Nov 15 16:44 test

drwxrwxr-x 2 build engr 512 Nov 15 16:44 x



bpte4500s001:/sunbuild1/giri/testcases/cscope/%ls -lR *

-rw-r--r-- 1 build engr 79 Nov 15 16:18 htest.cpp



hidden:

total 6

-rw-r--r-- 1 build engr 320 Nov 15 16:18 hidden.cpp

-rw-r--r-- 1 build engr 155 Nov 15 16:18 hidden.h

-rw-r--r-- 1 build engr 358 Nov 15 16:18 hide.cpp



test:

total 4

-rw-rw-r-- 1 build engr 42 Nov 15 16:18 test.h

-rw-rw-r-- 1 build engr 354 Nov 15 16:18 testcase.cpp



x:

total 4

-rw-r--r-- 1 build engr 60 Nov 15 16:18 x.cpp

-rw-r--r-- 1 build engr 47 Nov 15 16:18 x.h



bpte4500s001:/sunbuild1/giri/testcases/cscope/%cscope

cscope: no source files found



bpte4500s001:/sunbuild1/giri/testcases/cscope/%find . -name "*" > cscope.files



bpte4500s001:/sunbuild1/giri/testcases/cscope/%ls

cscope.files hidden htest.cpp test x



bpte4500s001:/sunbuild1/giri/testcases/cscope/%cscope

(.. skipped cscope menu ..)



bpte4500s001:/sunbuild1/giri/testcases/cscope/%ls

cscope.files hidden test

cscope.out htest.cpp x



Note:

If cscope throws an error message like "Input string too long, limit 50251",

run truss on cscope and observe the last few lines to find the culprit and remove

it from cscope.files to let cscope continue building the symbol database



Courtesy:

Sun Microsystems, Sun Studio 9: C User's Guide
Email ThisBlogThis!Share to XShare to Facebook
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • *nix: Workaround to cannot find zipfile directory in one of file.zip or file.zip.zip ..
    Symptom: You are trying to extract the archived files off of a huge (any file with size > 2 GB or 4GB, depending on the OS) ZIP file with...
  • C/C++: Printing Stack Trace with printstack() on Solaris
    libc on Solaris 9 and later, provides a useful function called printstack , to print a symbolic stack trace to the specified file descripto...
  • JDS: Installing Sun Java Desktop System 2.0
    This document will guide you through the process of installing JDS 2.0 on a PC from integrated CDROM images Requirements I...
  • Binary compatibility
    What's It? "Binary compatibility" (BC) is the ability of one machine to run software that was written for another without hav...
  • Solaris: NULL pointer bugs & /usr/lib/0@0.so.1 library
    Some programmers assume that a NULL character pointer is the same as a pointer to a NULL string. However de-referencing a NULL pointer (ie.,...
  • Database: Oracle Server Architecture (overview)
    Oracle server consists of the following core components: 1) database(s) & 2) instance(s) 1) database consists of: 1) datafil...
  • Sun: OpenJDK
    Open source JDK, that is. Sun Microsystems did it again -- As promised during JavaOne event back in May 2006, Sun made the implementation of...
  • Consolidating Siebel CRM 8.0 on a Single Sun SPARC Enterprise Server, T5440
    .. blueprint document is now available on wikis.sun.com . Here is the direct link to the blueprint:              Consolidating Oracle Siebel...
  • Oracle Internet Directory 11g Benchmark on SPARC T5
    SUMMARY System Under Test (SUT)     Oracle's SPARC T5-2 server Software     Oracle Internet Directory 11 g R1-PS6 Target Load     50...
  • Fix to Firefox 3 Crash on Solaris 10 x86
    Symptom : Firefox 3 crashes on Solaris 10 x86 when the web browser tries to render some of the HTML pages with SWF content in them. For exam...

Categories

  • 80s music playlist
  • bandwidth iperf network solaris
  • best
  • black friday
  • breakdown database groups locality oracle pmap sga solaris
  • buy
  • deal
  • ebiz ebs hrms oracle payroll
  • emca oracle rdbms database ORA-01034
  • friday
  • Garmin
  • generic+discussion software installer
  • GPS
  • how-to solaris mmap
  • impdp ora-01089 oracle rdbms solaris tips upgrade workarounds zombie
  • Magellan
  • music
  • Navigation
  • OATS Oracle
  • Oracle Business+Intelligence Analytics Solaris SPARC T4
  • oracle database flashback FDA
  • Oracle Database RDBMS Redo Flash+Storage
  • oracle database solaris
  • oracle database solaris resource manager virtualization consolidation
  • Oracle EBS E-Business+Suite SPARC SuperCluster Optimized+Solution
  • Oracle EBS E-Business+Suite Workaround Tip
  • oracle lob bfile blob securefile rdbms database tips performance clob
  • oracle obiee analytics presentation+services
  • Oracle OID LDAP ADS
  • Oracle OID LDAP SPARC T5 T5-2 Benchmark
  • oracle pls-00201 dbms_system
  • oracle siebel CRM SCBroker load+balancing
  • Oracle Siebel Sun SPARC T4 Benchmark
  • Oracle Siebel Sun SPARC T5 Benchmark T5-2
  • Oracle Solaris
  • Oracle Solaris Database RDBMS Redo Flash F40 AWR
  • oracle solaris rpc statd RPC troubleshooting
  • oracle solaris svm solaris+volume+manager
  • Oracle Solaris Tips
  • oracle+solaris
  • RDC
  • sale
  • Smartphone Samsung Galaxy S2 Phone+Shutter Tip Android ICS
  • solaris oracle database fmw weblogic java dfw
  • SuperCluster Oracle Database RDBMS RAC Solaris Zones
  • tee
  • thanksgiving sale
  • tips
  • TomTom
  • windows

Blog Archive

  • ►  2013 (16)
    • ►  December (3)
    • ►  November (2)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (2)
    • ►  January (1)
  • ►  2012 (14)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (2)
  • ►  2011 (15)
    • ►  December (2)
    • ►  November (1)
    • ►  October (2)
    • ►  September (1)
    • ►  August (2)
    • ►  July (1)
    • ►  May (2)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2010 (19)
    • ►  December (3)
    • ►  November (1)
    • ►  October (2)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (5)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2009 (25)
    • ►  December (1)
    • ►  November (2)
    • ►  October (1)
    • ►  September (1)
    • ►  August (2)
    • ►  July (2)
    • ►  June (1)
    • ►  May (2)
    • ►  April (3)
    • ►  March (1)
    • ►  February (5)
    • ►  January (4)
  • ►  2008 (34)
    • ►  December (2)
    • ►  November (2)
    • ►  October (2)
    • ►  September (1)
    • ►  August (4)
    • ►  July (2)
    • ►  June (3)
    • ►  May (3)
    • ►  April (2)
    • ►  March (5)
    • ►  February (4)
    • ►  January (4)
  • ►  2007 (33)
    • ►  December (2)
    • ►  November (4)
    • ►  October (2)
    • ►  September (5)
    • ►  August (3)
    • ►  June (2)
    • ►  May (3)
    • ►  April (5)
    • ►  March (3)
    • ►  February (1)
    • ►  January (3)
  • ►  2006 (40)
    • ►  December (2)
    • ►  November (6)
    • ►  October (2)
    • ►  September (2)
    • ►  August (1)
    • ►  July (2)
    • ►  June (2)
    • ►  May (4)
    • ►  April (5)
    • ►  March (5)
    • ►  February (3)
    • ►  January (6)
  • ►  2005 (72)
    • ►  December (5)
    • ►  November (2)
    • ►  October (6)
    • ►  September (5)
    • ►  August (5)
    • ►  July (10)
    • ►  June (8)
    • ►  May (9)
    • ►  April (6)
    • ►  March (6)
    • ►  February (5)
    • ►  January (5)
  • ▼  2004 (36)
    • ►  December (1)
    • ▼  November (5)
      • UNIX: Terminology I
      • C++: Name Mangling
      • UNIX/C: cscope - an interactive program examiner
      • Sun C/C++: Installed Components & Version#s
      • JDS: Linux & Sony DSC-V1/W1 Digital Camera
    • ►  October (12)
    • ►  September (18)
Powered by Blogger.

About Me

Unknown
View my complete profile