C syntax question

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Jun 1 08:34:20 AEST 1989


In article <9838 at dasys1.UUCP> dlovell at dasys1.UUCP (Douglas Lovell) writes:
>>In article <821 at clyde.Concordia.CA> marcap at 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 \
	)



More information about the Comp.lang.c mailing list