| Introduction to Sun WorkShop |
Source Browsing With
sbquery,sb_init, andsbtags
- Describes
sbquery, one of the command-line utilities for browsing source code- Tells you how to work with source files where database information is stored in multiple directories
- Describes the
sbtagscommand, which provides a quick and convenient method for collecting browsing information from source filesThe information in this chapter pertains mainly to the use of the command line to complete tasks also available from within Sun WorkShop. For more conceptual information on using source browsing, see Chapter 5 and the Browsing Source Code section of the online help (you can access the online help through the Help menu in any Sun WorkShop window).
The
sbqueryUtilityThe
sbqueryutility provides you with a command-line browsing environment that you can access from terminals and from workstations emulating terminals. By default,sbquerysearches for symbols in the database in the current working directory. If you want to browse a database stored in another directory, see The sb_init File and Commands.To issue a query from the command line, type
sbquery, followed by any command-line options and their arguments, followed by the symbol you want to search for:
%sbquery[options] symbols
sbquerydisplays a list of matches that includes the file in which the symbol appears, the line number, the function containing the symbol, and the source line containing the symbol.Options
To obtain a list of the
sbquerycommand-line options, typesbqueryat the shell prompt. TABLE D-1 lists and describes the options (see also thesbquery(1) man page).
TABLE D-1 sbqueryOptions-patternsymbolQueries on symbol, which may contain special characters, including a leading dash ( -). This option allows you to query on a symbol that looks like a command-line option. For instance, you can query on the symbol-help, andsbquerydistinguishes it from the regular option-help.-break_lockBreaks the lock on a locked database. This argument might be needed if the update of the index file is aborted. The next time you issue a query you might get a message telling you that the database is locked. After using this option, your database may be in an inconsistent state. To ensure consistency, remove the database directory and recompile your program. -files_onlyLists only the files where the symbols you are searching for appear. -helpDisplays a synopsis of the sbquerycommand. Equivalent to typingsbquerywith no options and no symbol.-help_focusDisplays a list of the focus options available for querying only specific program types in a directory. Use focus options (see TABLE D-3) to issue a query limited to specific units of code such as programs or functions. -help_filterlanguageDisplays a list of the languages for which filter options are available for -help_filter. Displays a list of the filter options for the language for-help_filterlanguage. Use filter options (see TABLE D-2) to search for symbols based on how they are used in a program.max_memorysizeSets the approximate amount of memory in megabytes that should be allocated before sbqueryuses temporary files when building the index file.-no_caseMakes the query case-insensitive. -no_sourceDisplays only the file name and line number associated with each match and not the source line containing the match. -no_updateDoes not rebuild the index file when you issue a query following compilation. If you do not include this option and issue a query following compilation or recompilation, then the database updates and processes your query. -ofileSends query output to file. -show_db_dirsLists all database directories scanned when you issue a query. The list includes the following: the database directory in the current working directory and all other database directories specified by the importorexportcommands in yoursb_initfile.-symbols_onlyDisplays a list of all symbols that match the patterns in your search pattern. This is useful when you use wildcards in a query. -versionDisplays the current version number. -sh_patternUses shell-style expressions when issuing a query that includes wildcards. This wildcard setting is the default; include this option if you are doing other pattern matching on the same command line. See the sh(1) man page for more information about shell-style pattern matching.-reg_exprUses regular expressions when issuing a query that includes wildcards. If you do not include this option, shell-style patterns are assumed. -literalUses only literal strings and does not use any wildcard expressions for the query. This is useful when you want to search for a string that contains meta characters from other wildcard schemes.
Two types of options are available to help you narrow your search: filter options described in TABLE D-2 and focus options described in TABLE D-3.
The filter options are used to search for symbols based on how they are used in a program. For example, you could limit your search to declarations of variables.
%sbquery-help_filterlanguage
TABLE D-2 Filter Language Options ansi_cC sun_asAssembly language sun_c_plus_plusC++ sun_f77Fortran 77 sun_f90Fortran 90
The focus options listed in TABLE D-3 limit your search to specific classes of code, such as particular programs, functions, or libraries.
%sbqueryfocus-optionsymbol
Note If you include two or more focus options, a match is returned if it is found with any of the supplied focus options.
Environment Variables
Environment variables provide information that affects the operation of
sbquery(and source browsing in Sun WorkShop).
TABLE D-4 Environment Variables HOMEThe name of your login directory. PWDThe full path name of the current directory. SUNPRO_SB_ATTEMPTS_MAXThe maximum number of times the index builder tries to access a locked database. SUNPRO_SB_EX_FILE_NAMEThe absolute path name of the sun_source_browser.exfile.SUNPRO_SB_INIT_FILE_NAMEThe absolute path name of the sb_initfile. For more information onsb_init, see The sb_init File and Commands.
The
sb_initFile and CommandsThis section describes how to work with source files where database information is stored in multiple directories. As a default, the database is built in the current working directory and searches that database when you issue a query.
The text file
sb_initis used by the Source Browsing mode of Sun WorkShop, the compilers, andsbtagsto obtain control information about the source browsing database structure. Usesb_initif you want to work with source files whose database information is stored in multiple directories.The
sb_initfile should be placed in theSunWS_configdirectory, which should be placed in the directory from which source browsing, the compilers, andsbtagsare run. These tools look in the current working directory for thesb_initfile.The default is to look in the current working directory for the
sb_initfile. To instruct Sun WorkShop and the compiler to search for thesb_initfile in another directory, set the environment variableSUNPRO_SB_INIT_FILE_NAMEto
absolute-pathname/sb_init.To use an
sb_initcommand, add the command to thesb_initfile. Thesb_initfile is limited to the following commands:
import
%importpathnameThis command allows the Source Browsing mode of Sun WorkShop to read databases in directories other than the current working directory. Use of the
importcommand enables you to retain separate databases for separate directories.For example, you may want to set up administrative boundaries so that programmers working on Project A cannot write into directories for Project B and vice versa. In that case, Project A and Project B each need to maintain their own databases, both of which can then be read but not written by programmers working on the other project.
export
%exportprefixintopathThis command causes the compilers and
sbtagsto write database component files associated with source files to directories other than the current working directory used by the Source Browsing mode of Sun WorkShop and the compiler.Whenever the compiler processes a source file whose absolute path starts with prefix, the resulting browser database (
.bd)file is stored in path.The export command contains an implied
importcommand of path, so that exported database components are automatically read by the Source Browsing mode of Sun WorkShop.The
exportcommand enables you to save disk space by placing database files associated with identical files, such as#includefiles from/usr/include, in a single database, while still retaining distinct databases for individual projects.If your
sb_initfiles include multipleexportcommands, then you must arrange them from the most specific to the least specific. The compiler scansexportcommands in the same order that it encounters them in thesb_initfile.
replacepath
%replacepathfrom-prefix to-prefixThis command specifies how to modify path names in the source browsing database.
In general, from-prefix corresponds to the automounter mount point (the path name where the automounter actually mounts the file system); to-prefix corresponds to the automounter trigger point (the path name known and used by the developer).
There is considerable flexibility in how an automounter is used; the method can vary from host to host.
Path replacement rules are matched in the order that they are found, and matching stops after a replacement is done.
The default
replacepathcommand is used to strip away automounter artifacts:
%replacepath/tmp_mntWhen used for this purpose, the command should be given with the mount point as the first argument and the trigger point as the second argument.
automount-prefix
%automount-prefixmount-pointtrigger-pointThe
automount-prefixcommand enables you to browse on a machine other than the one on which you compiled your program. This command is identical to thereplacepathcommand except thatautomount-prefixpath translations occur at compile time and are written into the database.The
automount-prefixcommand defines which automounter prefixes to remove from the source names stored in the database. The directory under which the automounter mounts the file systems is the mount-point; the trigger-point is the prefix you use to access the exported file system. The default is/.If the path in the database fails, the path translations from both commands (that is,
automount-prefixandreplacepath) are used to search for source files while browsing.At first glance, searching both paths may not seem possible; the browser database that is created when you run the compiler contains the absolute path for each source file. If the absolute path is not uniform across machines, then Sun WorkShop will not be able to display the source files when it responds to a query.
To get around this problem, you can do one of the following:
- Ensure that all source files are mounted at the same mount point on all machines.
- Compile your programs in an automounted path. A reference to such a path causes the automounter to automatically mount a file system from another machine.
There is a default
automount-prefixcommand that is used to strip away automounter artifacts:
%automount-prefix/tmp-mnt/The default rule is generated only if no
automount-prefixcommands are specified.For more information on using the automounter, see the
automount(1M) man page.
cleanup-delayThis command limits the time elapsed between rebuilding the index and the associated database garbage collection. The compilers automatically invoke
sbcleanupif the limit is exceeded. The default value is 12 hours.The
sbtagsUtilityThe
sbtagscommand provides a method for collecting browsing information from source files, enabling you to collect minimal browsing information for programs that do not compile completely. See also thesbtags(1) man page.The
sbtagscommand collects a subset of the information available through compilation. The reduced information restricts some browsing functionality. A database generated bysbtagsenables you to perform queries on functions and variables and to display the function call graph.
- Cannot issue queries about local variables
- Cannot browse classes
- Cannot graph class relationships
- Has limited ability to issue complex queries
- Has limited ability to focus queries
- Has less reliability than compiled information
Once a file has been changed, it often need not be scanned again to incorporate changes into the database.
An
sbtagsdatabase is based on a lexical analysis of the source file. Though it does not always correctly identify all the language constructs, it will operate on files that will not compile and is faster than recompilation.
sbtagsrecognizes definitions for types and functions. It also collects information on function calls. No other information is collected (in particular, other semantic information for complex queries is not collected).The functionality of
sbtagsis similar toctagsandetags, except for the Call Grapher information. You may mix direct queries to the database for definitions and graphing with pattern-matching queries.With an
sbtagsgenerated database:
- Class Browser and Class Graph features are not available.
- The database does not contain information on all symbols and strings. It contains information on functions, classes, types, and calls to functions.
- Time is saved since the
sbtagsprogram runs faster than the compiler.- The database size is much smaller than the size of your source code.
- The database content is not guaranteed to be semantically correct because the
sbtagsprogram performs only simple syntactic and semantic analysis and may sometimes be in error.- A database is generated even if the source code cannot be compiled because the code is incomplete or semantically incorrect.
To generate a browsing database using
sbtags, type the following at a command line:
%sbtagsfilefile is the file for which you want to generate the database. See the
sbtags(1) man page for more information.
|
Sun Microsystems, Inc. Copyright information. All rights reserved. Feedback |
Library | Contents | Previous | Next | Index |