Programming Tools Guide
Table of Contents
Programming Tools Guide
Programming Tools Guide
Table of Contents
About this book
Using this guide
Typographical conventions
Related documentation
How can we improve this book?
Chapter 1: Using programming tools
Creating the source code
Archiving the code
Analyzing the code
Using cb
Using cscope
Using lint
Using cflow
Using cxref
Archiving changes made during the analysis
Compiling the code
Using make
Testing the code
Debugging the code
Using dbxtra
Testing the correction
Program structure and guidelines
Program structure
Header files
Error handling
Chapter 2: C compilation system
Compiling and linking
Basic cc command line syntax
Commonly used cc command line options
Searching for a header file
Preparing your program for debugging
Preparing your program for profiling
Optimizing your program
Link editing
Linking with archive libraries
Linking with dynamically linked libraries
Linking with standard libraries
Creating and linking with archive and dynamically linked libraries
Specifying directories to be searched by the link editor
Specifying directories to be searched by the dynamic linker
Checking for run-time compatibility
Dynamic linking programming interface
Implementation
Guidelines for building dynamically linked libraries
Minimize the library's data segment
Minimize paging activity
Maintenance
Multiply defined symbols
Quick-reference guide
Libraries and header files
Header files
How to use library functions
C library (libc)
Standard I/O routines
String, character, environment and memory routines
System calls
Math library (libm)
General purpose library (libgen)
Standard I/O
Standard files
Named files
Passing command line arguments
Chapter 3: C language compiler
Compilation modes
Phases of translation
Source files and tokenization
Tokens
Identifiers
Keywords
Constants
String literals
Wide string literals
Punctuators
Comments
Preprocessing
Trigraph sequences
Preprocessing tokens
Preprocessing directives
Declarations and definitions
Basic types
Scope
Storage duration
Storage class specifiers
Declarators
Function definitions
Conversions and expressions
Implicit conversions
Expressions
Operators
Associativity and precedence of operators
Constant expressions
Initialization
Statements
Expression statement
Compound statement
Selection statements
Iteration statements
Jump statements
Portability considerations
Chapter 4: COFF link editor
Sections
Memory configuration
Addresses
Binding
Object files
Link editor command language
Expressions
Assignment statements
Specifying a memory configuration
Section definition directives
Changing the entry point
Using archive libraries
Allocation algorithm
Incremental link editing
DSECT, COPY, NOLOAD, INFO, and OVERLAY sections
Output file blocking
Nonrelocatable input files
Syntax diagram for input directives
Chapter 5: lint analyzer
What lint does
Consistency checks
Portability checks
Suspicious constructs
Using lint
lint libraries
lint filters
Options and directives listed
Understanding lint-specific messages
Chapter 6: dbXtra and dbxtra
Invoking dbXtra and dbxtra from the command line
The dbXtra interface
Configuring dbXtra X11 and Motif resources
The dbxtra interface
Screen mode
dbxtra keyboard interface
dbxtra tutorial session
Preparing files for dbxtra
Starting dbxtra
The dbxtra screen
The dbxtra help facility
Printing the value of variables
Viewing source code and aliasing
Viewing the call stack
Traversing the call stack
Monitoring the contents of variables
Analyzing the results
Examining a different function
Using a breakpoint
Continuing after a breakpoint
Exiting dbxtra
dbXtra and dbxtra commands
File menu: saving and quitting
Events menu: managing execution time events
eXecute menu: executing the program being debugged
Source menu: accessing source files
Info menu: debugging registers, memory locations, and expressions
Options menu: controlling the debugging environment
The help menu
curses interface commands
Default command aliases
dbXtra and dbxtra expressions and conditions
C++ specific debugging features
Usage requirements
Overloaded functions and operators
The dbXtra and dbxtra cc command
Debugging child processes
Attaching to a running process
Chapter 7: sdb: symbolic debugger
Using sdb
Printing a stack trace
Examining variables
Source file display and manipulation
Displaying the source file
A controlled environment for program testing
Setting and deleting breakpoints
Running the program
Calling functions
Machine language debugging
Displaying machine language statements
Manipulating registers
Other commands
An sdb session
Chapter 8: adb: absolute debugger
Starting adb
Starting adb with a core image file
Exiting adb
Displaying program instructions and data
Forming addresses
Forming expressions
Choosing data formats
Using the = command
Using the ? and / commands
An example: simple formatting
Debugging program execution
Executing a program
Setting breakpoints
Displaying breakpoints
Continuing execution
Stopping a program with interrupt and quit
Single-stepping a program
Killing a program
Deleting breakpoints
Displaying the C stack backtrace
Displaying CPU registers
Displaying external variables
An example: tracing multiple functions
Using the adb memory maps
Displaying the memory maps
Changing the memory map
Creating new map entries
Validating addresses
Miscellaneous features
Combining commands on a single line
Creating adb scripts
Setting output width
Setting the maximum offset
Setting default input format
Using UNIX commands
Computing numbers and displaying text
An example: directory and inode dumps
Patching binary files and memory
Locating values in a file
Writing to a file
Making changes to memory
Chapter 9: C programmer's productivity tools
lprof
Creating a profiled version of a program
Running the profiled program
The PROFOPTS environment variable
Examples of using PROFOPTS
Interpreting profiling output
Viewing the profiled source listing
Specifying program and data files to lprof
Files needed by lprof
Source listing for a subset of files
Summary option
Merging option
Cautionary notes on using
lprof
Improving performance with prof and lprof
Improving test coverage with lprof
cscope
Configuring the environment
Using cscope
Running cscope
The cross-reference file
A tutorial example: locating the source of the error message
Conditional compilation directives
Examples of using cscope
Changing a text string
Adding an argument to a function
Changing the value of a variable
Chapter 10: make
Basic features
Parallel make
Recursive makefiles
makefiles and substitutions
Dependency line syntax
Dependency information
Macro definitions
Executable commands
Output translations
Suffixes and transformation rules
Implicit rules
Archive libraries
Tildes in SCCS filenames
The null suffix
Creating new suffix rules
include files
Dynamic dependency parameters
Environment variables
Suggestions and warnings
Makefile example
Internal rules
Chapter 11: Source code control system (SCCS)
SCCS for beginners
Terminology
Creating an SCCS file using admin
Retrieving a file by means of get
Recording changes by using delta
Additional information about get
Delta numbering
SCCS command conventions
x-files and z-files
SCCS commands
Error messages
help command
get command
delta command
admin command
prs command
sact command
rmdel command
cdc command
what command
sccsdiff command
comb command
val command
vc command
SCCS files
Protection
Formatting
Auditing
Chapter 12: lex
Writing lex programs
Rules section
Definitions section
The subroutines section
Advanced lex usage
Disambiguating rules
Context sensitivity
lex I/O routines
Routines to reprocess input
Using lex with yacc
Using lex under UNIX systems
Running lex
Compiling a lexical analyzer
Running the lexical analyzer
Using make with lex
Chapter 13: yacc
yacc specifications
Terminal and non-terminal symbols
Rules
Actions
Declarations
Subroutines
The yacc environment
Lexical analysis
lex and yylval
Token numbers
End-marker token
Reserved token names
Parsing
Compiling
Running the parser
Parser operation
Ambiguity and conflicts
Disambiguating rules
Precedence
Assigning a precedence to grammar rules
Error handling
Error token
Interactive error recovery
Hints for preparing specifications
Input style
Left recursion
Lexical tie-ins
Reserved words
Examples of using yacc
Simple example
Advanced example
Chapter 14: Shared libraries
What is a shared library?
Building an a.out file
Deciding whether to use a shared library
Space considerations
Saving space
Increase space usage in memory
Coding an application
Identifying a.out files that use shared libraries
Debugging a.out files that use shared libraries
Implementing shared libraries
The host library and target library
The branch table
Building a shared library
The building process
Guidelines for writing shared library code
Choosing library members
Include large, frequently used routines
Exclude infrequently used routines
Exclude routines that use much static data
Exclude routines that complicate maintenance
Include routines the library itself needs
Changing existing code for the shared library
Minimize global data
Using the specification file for compatibility
Importing symbols
Providing compatibility with non-shared libraries
Tuning the shared library code
Checking for compatibility
An example
Appendix A: ANSI implementation-defined behavior
Translation
Environment
Identifiers
Characters
Integers
Floating point
Arrays and pointers
Registers
Structures, unions, enumerations, and bit-fields
Qualifiers
Declarators
Statements
Preprocessing directives
Library functions
Locale-specific behavior
C Implementation limits description
Translation limits
Appendix B: C compiler diagnostics
Message types and applicable options
Operator names in messages
Messages
Operator names
Other error messages
Index