Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: RE: RE: Debugging: reporting line number of loop or do-file causing error


From   David Elliott <dcelliott@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: Debugging: reporting line number of loop or do-file causing error
Date   Fri, 6 Aug 2010 16:06:31 -0300

As possibly one of the "intermittent discussants" regarding do-file
debugging of whom Nick speaks, I have taken the approach of "adoizing"
do-files through use of an ado I call -dodebug-.  -dodebug- wraps the dofile
in ado code and runs it with -set trace on-.  One can follow all the macro
expansions and loops that occur.

Here is a brief listing showing options:

program define dodebug
version `c(version)'

*! version 1.0.3  2010.02.10
*! Run a dofile with trace functionality for debugging
*! by David C. Elliott
*!
*! syntax:
*! dodebug using dofilename [, depth(integer) hilite(string) number
version(real) more]
*! depth - set tracedepth, defaults to 1
*! hilite string - hilight text in trace, normally blank
*! number - sets nesting numbering on, normally blank
*! version - allows dofile to be run under version control
*! more - sets more on, normally off
*! Note: dofilename cannot have spaces or special characters

syntax using/ [, Depth(integer 1) Hilite(string) Number Version(real
`c(version)') More]

It still has some rough edges which is why I haven't made it available on
SSC yet, but I am happy to provide it to Beta testers if they wish to
contact me offlist.

DCElliott


> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
> Sent: 29 July 2010 12:32
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: Debugging: reporting line number of loop or do-file causing error
>
> This area is the subject of intermittent discussion, for example at the recent Stata Conference in Boston. What you report is from one point of view a feature, as reporting step-by-step progress through a loop of hundreds (thousands (...)) of steps would bloat traces mightily and would surely be a matter for frequent complaint. But equally many user-programmers would echo your experience.
>
> For the moment, adding your own debugging lines designed to catch what is most problematic is I believe the only game in town. Printing out something important or sensitive is however likely to be more informative than quite what you have here, except that I don't know the context.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Aleksander Rutkowski
>
> Is there any convenient way to make Stata report (together with an
> error message) the line number of a loop or a line number of a do-file
> which is causing an error?  In general, I think this is an important
> feature needed for efficient debugging.
>
> When loops are executed, the commands are not reported in the results
> window, so it is difficult to quickly identify which command causes an
> error. So far, I used the following solution, but it is not very
> convenient:
>
> local i 0
> forval j = 1/100 {
>   local ++i
>   di "Now executing line `i'..."
>   ...some command here...
>   local ++i
>   di "Now executing line `i'..."
>   ...some command here...
>   ...etc...
> }
>
>
> *
> *   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/



--
David Elliott

Everything is theoretically impossible, until it is done.
Progress is made by lazy men looking for easier ways to do things.
 -- Robert A. Heinlein (American science-fiction Writer, 1907-1988)

*
*   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   |   Site index