Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: C syntax question Keywords: C, syntax, compiler Message-ID: <10342@smoke.BRL.MIL> Date: 31 May 89 22:34:20 GMT References: <2747@buengc.BU.EDU> <207600022@s.cs.uiuc.edu> <821@clyde.Concordia.CA> <10305@smoke.BRL.MIL> <9838@dasys1.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 68 In article <9838@dasys1.UUCP> dlovell@dasys1.UUCP (Douglas Lovell) writes: >>In article <821@clyde.Concordia.CA> marcap@concour.CS.Concordia.CA (Marc Pawlowsky) writes: >>>I am looking for a public-domain trace utility for C. e.g. say when a >>>statement is about to execute. ... I also want to know >>>which sections of code have or have not been entered. This reminded me that I still hadn't posted the way I use "ctrace" to get source code listings with statement execution counts in the margin. The following excerpt from one of our Makefiles should be adaptable to your particular System V environment; the biggest change for those who don't have "sam" will be to change the editing commands to work with "ed", "ex", or some such editor instead. ("sam" is available from the UNIX System ToolChest; you don't need the bitmap terminal-dependent part for this application.) CFILES = one.c two.c # etc. HFILES = foo.h # etc. OBJS = one.o two.o # etc. PCFILES = P.one.c P.two.c # etc. TEST = test_driver # or some such TLIBES = /usr/local/ourlib.a -lm # etc. PRFLAGS = -f PRINT = pr $(PRFLAGS) DEFS = -DDEBUG # or whatever INCS = -I. -I/usr/local/include # etc. LDFLAGS = -n # etc. PKGDEFS = # more -D options SYSTEM = -DSYSV # or whatever CC = cc CTFLAGS = -b -l0 -p'fprintf(&_iob[2],' -P CTRACE = ctrace $(CTFLAGS) $(DEFS) $(PKGDEFS) $(SYSTEM) $(INCS) trace: $(PCFILES) @for c in $(CFILES); \ do $(PRINT) -h "$(TEST) coverage of \"$$c\"" P.$$c; \ done # CAUTION: The following procedure requires Rob Pike's "sam" text editor. $(PCFILES): $(HFILES) $(CFILES) $(OBJS) $(TEST).o # $(CFILES) is overkill @( c=`echo $@ | sed 's/^P\.//'`; \ o=`basename $$c .c`.o; \ $(CTRACE) $$c > T.$$c; \ $(CC) -c T.$$c; \ mv $$o B.$$o && mv T.$$o $$o; \ $(CC) $(LDFLAGS) -o $(TEST) $(TEST).o $(OBJS) $(TLIBES); \ ./$(TEST) $(TEST).out 2> X.$$c; \ rm -f T.$$o && mv B.$$o $$o; \ grep '^ *[1-9][0-9]* ' < X.$$c \ | sed 's/^ *\([1-9][0-9]*\).*/\1/' \ | sort -n > L.$$c; \ rm -f X.$$c; \ ( echo ',x/t_ct_\("\\\\n *[1-9][0-9]* /{'; \ echo 'x/[1-9][0-9]*/p\n/\\n/p'; \ echo '}\nq\n' \ ) | sam -d T.$$c | sort -n -u > A.$$c; \ ( echo f P.$$c; \ echo ',x/^/c/ /'; \ uniq -c L.$$c \ | sed 's;^\( *[1-9][0-9]*\) \([1-9][0-9]*\);\2i/\1/;'; \ uniq L.$$c | comm -13 - A.$$c | sed 's;.*;&i/ 0/;'; \ echo 'w\nq\n' \ ) | sam -d $$c; \ rm -f [ALT].$$c \ )