Using Sun WorkShop

Source Browsing Databases

The Source Browser obtains the information it uses from a database that describes the static structure of your program. To use source browsing, you must first create a source browsing database by adding the -xsb option to your compilation command or your makefile.

The browser has different levels of functionality depending upon the database it accesses:

Compiler-generated database 

use full browser functionality 

Tags-generated database 

Allows queries on functions and global variables and can display function calls. Graphing features are not available. 

No database 

Must use the Pattern Search mode of the Source Browser. 

Using a tags-generated database has some advantages over using a database generated by a compiler:

Generating a Browser Database

When you compile your source files with the source browser option, Sun WorkShop creates a database containing information about the files. The Source Browser responds to queries by searching through this database.

When you create a compiler-generated database, you can access all browsing features.

To generate the browsing database, add the source browser option to your makefile:

Language 

Compiler Source Browser Option 

C++ 

-xsb or -sb

ANSI C 

-xsb

FORTRAN 77 

-xsb or -sb

Assembler 

-b

Creating a Tags Database

A tags database provides a quick and convenient method for browsing source files without compilation. The database is based on a lexical analysis of the source file. It will not always correctly identify all language constructs, but it will operate on files that you cannot compile.


Note -

The source browsing tags are not in the same format as ctags; the tags discussed here are in a format that works specifically with source browsing.


If you browse using a tags database, you:

A tags database recognizes only global definitions for variables, types, and functions, and collects information on function calls. Function calls for C++ members are recognized only when called explicitly.

To create a tags database:

  1. From the Browsing window, choose Browse > Create Tags Database.

  2. In the Create Tags Database dialog box, click OK to accept the default file filter or enter the type of files you want to scan and click OK.

    The browser creates the tags database.

Searching Multiple Directories

If you keep your source files in several different directories, you are likely to execute the compiler in each of these directories. As a result, the default compiler behavior generates a separate source browser database in each directory.

Since the Source Browser looks at only one database at a time, only the part of your application located in the current directory is searched. You can override this default behavior by importing databases.

Importing Databases

Instead of merging separate databases, you can import databases. Use the sb_init file to read more than one database. You can start browsing in the same directory that holds the sb_init file.

To import databases:

  1. Identify where your sb_init file resides.

  2. Add an import command to the sb_init file for each directory in which the compiler is executed:

    import absolute_or_relative_pathname

  3. Set your SUNPRO_SB_INIT_FILE_NAME environment variable to point to your sb_init file.

    Add the following line to your .login file:

    setenv SUNPRO_SB_INIT_FILE_NAME path to sb_init file/sb_init


Note -

Use the import option to search your entire source tree for source files and browser databases. Just add an import command to the sb_init file for each directory in your source tree.



Note -

Because pattern searching uses sb_init to search source files in multiple directories, and source browsing uses sb_init to search browser databases (which include object files) in multiple directories, you may want to include import commands for both source and object directories in your sb_init file.