Saving breakpoint presets in debugging would be awesome - page 2

 

Well, I just published it on shared projects as a cloud storage project.

Go and look for "MQLplus Include Library Collection" in the shared projects. Feel free to contribute.


Include the library as follows:

#define LIB_DEBUG
#include <../Shared Projects/MQLplus/lib_debug.mqh>


Here is how its used.

DBG_BREAK_CONDITION_CREATE(abc, true);		// Set the second parameter to false to disable this group


//+------------------------------------------------------------------+
//| Service program start function                                   |
//+------------------------------------------------------------------+
void OnStart()
  {
//---


        int cnt = NULL;
        cnt++;
        DBG_BREAK_CONDITION_ACTIVATE(abc, (cnt > 100));    
        DBG_BREAK_CONDITION_DEACTIVATE(abc, (cnt > 300));
        DBG_BREAK_CONDITION_ON_ID(abc);



   
  }
//+------------------------------------------------------------------+



Yes, you can spread the macros over your code as you like.

 
Dominik Christian Egert #:

Well, I just published it on shared projects as a cloud storage project.

Go and look for "MQLplus Include Library Collection" in the shared projects. Feel free to contribute.


Include the library as follows:


Here is how its used.



Yes, you can spread the macros over your code as you like.

Hi @Dominik Christian Egert -- very, very powerful stuff you put together here... and elegant as well, BRAVO!!!  👏  👏  👏 

I must say that skimming through over 2500 lines of macro code quite was quite intimidating at first, but thankfully I still remember enough of my C-preprocessor hacking days ages ago to follow along and am starting to get a hang of it.

One thing I could try and contribute if you find it adds value to the library, is a general purpose conditional code execution macro in case you don't have one -- I couldn't identify a suitable one in my initial forays into your header file. Basically, sometimes I want to have a one or more counters to check how many times some part of a function/method got executed, but only while debugging.

Perhaps something along these lines could do the trick. Let me know what you think, and whether this can already be done with lib_debug.mqh or if there is a better way to look at it... Thanks in advance. 

#define DBG_EXEC_STATEMENT(x)         if (IS_DEBUG_MODE) { x; }
#define DBG_EXEC(x)                   DBG_EXEC_STATEMENT(x)

// perhaps even add a similar macro that only executes if some condition `y` is met

#ifdef IS_DEBUG_MODE
int dbg_func_counter = 0;
#endif

void SomeFunc()
{
   //...
   DBG_EXEC(dbg_func_counter++);
   //...
}
 
Dima Diall #:

Hi @Dominik Christian Egert -- very, very powerful stuff you put together here... and elegant as well, BRAVO!!!  👏  👏  👏 

I must say that skimming through over 2500 lines of macro code quite was quite intimidating at first, but thankfully I still remember enough of my C-preprocessor hacking days ages ago to follow along and am starting to get a hang of it.

One thing I could try and contribute if you find it adds value to the library, is a general purpose conditional code execution macro in case you don't have one -- I couldn't identify a suitable one in my initial forays into your header file. Basically, sometimes I want to have a one or more counters to check how many times some part of a function/method got executed, but only while debugging.

Perhaps something along these lines could do the trick. Let me know what you think, and whether this can already be done with lib_debug.mqh or if there is a better way to look at it... Thanks in advance. 

Thank you.

If I understand you correctly, you are looking for some type of counter. - I think you could "missuse" the macros for loop tracing.

Look for  DBG_TRACE_LOOP_BEGIN,  DBG_TRACE_LOOP_START,  DBG_TRACE_LOOP_FINISH,  DBG_TRACE_LOOP_END. Or maybe even the "complex" version of these, using the ID specifyer.


*          double some_function(const int index = NULL)
*          {
*              DBG_TRACE_SOME_FUNCTION(
*                  DBG_MSG_TRACE_BEGIN;
*                  DBG_MSG_VAR(index)
*                  );
*              PERF_COUNTER_BEGIN;
*
*              DBG_TRACE_SOME_FUNCTION(DBG_TRACE_LOOP_BEGIN);
*              for(int cnt = (int)some_periods; ((cnt > NULL) && (!_StopFlag)); cnt--)
*              {
*                  DBG_TRACE_SOME_FUNCTION(DBG_TRACE_LOOP_START);
*
*                  // Basic calculations
*                  a += a * cnt;
*
*                  // Some check
*                  if(a)
*                  { continue; }
*
*                  DBG_TRACE_SOME_FUNCTION(DBG_TRACE_LOOP_FINISH);
*              }
*              DBG_TRACE_SOME_FUNCTION(DBG_TRACE_LOOP_END);
*
*              // Assert value is greater than NULL
*              DBG_ASSERT((some_testing_value > NULL), DBG_MSG_VAR(some_testing_value));
*
*              // Return
*              DBG_TRACE_SOME_FUNCTION_RETURN(some_double_value);
*          }
*


In this example it is used as a loop tracing counter, but in fact, since all are macros, they dont care about loops, and you could also see part of a function, or even more of your code as a loop, recurring calls like OnTick could be traced this way, and yes it should be possible to trace down certain parts of the code on how often they were called or executed.


Although I havent tested them, since you said, you are able to read that cryptic stuff, I suppose, you might get into it.


If you would like to contribute to the code, you are welcome, as said, and as documented in CodeBase, its available on SHared Storage as part of the project MQLplus inlcude library collection. (Not much in it yet)

I updated lib_debug.mqh today with some new features, like logging all debug to a file, but havent updated the docs. - Also I am working on some way of tracing MQL-API function calls, but that is as well stil lin development, and will probably not be feasable with the limitations of the preprocessor. - but maybe someone finds a good way to solve it before I do.

Anyways, if you want, join the project, Ill assign you write permissions.

 
As a simple solution, you can use the macro DBG_MSG_VAR_IF(condition, statement)

This will print and execute your statement.