From 5c3e63375c78a9da28921acc29a75c4e5e1453b1 Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Tue, 30 Nov 2021 17:07:40 +0200 Subject: [PATCH 01/11] py/mpprint.h: Add DBG() macro. Debugging macro for developers. --- py/mpprint.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/py/mpprint.h b/py/mpprint.h index 8383ea85794c2..9817aadf89d31 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -79,4 +79,44 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...); int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif +// Debug messages during code developing. +// An approximate hierarchy of debug levels is: +// -1 - SUPPRES all messages in release version +// 0 - the most CRITICAL errors, often requiring a system reset, use message with this level if possible raising an exception +// 1 - ERROR requiring program restart, use message with this level before raising an exception +// 2 - WARNING, something went wrong, but you can fix it with additional operations in code right now +// 3 - INFO, it is interesting and useful for understanding a bug +// 4 - DEBUG, more detaled info, dig deeper +// 5 - TRACE, show algorithm flow +// In real you may use own classification of debug levels. +#define DBG(level, ...) \ + do { \ + if (level <= DBG_LEVEL) { \ + mp_printf(MP_PYTHON_PRINTER, "%d:: ", level); \ + mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ + mp_printf(MP_PYTHON_PRINTER, "\n"); \ + } \ + } while (0); +/* +// How to use: +// Set DBG_LEVEL in developed *.C or *.CPP file +#define DBG_LEVEL 1000 // show all messages +// Add DBG() macro in code, like +void foo() { + DBG(5, "Enter foo()") + ... + int value; + ... + // calculate value + DBG(3, "See a value=%d", value) + ... + DBG(5, "Exit foo()") +} +// See usage in ports/esp32/machine_pwm.c +// It is not a dogma. You may start debugging from level 3. +#define DBG_LEVEL 3 +// Then add DBG(3, ...) and when gets too much messages then change some messages to the next level DBG(4, ...), or DBG(2, ...) +// Then you may change DBG_LEVEL to 2, and finally to -1. +*/ + #endif // MICROPY_INCLUDED_PY_MPPRINT_H From cecd5029b5e1e3e23315c8896dc2e6118ca2eefe Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Thu, 2 Dec 2021 19:31:11 +0200 Subject: [PATCH 02/11] py/mprint.h: Change names to MP_PRN & MP_PRN_LEVEL. --- py/mpprint.h | 59 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/py/mpprint.h b/py/mpprint.h index 9817aadf89d31..3ac53fb607290 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -79,44 +79,55 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...); int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif -// Debug messages during code developing. -// An approximate hierarchy of debug levels is: -// -1 - SUPPRES all messages in release version -// 0 - the most CRITICAL errors, often requiring a system reset, use message with this level if possible raising an exception -// 1 - ERROR requiring program restart, use message with this level before raising an exception -// 2 - WARNING, something went wrong, but you can fix it with additional operations in code right now -// 3 - INFO, it is interesting and useful for understanding a bug -// 4 - DEBUG, more detaled info, dig deeper -// 5 - TRACE, show algorithm flow +// Debug messages during code developing with MP_PRN(level, ...) & MP_PRN_LEVEL. +// An approximate hierarchy of debug levels (MP_PRN_LEVEL) is: +// 0 - SUPPRES all messages. Use it in release version. +// 1 - The most CRITICAL errors, often requiring a system reset, use message with this level if possible raising an exception. +// 2 - ERROR requiring program restart, use message with this level before raising an exception. +// 3 - WARNING, something went wrong, but you can fix it with additional operations in code right now or may ignore it. +// 4 - INFO, it is interesting and useful for understanding a bug. +// 5 - DEBUG, more detaled info, dig deeper. +// 6 - TRACE, show algorithm flow, like enter/exit a function. // In real you may use own classification of debug levels. -#define DBG(level, ...) \ +#define MP_PRN(level, ...) \ do { \ - if (level <= DBG_LEVEL) { \ - mp_printf(MP_PYTHON_PRINTER, "%d:: ", level); \ - mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ - mp_printf(MP_PYTHON_PRINTER, "\n"); \ + if (MP_PRN_LEVEL > 0) { \ + if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ + mp_printf(MP_PYTHON_PRINTER, "%d:: ", level); \ + mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ + mp_printf(MP_PYTHON_PRINTER, "\n"); \ + } \ } \ } while (0); /* // How to use: -// Set DBG_LEVEL in developed *.C or *.CPP file -#define DBG_LEVEL 1000 // show all messages -// Add DBG() macro in code, like +// Set MP_PRN_LEVEL in developed *.C or *.CPP file, for example + +#define MP_PRN_LEVEL 1000 // show all messages +// Add MP_PRN() macro in code, like void foo() { - DBG(5, "Enter foo()") + MP_PRN(6, "Enter foo()") ... int value; ... // calculate value - DBG(3, "See a value=%d", value) ... - DBG(5, "Exit foo()") + MP_PRN(4, "See a value=%d", value) + ... + MP_PRN(6, "Exit foo()") } -// See usage in ports/esp32/machine_pwm.c + +// See usage in ports/esp32/esp32_pcnt.c and ports/esp32/machine_pwm.c // It is not a dogma. You may start debugging from level 3. -#define DBG_LEVEL 3 -// Then add DBG(3, ...) and when gets too much messages then change some messages to the next level DBG(4, ...), or DBG(2, ...) -// Then you may change DBG_LEVEL to 2, and finally to -1. +#define MP_PRN_LEVEL 3 +// Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) +// Then you may change MP_PRN_LEVEL to 2(reduce printing), and finally to 0(supress printing). +// +// To switching off MP_PRN() from a compiled binary, use +#ifdef MP_PRN + #undef MP_PRN + #define MP_PRN(level, ...) +#endif */ #endif // MICROPY_INCLUDED_PY_MPPRINT_H From dabab6cf26a412a57eb5bb8e0a3c1e35e557f859 Mon Sep 17 00:00:00 2001 From: IhorNehrutsa <70886343+IhorNehrutsa@users.noreply.github.com> Date: Fri, 10 Dec 2021 10:07:29 +0200 Subject: [PATCH 03/11] py\mpprint.h: Change MP_PRN() delimiter to '|'. --- py/mpprint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/mpprint.h b/py/mpprint.h index 3ac53fb607290..3578b88c3fbeb 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -93,7 +93,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); do { \ if (MP_PRN_LEVEL > 0) { \ if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ - mp_printf(MP_PYTHON_PRINTER, "%d:: ", level); \ + mp_printf(MP_PYTHON_PRINTER, "%d| ", level); \ mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ mp_printf(MP_PYTHON_PRINTER, "\n"); \ } \ From 8e69ae7279812fa5c02b7ce651a542063d902420 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Wed, 15 Dec 2021 14:10:03 +0200 Subject: [PATCH 04/11] py\mpprint.h: MP_PRN() is off by default. --- py/mpprint.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/py/mpprint.h b/py/mpprint.h index 3578b88c3fbeb..9121d1ae1399b 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -80,15 +80,16 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif // Debug messages during code developing with MP_PRN(level, ...) & MP_PRN_LEVEL. -// An approximate hierarchy of debug levels (MP_PRN_LEVEL) is: -// 0 - SUPPRES all messages. Use it in release version. -// 1 - The most CRITICAL errors, often requiring a system reset, use message with this level if possible raising an exception. +// An approximate hierarchy of debug levels MP_PRN_LEVEL is: +// 0 - SUPPRESS all messages. Use it in the release version. +// 1 - For the most CRITICAL errors, often requiring a system reset. Use a message with this level, if possible, raising an exception. // 2 - ERROR requiring program restart, use message with this level before raising an exception. // 3 - WARNING, something went wrong, but you can fix it with additional operations in code right now or may ignore it. // 4 - INFO, it is interesting and useful for understanding a bug. -// 5 - DEBUG, more detaled info, dig deeper. -// 6 - TRACE, show algorithm flow, like enter/exit a function. -// In real you may use own classification of debug levels. +// 5 - DEBUG, more detailed information, dig deeper. +// 6 - TRACE, show a flow of the algorithm, like enter/exit a function. +// In reality, you may use your own classification of debug levels. +#if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) #define MP_PRN(level, ...) \ do { \ if (MP_PRN_LEVEL > 0) { \ @@ -99,6 +100,9 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); } \ } \ } while (0); +#else +#define MP_PRN(level, ...) +#endif /* // How to use: // Set MP_PRN_LEVEL in developed *.C or *.CPP file, for example @@ -122,12 +126,6 @@ void foo() { #define MP_PRN_LEVEL 3 // Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) // Then you may change MP_PRN_LEVEL to 2(reduce printing), and finally to 0(supress printing). -// -// To switching off MP_PRN() from a compiled binary, use -#ifdef MP_PRN - #undef MP_PRN - #define MP_PRN(level, ...) -#endif */ #endif // MICROPY_INCLUDED_PY_MPPRINT_H From d6534e3a5136f56aa702486c5466701637750090 Mon Sep 17 00:00:00 2001 From: Ihor Nehrutsa Date: Fri, 24 Dec 2021 14:50:31 +0200 Subject: [PATCH 05/11] py\mpprint.h: Add __LINE__ and __FILE__. --- py/mpprint.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/py/mpprint.h b/py/mpprint.h index 9121d1ae1399b..caefa1a168def 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -92,12 +92,10 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) #define MP_PRN(level, ...) \ do { \ - if (MP_PRN_LEVEL > 0) { \ - if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ - mp_printf(MP_PYTHON_PRINTER, "%d| ", level); \ - mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ - mp_printf(MP_PYTHON_PRINTER, "\n"); \ - } \ + if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ + mp_printf(MP_PYTHON_PRINTER, " %d|| ", level); \ + mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ + mp_printf(MP_PYTHON_PRINTER, " ||%d %s\n", __LINE__, __FILE__); \ } \ } while (0); #else @@ -108,6 +106,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); // Set MP_PRN_LEVEL in developed *.C or *.CPP file, for example #define MP_PRN_LEVEL 1000 // show all messages + // Add MP_PRN() macro in code, like void foo() { MP_PRN(6, "Enter foo()") @@ -121,10 +120,9 @@ void foo() { MP_PRN(6, "Exit foo()") } -// See usage in ports/esp32/esp32_pcnt.c and ports/esp32/machine_pwm.c // It is not a dogma. You may start debugging from level 3. #define MP_PRN_LEVEL 3 -// Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) +// Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) etc. // Then you may change MP_PRN_LEVEL to 2(reduce printing), and finally to 0(supress printing). */ From ebe4a1ad26a488ac6e3f7e6724e06de7738ad8be Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Fri, 1 Jul 2022 09:01:45 +0300 Subject: [PATCH 06/11] py/mpprint.h: Add MP_PRN_levels --- py/mpprint.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/py/mpprint.h b/py/mpprint.h index caefa1a168def..0610c201d2ffd 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -81,13 +81,13 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); // Debug messages during code developing with MP_PRN(level, ...) & MP_PRN_LEVEL. // An approximate hierarchy of debug levels MP_PRN_LEVEL is: -// 0 - SUPPRESS all messages. Use it in the release version. -// 1 - For the most CRITICAL errors, often requiring a system reset. Use a message with this level, if possible, raising an exception. -// 2 - ERROR requiring program restart, use message with this level before raising an exception. -// 3 - WARNING, something went wrong, but you can fix it with additional operations in code right now or may ignore it. -// 4 - INFO, it is interesting and useful for understanding a bug. -// 5 - DEBUG, more detailed information, dig deeper. -// 6 - TRACE, show a flow of the algorithm, like enter/exit a function. +#define MP_PRN_SUPPRESS 0 // SUPPRESS all messages. Use it in the release version. +#define MP_PRN_CRITICAL 1 // For the most CRITICAL errors, often requiring a system reset. Use a message with this level, if possible, raising an exception. +#define MP_PRN_ERROR 2 // ERROR requiring program restart, use message with this level before raising an exception. +#define MP_PRN_WARNING 3 // WARNING, something went wrong, but you can fix it with additional operations in code right now or may ignore it. +#define MP_PRN_INFO 4 // INFO, it is interesting and useful for understanding a bug. +#define MP_PRN_DEBUG 5 // DEBUG, more detailed information, dig deeper. +#define MP_PRN_TRACE 6 // TRACE, show a flow of the algorithm, like enter/exit a function. // In reality, you may use your own classification of debug levels. #if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) #define MP_PRN(level, ...) \ @@ -126,4 +126,14 @@ void foo() { // Then you may change MP_PRN_LEVEL to 2(reduce printing), and finally to 0(supress printing). */ +#if 0 +#if MICROPY_DEBUG_VERBOSE // print debugging info +#define DEBUG_PRINT (1) +#define DEBUG_printf(...) MP_PRN(MP_PRN_DEBUG, __VA_ARGS__) +#else // don't print debugging info +#define DEBUG_PRINT (0) +#define DEBUG_printf(...) +#endif +#endif + #endif // MICROPY_INCLUDED_PY_MPPRINT_H From c62d2faa31606a806fccc368d6af88e05b19a54a Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Thu, 9 Mar 2023 15:03:20 +0200 Subject: [PATCH 07/11] Update mpprint.h --- py/mpprint.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) mode change 100644 => 100755 py/mpprint.h diff --git a/py/mpprint.h b/py/mpprint.h old mode 100644 new mode 100755 index 0610c201d2ffd..e0ecdd3c2b959 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -79,6 +79,9 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...); int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif +#endif // MICROPY_INCLUDED_PY_MPPRINT_H + +#if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) // Debug messages during code developing with MP_PRN(level, ...) & MP_PRN_LEVEL. // An approximate hierarchy of debug levels MP_PRN_LEVEL is: #define MP_PRN_SUPPRESS 0 // SUPPRESS all messages. Use it in the release version. @@ -89,13 +92,17 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #define MP_PRN_DEBUG 5 // DEBUG, more detailed information, dig deeper. #define MP_PRN_TRACE 6 // TRACE, show a flow of the algorithm, like enter/exit a function. // In reality, you may use your own classification of debug levels. -#if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) + +#if defined(MP_PRN) +#undef MP_PRN +#endif + #define MP_PRN(level, ...) \ do { \ if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ - mp_printf(MP_PYTHON_PRINTER, " %d|| ", level); \ + mp_printf(MP_PYTHON_PRINTER, " %d || ", level); \ mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ - mp_printf(MP_PYTHON_PRINTER, " ||%d %s\n", __LINE__, __FILE__); \ + mp_printf(MP_PYTHON_PRINTER, " || %d %s\n", __LINE__, __FILE__); \ } \ } while (0); #else @@ -119,7 +126,6 @@ void foo() { ... MP_PRN(6, "Exit foo()") } - // It is not a dogma. You may start debugging from level 3. #define MP_PRN_LEVEL 3 // Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) etc. @@ -135,5 +141,3 @@ void foo() { #define DEBUG_printf(...) #endif #endif - -#endif // MICROPY_INCLUDED_PY_MPPRINT_H From 23c465496d60128bd326c4d137adc7b5621592ec Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Tue, 30 Nov 2021 17:07:40 +0200 Subject: [PATCH 08/11] py/mpprint.h: Add DBG() macro. Debugging macro for developers. py/mprint.h: Change names to MP_PRN & MP_PRN_LEVEL. py\mpprint.h: Change MP_PRN() delimiter to '|'. py\mpprint.h: MP_PRN() is off by default. py\mpprint.h: Add __LINE__ and __FILE__. py/mpprint.h: Add MP_PRN_levels --- py/mpprint.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/py/mpprint.h b/py/mpprint.h index 8383ea85794c2..0610c201d2ffd 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -79,4 +79,61 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...); int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif +// Debug messages during code developing with MP_PRN(level, ...) & MP_PRN_LEVEL. +// An approximate hierarchy of debug levels MP_PRN_LEVEL is: +#define MP_PRN_SUPPRESS 0 // SUPPRESS all messages. Use it in the release version. +#define MP_PRN_CRITICAL 1 // For the most CRITICAL errors, often requiring a system reset. Use a message with this level, if possible, raising an exception. +#define MP_PRN_ERROR 2 // ERROR requiring program restart, use message with this level before raising an exception. +#define MP_PRN_WARNING 3 // WARNING, something went wrong, but you can fix it with additional operations in code right now or may ignore it. +#define MP_PRN_INFO 4 // INFO, it is interesting and useful for understanding a bug. +#define MP_PRN_DEBUG 5 // DEBUG, more detailed information, dig deeper. +#define MP_PRN_TRACE 6 // TRACE, show a flow of the algorithm, like enter/exit a function. +// In reality, you may use your own classification of debug levels. +#if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) +#define MP_PRN(level, ...) \ + do { \ + if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ + mp_printf(MP_PYTHON_PRINTER, " %d|| ", level); \ + mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ + mp_printf(MP_PYTHON_PRINTER, " ||%d %s\n", __LINE__, __FILE__); \ + } \ + } while (0); +#else +#define MP_PRN(level, ...) +#endif +/* +// How to use: +// Set MP_PRN_LEVEL in developed *.C or *.CPP file, for example + +#define MP_PRN_LEVEL 1000 // show all messages + +// Add MP_PRN() macro in code, like +void foo() { + MP_PRN(6, "Enter foo()") + ... + int value; + ... + // calculate value + ... + MP_PRN(4, "See a value=%d", value) + ... + MP_PRN(6, "Exit foo()") +} + +// It is not a dogma. You may start debugging from level 3. +#define MP_PRN_LEVEL 3 +// Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) etc. +// Then you may change MP_PRN_LEVEL to 2(reduce printing), and finally to 0(supress printing). +*/ + +#if 0 +#if MICROPY_DEBUG_VERBOSE // print debugging info +#define DEBUG_PRINT (1) +#define DEBUG_printf(...) MP_PRN(MP_PRN_DEBUG, __VA_ARGS__) +#else // don't print debugging info +#define DEBUG_PRINT (0) +#define DEBUG_printf(...) +#endif +#endif + #endif // MICROPY_INCLUDED_PY_MPPRINT_H From bc420b5b1ad771ef84092edbc4a3920a2f0daf5a Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Thu, 9 Mar 2023 15:28:53 +0200 Subject: [PATCH 09/11] Update mpprint.h --- py/mpprint.h | 59 ---------------------------------------------------- 1 file changed, 59 deletions(-) diff --git a/py/mpprint.h b/py/mpprint.h index 6f06e00619fe2..67a22c83ed28d 100755 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -79,63 +79,6 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...); int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif -// Debug messages during code developing with MP_PRN(level, ...) & MP_PRN_LEVEL. -// An approximate hierarchy of debug levels MP_PRN_LEVEL is: -#define MP_PRN_SUPPRESS 0 // SUPPRESS all messages. Use it in the release version. -#define MP_PRN_CRITICAL 1 // For the most CRITICAL errors, often requiring a system reset. Use a message with this level, if possible, raising an exception. -#define MP_PRN_ERROR 2 // ERROR requiring program restart, use message with this level before raising an exception. -#define MP_PRN_WARNING 3 // WARNING, something went wrong, but you can fix it with additional operations in code right now or may ignore it. -#define MP_PRN_INFO 4 // INFO, it is interesting and useful for understanding a bug. -#define MP_PRN_DEBUG 5 // DEBUG, more detailed information, dig deeper. -#define MP_PRN_TRACE 6 // TRACE, show a flow of the algorithm, like enter/exit a function. -// In reality, you may use your own classification of debug levels. -#if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) -#define MP_PRN(level, ...) \ - do { \ - if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ - mp_printf(MP_PYTHON_PRINTER, " %d|| ", level); \ - mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ - mp_printf(MP_PYTHON_PRINTER, " ||%d %s\n", __LINE__, __FILE__); \ - } \ - } while (0); -#else -#define MP_PRN(level, ...) -#endif -/* -// How to use: -// Set MP_PRN_LEVEL in developed *.C or *.CPP file, for example - -#define MP_PRN_LEVEL 1000 // show all messages - -// Add MP_PRN() macro in code, like -void foo() { - MP_PRN(6, "Enter foo()") - ... - int value; - ... - // calculate value - ... - MP_PRN(4, "See a value=%d", value) - ... - MP_PRN(6, "Exit foo()") -} - -// It is not a dogma. You may start debugging from level 3. -#define MP_PRN_LEVEL 3 -// Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) etc. -// Then you may change MP_PRN_LEVEL to 2(reduce printing), and finally to 0(supress printing). -*/ - -#if 0 -#if MICROPY_DEBUG_VERBOSE // print debugging info -#define DEBUG_PRINT (1) -#define DEBUG_printf(...) MP_PRN(MP_PRN_DEBUG, __VA_ARGS__) -#else // don't print debugging info -#define DEBUG_PRINT (0) -#define DEBUG_printf(...) -#endif -#endif - #endif // MICROPY_INCLUDED_PY_MPPRINT_H #if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) @@ -168,9 +111,7 @@ void foo() { /* // How to use: // Set MP_PRN_LEVEL in developed *.C or *.CPP file, for example - #define MP_PRN_LEVEL 1000 // show all messages - // Add MP_PRN() macro in code, like void foo() { MP_PRN(6, "Enter foo()") From 3db8d33fd2652acd274aaef3b55ddbb3a72aa7f2 Mon Sep 17 00:00:00 2001 From: IhorNehrutsa <70886343+IhorNehrutsa@users.noreply.github.com> Date: Mon, 17 Jul 2023 13:38:56 +0300 Subject: [PATCH 10/11] Update mpprint.h --- py/mpprint.h | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/py/mpprint.h b/py/mpprint.h index 67a22c83ed28d..6b8d2821ed801 100755 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -100,9 +100,9 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #define MP_PRN(level, ...) \ do { \ if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ - mp_printf(MP_PYTHON_PRINTER, " %d || ", level); \ + mp_printf(MP_PYTHON_PRINTER, " MP_PRN_LEVEL=%d : ", level); \ mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ - mp_printf(MP_PYTHON_PRINTER, " || %d %s\n", __LINE__, __FILE__); \ + mp_printf(MP_PYTHON_PRINTER, " : LINE=%d FILE=%s\n", __LINE__, __FILE__); \ } \ } while (0); #else @@ -129,13 +129,3 @@ void foo() { // Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) etc. // Then you may change MP_PRN_LEVEL to 2(reduce printing), and finally to 0(supress printing). */ - -#if 0 -#if MICROPY_DEBUG_VERBOSE // print debugging info -#define DEBUG_PRINT (1) -#define DEBUG_printf(...) MP_PRN(MP_PRN_DEBUG, __VA_ARGS__) -#else // don't print debugging info -#define DEBUG_PRINT (0) -#define DEBUG_printf(...) -#endif -#endif From f57a8b5482e9b59dacc2f6493161e0eb92277fd6 Mon Sep 17 00:00:00 2001 From: IhorNehrutsa <70886343+IhorNehrutsa@users.noreply.github.com> Date: Tue, 18 Jul 2023 07:30:06 +0300 Subject: [PATCH 11/11] Update mpprint.h --- py/mpprint.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/py/mpprint.h b/py/mpprint.h index 6b8d2821ed801..249d8b0b71326 100755 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -79,8 +79,6 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...); int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif -#endif // MICROPY_INCLUDED_PY_MPPRINT_H - #if defined(MP_PRN_LEVEL) && (MP_PRN_LEVEL > 0) // Debug messages during code developing with MP_PRN(level, ...) & MP_PRN_LEVEL. // An approximate hierarchy of debug levels MP_PRN_LEVEL is: @@ -102,7 +100,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); if ((0 < level) && (level <= MP_PRN_LEVEL)) { \ mp_printf(MP_PYTHON_PRINTER, " MP_PRN_LEVEL=%d : ", level); \ mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__); \ - mp_printf(MP_PYTHON_PRINTER, " : LINE=%d FILE=%s\n", __LINE__, __FILE__); \ + mp_printf(MP_PYTHON_PRINTER, " : FUNC=%s LINE=%d FILE=%s\n", __FUNCTION__, __LINE__, __FILE__); \ } \ } while (0); #else @@ -113,19 +111,26 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); // Set MP_PRN_LEVEL in developed *.C or *.CPP file, for example #define MP_PRN_LEVEL 1000 // show all messages // Add MP_PRN() macro in code, like -void foo() { - MP_PRN(6, "Enter foo()") +void foo(int arg) { + MP_PRN(MP_PRN_TRACE, "Enter foo()") + if (arg < 0) { + MP_PRN(MP_PRN_WARNING, "arg=%d less zero", arg) + ... + } ... int value; ... // calculate value ... - MP_PRN(4, "See a value=%d", value) + MP_PRN(MP_PRN_INFO, "See a value=%d", value) ... - MP_PRN(6, "Exit foo()") + MP_PRN(MP_PRN_TRACE, "Exit foo()") } + // It is not a dogma. You may start debugging from level 3. #define MP_PRN_LEVEL 3 // Then add MP_PRN(3, ...) and when gets too much messages then change some messages to the next level MP_PRN(4, ...), or MP_PRN(2, ...) etc. // Then you may change MP_PRN_LEVEL to 2(reduce printing), and finally to 0(supress printing). */ + +#endif // MICROPY_INCLUDED_PY_MPPRINT_H