Wiki

Changes between Initial Version and Version 1 of Trace

Show
Ignore:
Timestamp:
05/04/10 14:23:52 (15 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Trace

    v1 v1  
     1= Trace =  
     2 
     3Display an execution trace for   
     4    * a point of execution or 
     5    * an expression or expressionlist or 
     6    * all args and locals in the current method  
     7or enable or disable subsequent trace output. 
     8 
     9Tracing an expression or expressionlist is unlike a print of the same expression in that  
     10   * The display format is different;  
     11     trace generates expression-text = expression-value for each expression 
     12   * Position information (filename, line number, declaring class and method) of the trace line is printed 
     13   * Traces can be suppressed on a build by a cobra commandline argument 
     14        {{{ cobra -include-traces:no ...}}} 
     15 
     16traces are useful for debugging (displaying interim expression values) and  
     17logging a point of execution( e.g. indicating that code in a code block is being executed). 
     18 
     19 
     20A simple '''trace'''' statement with no arguments gives just the position info 
     21of the trace statement - the filename, line number, declaring class name 
     22and declaring method name that the trace is located in. [[BR]] 
     23If the current object's class is a subclass of the declaring class then the 
     24subclass name is reported as well. 
     25 
     26When given one or more expressions, trace gives the same information 
     27plus the source code and value of each expression. 
     28 
     29The '''trace all''' statement is a convenience for logging  
     30    * this,  
     31    * every method argument and  
     32    * every local variable. 
     33 
     34The '''trace off''' statement turns off the subsequent trace statements in the declaring method.  
     35 
     36The '''trace on''' statement turns them back on. 
     37 
     38== Grammar == 
     39{{{ 
     40trace 
     41trace <expr1>, <expr2>, ... <expr3> 
     42trace all 
     43trace off 
     44trace on 
     45 
     46}}} 
     47 
     48 
     49== Examples == 
     50 
     51{{{ 
     52class Foo  
     53 
     54    var _z as int  
     55 
     56    def computeStuff(x as int, y as int)  
     57        if x > y  
     58            trace  
     59            return  
     60        _z = x * y  
     61        trace all  
     62        trace _z 
     63 
     64trace: at Foo.cobra:7; in Foo.computeStuff 
     65trace: this=Foo; x=4; y=2; at Foo.cobra:10; in Foo.computeStuff 
     66trace: this=Foo; _z=8; at Foo.cobra:11; in Foo.computeStuff 
     67}}} 
     68 
     69== Notes == 
     70 
     71Needs a way to display just the expression (suppress position info). 
     72 
     73See also [http://cobra-language.com/docs/manual/basic-statements/trace.html manual: trace statement documentation]