Discussion of article "Tracing, Debugging and Structural Analysis of Source Code"

 

New article Tracing, Debugging and Structural Analysis of Source Code is published:

The entire complex of problems of creating a structure of an executed code and its tracing can be solved without serious difficulties. This possibility has appeared in MetaTrader 5 due to the new feature of the MQL5 language - automatic creation of variables of complex type of data (structures and classes) and their elimination when going out of local scope. The article contains the description of the methodology and the ready-made tool.

Author: Alex Sergeev

 

Oh, yes, Pushkin, yes, son of a bitch.

That's a great article. A real endoscope.

I will definitely use it in large projects. It takes me 24 hours to figure out where the error is.

Debugger is good, but trace gives a complete picture of signal passage.

 
Yeah, good article. Thanks, Alex.
 

You're welcome, I tried my best for you. :)

I plan to maintain and try to expand the functionality in this system. If there will be a need in something, then write.

-----

For full clarity I think it is necessary to say about two more purely technical points.

1. In the Trace.mqh file a single instance of the tracer is created (at the bottom of the file).

extern CTraceCtrl* m_trace; // a single instance of the tracer

Thanks to the extern directive, the instance will be only one. That is, it doesn't depend on how many #include "Trace.mqh" files are included in the #include "Trace.mqh" file


2.
CTraceView class is used in CTraceCtrl only for one single reason - to work out the CTraceCtrl::Break function.
Namely to have a reaction to user clicks in a looped while (true)

 

Added __PATH__ macro processing (build 420), in connection with which all classes are updated.

The button to open a node file has been added to the INFO window.



Opening is performed by ShellExecute command, so DLL import permission is required for classes to work

Files:
MQL5.zip  23 kb
 

added functionality for adding node description.

now in _IN macros it is possible to add an additional description, for example, to display conditions for entering a node or some relevant information.

This description is dynamically updated in the tree display.

Code example:

void OnTick()
  { _IN("");
   static datetime limit_time=0; // last trade processing time + timeout
//--- don't process if timeout
   if(TimeCurrent()>=limit_time)
     { _IN2(TimeCurrent()+">="+limit_time);
      //--- check for data
      if(Bars(Symbol(),Period())>2*InpMATrendPeriod)
        { _IN3(Bars(Symbol(),Period())>2*InpMATrendPeriod);
         //--- change limit time by timeout in seconds if processed
         if(ExtExpert.Processing()) limit_time=TimeCurrent()+ExtTimeOut;
        }
     }
//---
  }


An example of how the information will look like


Button to activate the description display - top right "i"

Files:
MQL5.zip  23 kb
 

1. Added a separate CPropertyView class for displaying node properties.

2. All overridden functions of classes are made as virtual, so all classes are updated.

3. Added two new properties to the CNode class.
m_edit - sign of the editable field in CPropertyView
m_brkuse - number of calls to the node, at which the CTraceCtrl::Break function is stopped and called. 3.

3. According to Urain's notes on the forum, two possibilities of using code stops were added.
- enable/disable stops (red button D)
- stop by specified number of node invocation

а. Setting the initial number m_brkuse in the node can be done using a macro (in the Trace file)

#define _BRKUSES(u)     if (!NIL(m_trace)) if (!NIL(m_trace.m_cur)) ........

b. Or directly in the node properties window in the"DebugBreak after" field, which specifies the required number of calls before stopping



4. To offload the message flow and speed up processing, the following messages are disabled in the!TraceAgent indicator :

CHARTEVENT_CLICK
CHARTEVENT_KEYDOWN
CHARTEVENT_OBJECT_DELETE
CHARTEVENT_OBJECT_CHANGE
CHARTEVENT_OBJECT_CREATE

5. Minor cosmetic changes in tree mapping

Files:
MQL5.zip  27 kb
 

Super article, thanks, sergeev!

Is there any way to use this mechanism in scripts?

 
denkir:

Is there any way to use this mechanism in scripts?

I think so. But usually in scripts the code is not branched much (unless of course the script is in a loop).

Besides, there is an inconvenience - OnChartEvent event is not handled in scripts.

 
sergeev:

I think so. But usually in scripts the code is not branched much (unless of course the script is in a loop).

Besides, there is an inconvenience - scripts don't handle OnChartEvent event.

And if my script uses many different classes, class hierarchies?

I think it is necessary to sharpen the tool for scripts as well...

 

CTraceView class doesn't care who calls it. It will make a tree and display it.

But scripts have an unsolvable feedback problem. You will not be able to actively work with the tree.