Chapter 11 Programming Tools - PowerPoint PPT Presentation

About This Presentation
Title:

Chapter 11 Programming Tools

Description:

palindrome.o: palindrome.h reverse.h. Slide 13. Run Modular Programs Using makefile ... rules under main2.o, reverse.o and palindrome.o. are skipped due to default. ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 16
Provided by: freder63
Category:

less

Transcript and Presenter's Notes

Title: Chapter 11 Programming Tools


1
Chapter 11 Programming Tools
  • By C. Shing
  • ITEC Dept
  • Radford University

2
Objectives
  • Understand how to create an archived library
  • Understand how to use debugger dbx
  • Understand how to create a makefile

3
Archived 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

4
Archived 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

5
Archived 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

6
Debugger - 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

7
Debugger dbx (Cont.)
  • dbx commands

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
8
Debugger dbx (Cont.)
  • dbx commands (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
9
Debugger dbx (Cont.)
  • Example
  • (dbx) run
  • (dbx) stop at 10
  • (dbx) rerun
  • (dbx) stop in func1
  • (dbx) rerun
  • (dbx) step
  • (dbx) print var1
  • (dbx) quit

10
Run 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

11
Run Modular Programs Using makefile(Cont.)
  • Macro in makefile
  • Syntax MACRONAME string
  • Used as
  • (MACRONAME)
  • Example
  • LIBmylib.a
  • gcc o main main.c (LIB)

12
Run 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

13
Run 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.

14
Run Modular Programs Using makefile (Cont.)
  • Update time stamp of all .c files by
  • touch .c
  • Run the makefile by
  • make f main2.make

15
Reference
  • Chapter 12 of Glass Unix
Write a Comment
User Comments (0)
About PowerShow.com