Statalist


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

RE: st: RE: Tracing dofile execution


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Tracing dofile execution
Date   Tue, 9 Feb 2010 23:47:11 +0100

<>

"Here you clearly see the value stored in the local.  I think this is
an important advantage over other methods when debugging."


I usually just put a -macro dir- in there to see what is defined at some
point in a do-file. True, you have to remove those before finalizing the
thing...


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of David Elliott
Sent: Dienstag, 9. Februar 2010 23:37
To: [email protected]
Subject: Re: st: RE: Tracing dofile execution

While it is possible to trace dofiles, I have never been able to see
proper macro expansion the way it occurs with adofiles.

Imagine the following dofile "example.do" with a single line:

local xmas `"Days until Christmas: `=td(25 dec 2010) -
td(`c(current_date)')'"'

if you -set trace on- and -do example.do- (or using Ben's program -tr
1:do example.do- )
you will see simply:

. local xmas `"Days until Christmas: `=td(25 dec 2010) -
td(`c(current_date)')'"'

Can you tell me the value that is in the local macro xmas ??
If you use my program -dodebug using example.do- you get the following:

  - local xmas `"Days until Christmas: `=td(25 dec 2010) -
td(`c(current_date)')'"'
  = local xmas `"Days until Christmas: 319"'

Here you clearly see the value stored in the local.  I think this is
an important advantage over other methods when debugging.

Thanks to Eric for directing me to -appendfile- and I used Julian
Reif's method to sandwich the dofile code into the adofile wrapper
resulting in this new version:


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)]

// cleanup if program has been run previously
capture program drop __dotemp
capture erase `"`c(sysdir_personal)'__dotemp.ado"'

file open top using `"`c(sysdir_personal)'__dotemp.ado"', write append
file write top "program define __dotemp" _n ///
    "version 9" _n ///
    `"noisily di "{res:{hline 10} begin debug {hline}}""' _n

file open middle using "`using'", read text
file read middle line
while r(eof)==0 {
	file write top `"`macval(line)'"' _n
	file read middle line
	}
file write top `"noisily di "{res:{hline 10} end debug {hline}}""' _n ///
	"end" _n

file close _all

set tracedepth `depth'
set tracehilite "`hilite'"

set trace on
__dotemp
set trace off

* viewsource __dotemp.ado // Uncomment to look at temporary adofile
erase `"`c(sysdir_personal)'__dotemp.ado"'

end

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

DC Elliott
*
*   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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index