ICS 54 Klefstad Unix Programming in C Make - a program for re-building modular systems dbx - a symbolic debugger Libraries and Archives Error Handling in C Programs The UNIX make Facility . make is a tool for building systems composed of modules . eg programs, papers, lectures . `Makefile` contains dependency relations and commands to update . need for update is determined by comparing time of last modification . Makefile contains macros, dependency rules, and update commands Macros . definition VAR = value . value is referenced with ("VAR") or {VAR} . eg OBJECTS = a.o b.o \ c.o d.o e.o SOURCES = a.c b.c c.c HEADERS = a.h b.h c.h ALL = ("OBJECTS") (SOURCES) $(HEADERS) CFLAGS = -g CC = gcc Dependency Rules and Update Commands . form targets: components ; command command ... . eg a single file date: date.c ; gcc date.c -o date . eg a program composed of two modules date: date.o main.o gcc date.o main.o -o date date.o: date.c gcc date.c main.o: main.c gcc main.c Updating Target Files . make builds a dependency graph . it does depth-first-search on the graph to determine what must be 'remade' . if a target is older than any of its components, the update commands are issued . commands are printed as they are executed, @ before command prevents printing Suffix Dependency and Implicit Rules . you can specify general rules for updating components . form .ComponentSufix.TargetSuffix: ; command . special variables . $@ - the name of the target to be make . $? - the string of components newer than the target . $* - common base name of component and target . $< - full component name for implicit rule . eg to remake my lectures .SUFFIXES: .sli .dvi all: program_maintenence.dvi intro.dvi electronic_mail.dvi .sli.dvi: sli $*.sli . eg some of make's default definitions .SUFFIXES: .out .o .c .h CC=cc CFLAGS= .c.o: \("CC") \$("CFLAGS") -c \< Example . Makefile for my_prog SOURCES = a.c b.c c.c OBJECTS = a.o b.o c.o CC = gcc my_prog: $(OBJECTS) \("CC") \(OBJECTS) -o my_prog test: my_prog my_prog < testcases > test clean: rm $(OBJECTS) Make commands . % make . remakes the first target defined in the Makefile . % make my_prog . remakes target my_prog . % make clean . removes all the intermediate files that can be reconstructed . % make -k . continue to make even after an error with an update command . % make -n . just print (don't execute) the update commands Debugging C programs with dbx . dbx is a source-level debugger . provides the following features . source-level control tracing and single-stepping . setting breakpoints and evaluating expressions at breakpoints . displaying and editing of source files . to use dbx, code must be compiled with -g option . % gcc -g my_prog.c -o my_prog . run dbx supplying the name of your program . % dbx my_prog . run your program . (dbx) run args < input_file > output_file . the program will stop upon signal or breakpoint . Summary of dbx commands follows Dynamic Tracing . trace line_number . show whenever the specified line is executed . trace function_name . show each call to named function . trace variable . print new value whenever variable is set . trace expression at line . print value of expression when executing line . trace if condition . trace only if condition is true . where . displays the sequence of function calls on the stack Listing Source Code . list . show the next 10 lines of source code . list start,end . show lines from number start to number end . list function . show the source code for the named function . whatis name . displays the declared type structure of identifier name Setting Breakpoints . stop at line . suspend execution when it reaches line . stop in function . suspend execution upon entering named function . stop variable . suspend execution if variable is changed . stop if condition . suspend execution if condition is true . print expression . display the value of expression . cont . continue execution from a breakpoint . status . display all breakpoints . delete number . remove the numbered trace or breakpoint Single Stepping . step . executes one source line . perhaps into a function call . next . execute up to the next source line . even across function calls