Title: Chapter 11 Programming Tools
1Chapter 11 Programming Tools
- By C. Shing
- ITEC Dept
- Radford University
2Objectives
- Understand how to create an archived library
- Understand how to use debugger dbx
- Understand how to create a makefile
3Archived Library
- ar
- Syntax ar option archivename.a objfilename.o
- Option
- r add objfilename in if not exists replace
otherwise - q append objfilename to the end
- d delete objfilename
- t displays table of contents (do not use
objfilename.o) - x extract objfilename
- v verbose output
4Archived Library (Cont.)
- In older system need to make order of
- object code in archive unimportant
- Create an archive list use ranlib utility
- Syntax ranlib archivename.a
5Archived Library (Cont.)
- Example creates an archive mylib.a
- which contains reverse.o. Then link the archive
- when needed.
- gcc o reverse reverse.c
- ar rv mylib.a reverse.o
- ranlib mylib.a
- ar t mylib.a
- gcc o main1 main1.c mylib.a
6Debugger - dbx
- Steps to use dbx
- Compile for debugging gcc g o main main.c
- Enter in dbx environment dbx main
- Type help to show commands in
- dbx environment
- (dbx) help
- Quit dbx environment quit
7Debugger dbx (Cont.)
Command Explain
stop at Break point at line
stop in funcname Break point in function
trace varname Trace variable
step Execute one line into function
next Execute one line, skip function
run (rerun) Run whole program
8Debugger dbx (Cont.)
Command Explain
cont Continue running from last stop
print expr Print value of expression
trace Request trace
trace Trace line
trace varname in funcname Trace variable in function
trace funcname Trace function
9Debugger dbx (Cont.)
- Example
- (dbx) run
- (dbx) stop at 10
- (dbx) rerun
- (dbx) stop in func1
- (dbx) rerun
- (dbx) step
- (dbx) print var1
- (dbx) quit
10Run Modular Programs Using makefile
- makefile lists dependencies between modules
- and the rules to update those files
- Forms
- target files dependency files
- lttabgtrules
- Example
- main2 maine2.o reverse.o palindrome.o
- gcc o main2 main2.o reverse.o palindrome.o
- Update time stamp of a filename by
- touch fileneme
- Run the makefile using make utility
- make f makefilename
11Run Modular Programs Using makefile(Cont.)
- Macro in makefile
- Syntax MACRONAME string
- Used as
- (MACRONAME)
- Example
- LIBmylib.a
- gcc o main main.c (LIB)
12Run Modular Programs Using makefile (Cont.)
- Example vi main2.make
- CCgcc
- main2 main2.o reverse.o palindrome.o
- (CC) -o main2 main2.o reverse.o palindrome.o
- main2.o palindrome.h
- reverse.o reverse.h
- palindrome.o palindrome.h reverse.h
13Run Modular Programs Using makefile (Cont.)
- Note in the previous example,
- rules under main2.o, reverse.o and palindrome.o
- are skipped due to default.
- Also in target files
- main2.c in main2.o
- reverse.c in reverse.o
- palinfrome.c in parlindrome.o
- are neglected by default.
14Run Modular Programs Using makefile (Cont.)
- Update time stamp of all .c files by
- touch .c
- Run the makefile by
- make f main2.make
15Reference