Discussion of article "Debugging MQL5 Programs"

 

New article Debugging MQL5 Programs is published:

This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It reveals some debugging techniques and presents a combined experience of the author and many other programmers.

Debugging is a stage in program development meant for detecting and removing program execution errors. During the debugging process, a developer analyzes an application trying to detect possible issues. Data for analysis is received by observing the variables and program execution (what functions are called and when).

There are two complementary debugging technologies:

  • Using the debugger - utility showing step-by-step execution of the developed program.
  • Interactive display of variables' states and functions' invocations on a screen, in the journal or in a file.

Debugging process - viewing variable values

Debugging process. Viewing variable values.

Author: Nikolay Demko

 

It's not bad, per se. But.

1. Not a word aboutassertions (assertions), which are just a huge help when debugging.

2. the tracer is controversial, to say the least.

3. It should be mentioned that due to optimisation (of the compiler) debugging becomes very difficult for simple functions because of inlining and suggest ways to circumvent this drawback.

 
TheXpert:

It's not bad, per se. But.

1. Not a word about assertions (assertions), which are just a huge help when debugging.

2. the tracer is controversial, to say the least.

3. It should be mentioned that because of optimisation (compiler) debugging is very difficult for simple functions due to inlining and suggest ways to work around this drawback.

I'll think about 1 and 3 (maybe I'll even finalise the article), everyone has a lot of their own methods, but suggest tracing (or rather, just insert links, there have already been a lot of suggestions).
 
TheXpert:

3. it is necessary to mention that due to optimisation (compiler) debugging is very difficult for simple functions because of inlining and suggest ways around this disadvantage.

In the debugger, inlining is completely disabled and the walkthrough is completely by source code as it is.

In the profiler of the last builds there was a problem with checkpointing, which reduced the quality of reports, but it has been fixed and in the next build next week a new version with more detailed reports will be available.

 

But what is written here is fundamentally wrong:

Хочу отдельно отметить, что компилятор MetaEditor транслирует программы в байт-код, а не нативный код (подробнее читаем по ссылке). Это дает возможность создавать защищенные шифрованием программы, не боясь взлома. Также преимуществом такой трансляции является то, что байт-код может быть запущен как в 32-х битной версии операционной системы, так и в 64-х битной.

At the first stage of compilation, a universal bytecode is stored, but when executed in the terminal, this bytecode is fully 100% translated into native 32 or 64 bit code with additional optimisation. It is due to the translation into native code that we have multiplied the speed of execution of MQL5 programmes compared to MQL4.

Pure bytecode without translation into native code was in MQL4.

 
Renat:

In the debugger, inlining is completely disabled and the walkthrough is completely on the source code as it is.

How long has it been like this? It used to be a big problem. It's just been quite a while since I've worked in 5ka.
 
TheXpert:
How long has it been like this? It used to be a big problem. It's just been quite a while since I've worked in 5k.

Since the beginning.

Inlining eats most of the functions and it would be impossible to debug with it at all, even theoretically. Maybe you just worked with the first versions of the debugger, where there were a number of problems.

 

And for debuging during weed end or without connection with the market? Have you got solution? Because there is a problem after the "OnTick" with the debugger, On MT4 there is an "Tick generator", something like this on mt5?

Thanks in advance,

 
Bisemper:

And for debuging during weed end or without connection with the market? Have you got solution? Because there is a problem after the "OnTick" with the debugger, On MT4 there is an "Tick generator", something like this on mt5?

Thanks in advance,

We can make an association about that ;-)
 

I practically do not use the realtime otaldka because of the long process of quotes arrival and the required chart section.

I have to shove Print in the old way and monitor it in the tester.

Still, the local debugger does not take off before Visual Studio at all. You point at a variable and it gives you a value, point at an expression like a+b /s and the result pops up. In ME it is easier to use Print.

 

We will definitely improve the debugger as soon as we finish the MT4 upgrade.