DOC PREVIEW
UW CSE 303 - Lecture Notes

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

'&$%CSE 303:Concepts and Tools for Software DevelopmentDan GrossmanSpring 2007Lecture 14— Makefiles continued; Breakpoint debugging & gdbDan Grossman CSE303 Spring 2007, Lecture 14 1'&$%Where are We• Basics of make, particular the concepts (last le cture, slides 18–23)• Some fancier make features (revenge of funky characters)• Start debuggers, particular gdbDebuggers on the final, not the midterm.• Can be very useful for homework (and in general, of course)Dan Grossman CSE303 Spring 2007, Lecture 14 2'&$%Precise reviewA Makefile has a bunch of these:target: source1 ... sourcenshell_commandRunning make target does this:• For each source, if it is a target in the Makefile, recur with it.• Then:– If some source does not exist, error.– If some source is newer than the target (or target does notexist), run shell_command (presumably updates target, butthat is up to you).Dan Grossman CSE303 Spring 2007, Lecture 14 3'&$%make variablesYou can define variables in a Makefile. Example:CC = gccCFLAGS = -Wallfoo.o: foo.c foo.h bar.h$(CC) $(CFLAGS) -c foo.c -o foo.oWhy do this?• Easy to change things once and affect many commands.• Can change variables on the command-line (overrides definitionsin file). (For example make CFLAGS=-g.)• Easy to reuse most of a Makefile from one “homework” to thenext.• Can use conditionals to set variables (using inherited environmentvariables):Dan Grossman CSE303 Spring 2007, Lecture 14 4'&$%make conditionalsEXE=ifdef WINDIR # assume we are on a Windows machineEXE=.exeendifmyprog$(EXE): foo.o bar.o$(CC) $(CFLAGS) -o myprog$(EXE) foo.o bar.oOther forms of conditionals exist (e.g., are two strings equal)Dan Grossman CSE303 Spring 2007, Lecture 14 5'&$%more variablesIt’s also common to use variables to hold list of filenames:MYOBJFILES = foo.o bar.o baz.omyprog: $(MYOBJFILES)gcc -o myprog $(MYOBJFILES)clean:rm $(MYOBJFILES) myprogclean is a convention: remove any generated files, to “start over” andhave just the source.It’s “funny” because the target doesn’t exist and there are no sources,but that’s okay:• If target doe sn’t ex ist, it m ust be “remade” so run the commands• These “phony” targets have sev eral uses, another is an “all”target:Dan Grossman CSE303 Spring 2007, Lecture 14 6'&$%“all” exampleall: prog B.class someLib.a # notice no commands this timeprog: foo.o bar.o main.ogcc -o prog foo.o bar.o main.oB.class: B.javajavac B.javasomeLib.a: foo.o baz.oar r foo.o baz.ofoo.o: foo.c foo.h header1.h header2.hgcc -c -Wall foo.c... (similar targets for bar.o, main.o, baz.o) ...Dan Grossman CSE303 Spring 2007, Lecture 14 7'&$%Revenge of funny charactersUNIX hackers just can’t get enough of funny metacharacters can they?In commands:• $@ for target• $^ for all sources• $< for left-mos t source• ...Examples:myprog$(EXE): foo.o bar.o$(CC) $(CFLAGS) -o $@ $^foo.o: foo.c foo.h bar.h$(CC) $(CFLAGS) -c $<Dan Grossman CSE303 Spring 2007, Lecture 14 8'&$%More fancy stuff• There are a lot of “built-in” rules. E.g., make just “knows” tocreate foo.o by c alling $(CC) $(CFLAGS) on foo.c. (Opinion:more confusing than helpful.)• There are “suffix” rules and “pattern” rules. Example:%.class: %.javajavac $< # Note we need $< here• Remember you can put any shell command on the command-line,even whole scripts• You can repeat target names to add more dependencies (usefulwith automatic dependency generation).Often this stuff is more useful for reading makefiles than writing yourown (until some day...)Dan Grossman CSE303 Spring 2007, Lecture 14 9'&$%Dependency generationSo far, we are still listing dependencies manually, e.g.:foo.o: foo.c foo.h bar.hIf you forget, say, bar.h, you can introduce subtle bugs in yourprogram (or if you’re lucky, get confusing errors).This is not make’s problem: It has no understanding of differentprogramming languages, commands, etc., just file-mod times.But it does seem too error-prone and busy-work to have to rememberto update dependencies, so there are often language-specific tools thatdo it for you...Dan Grossman CSE303 Spring 2007, Lecture 14 10'&$%Dependency-generator examplegcc -M• Actually lots of useful variants, including -MM and -MG. See mangcc• Automatically creates a rule for you.• Then include the resulting file in your Makefile.• Typically run via a phony depend target, e.g.:depend: $(MY_C_FILES)gcc -M $^• The program makedepend combines many of these steps; again itis C-specific but some other languages have their own.Dan Grossman CSE303 Spring 2007, Lecture 14 11'&$%Build-script summaryAlways script complicated tasks.Always automate “what needs rebuilding” via dependency analysis.make is a text-based program with lots of bells and whistles for doingthis. It is not language-specific. Use it.With language-specific tools, you c an automate dependencygeneration.make files have this way of starting simple and ending up unreadable.It is worth ke eping them clean.There are conventions like make all and make clean common whendistributing source code.Dan Grossman CSE303 Spring 2007, Lecture 14 12'&$%An execution monitor?What would like to “see from” and “do to” a running program?Why might all that be helpful?What are reasonable ways to debug a program?A “debugger” is a tool that lets you stop running programs, inspect(sometimes set) values, etc.Dan Grossman CSE303 Spring 2007, Lecture 14 13'&$%Issues• Source information for compiled code. (Get compiler help.)• Stopping your program too late to find the problem. (Art.)• Trying to “debug” the wrong algorithm.• Trying to “run the debugger” instead of understanding theprogram.It’s an important tool. I use it sometimes.Debugging C vs. Java• Eliminating crashes does not make your C program correct.• Debugging Java is “easier” because crashes and memory errors donot exist.• But programming Java is “easier” for the same reason!Dan Grossman CSE303 Spring 2007, Lecture 14 14'&$%gdbgdb (Gnu debugger) is on attu and supports se veral languages,including C compiled by gcc.Modern IDEs have fancy GUI interfaces, which help, but concepts arethe same.Compiling with debugging information: gcc -g• Otherwise, gdb can tell you little more than the stack of functioncalls.Running gdb: gdb executable• Source files should be in same directory (or use the -d flag).At prompt: run argsNote: You can also inspect core files, which is w hy they ge t s aved.


View Full Document

UW CSE 303 - Lecture Notes

Documents in this Course
Profiling

Profiling

11 pages

Profiling

Profiling

22 pages

Profiling

Profiling

11 pages

Testing

Testing

12 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?