Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Tracing dofile execution


From   David Elliott <dcelliott@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Tracing dofile execution
Date   Tue, 9 Feb 2010 15:34:36 -0400

A frequent frustration I have is not being able to have -set trace on-
trace the executing lines of a dofile.  I've seen some discussions on
the list regarding this but no definitive solutions.  Michael Blasnik
created a little -stepdo- utility to emulate the trace function but it
chokes on //comment lines and multiline commands.  I decided to stop
whining and write a little utility of my own.  Basically, it turns the
dofile into a temporary adofile and then runs it under -set trace on-
conditions that can be user modified for depth and hiliting.  The
output is identical to an adofile trace because it IS an adofile
during the run.

x------------- begin code -------------x
program define dodebug
version 9.0

*! version 1.0.1  2010.02.09
*! Run a do-file with trace
*! by David C. Elliott

syntax using/ [, Depth(integer 1) Hilite(string)]

capture program drop dotemp

tempfile top bottom
file open top using `"`top'"', write text
file write top "program define dotemp" _n ///
    "version 9" _n ///
    `"noisily di "{res:{hline 10} begin debug {hline}}""' _n
file close top

file open bottom using `"`bottom'"', write text
file write bottom _n "set trace off" _n "end" _n
file close bottom

!copy "`top'"+"`using'"+"`bottom'" "`c(sysdir_personal)'dotemp.ado" /y /a

set trace on
set tracedepth `depth'
set tracehilite "`hilite'"
dotemp
set trace off
noisily di "{res:{hline 10} end debug {hline}}"
erase "`c(sysdir_personal)'dotemp.ado"

end
x------------- end code -------------x

This runs fine under Windows but I have no way of testing in Mac or
*nix environments so I don't know if the file appending shell command
will work in all settings.

I experimented with trying to -file write- above and below the
existing text of a dofile without success leading me to apply the
!copy kludge to wrap the dofile wolf in adofile sheep's clothing.  If
someone can educate me how I could do this with -file write- in text
mode, I'd be most grateful.

Feedback would be appreciated and if there is a favorable response
regarding usefulness I may whip up a helpfile and submit this to SSC.

Regards,

David Elliott MD, MSc
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index