From e5be88ad15427f9a0ee31f4bb15a1434b9c52f79 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Mon, 27 Sep 2021 13:39:12 +0200 Subject: [PATCH] Berry print stack trace when exception, more detailed with line numbers if `#define USE_BERRY_DEBUG` --- CHANGELOG.md | 1 + lib/libesp32/Berry/default/berry_conf.h | 6 ++++++ tasmota/my_user_config.h | 1 + tasmota/xdrv_52_9_berry.ino | 3 +++ 4 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d5af56bc..daad6c405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - Support for Sensirion SCD40/SCD41 CO2 sensor (#13139) - Support for BL0939 energy monitor as used in ESP32 based Sonoff Dual R3 V2 Pow (#13195) - Command ``WebQuery GET|POST|PUT|PATCH [] `` to extent HTTP requests (#13209) +- Berry print stack trace when exception, more detailed with line numbers if `#define USE_BERRY_DEBUG` ### Changed - M5 Stack Core2 uses UNIVERSAL_DISPLAY with enabled LVGL as default now diff --git a/lib/libesp32/Berry/default/berry_conf.h b/lib/libesp32/Berry/default/berry_conf.h index 6f0f4a807..2514013b9 100644 --- a/lib/libesp32/Berry/default/berry_conf.h +++ b/lib/libesp32/Berry/default/berry_conf.h @@ -216,4 +216,10 @@ extern "C" { **/ #define be_assert(expr) assert(expr) +/* Tasmota debug specific */ +#ifdef USE_BERRY_DEBUG + #undef BE_DEBUG_RUNTIME_INFO + #define BE_DEBUG_RUNTIME_INFO 2 /* record line information in 16 bits */ +#endif // USE_BERRY_DEBUG + #endif diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 956913606..e0ac83ae7 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -982,6 +982,7 @@ #define USE_BERRY // Enable Berry scripting language #define USE_BERRY_PSRAM // Allocate Berry memory in PSRAM if PSRAM is connected - this might be slightly slower but leaves main memory intact + // #define USE_BERRY_DEBUG // Compile Berry bytecode with line number information, makes exceptions easier to debug. Adds +8% of memory consumption for compiled code #define USE_WEBCLIENT // Enable `webclient` to make HTTP/HTTPS requests. Can be disabled for security reasons. // #define USE_WEBCLIENT_HTTPS // Enable HTTPS outgoing requests based on BearSSL (much ligher then mbedTLS, 42KB vs 150KB) in insecure mode (no verification of server's certificate) // Note that only one cipher is enabled: ECDHE_RSA_WITH_AES_128_GCM_SHA256 which is very commonly used and highly secure diff --git a/tasmota/xdrv_52_9_berry.ino b/tasmota/xdrv_52_9_berry.ino index 36d006618..c3ec98c21 100644 --- a/tasmota/xdrv_52_9_berry.ino +++ b/tasmota/xdrv_52_9_berry.ino @@ -27,6 +27,7 @@ extern "C" { extern void be_load_custom_libs(bvm *vm); + extern void be_tracestack(bvm *vm); } const char kBrCommands[] PROGMEM = D_PRFX_BR "|" // prefix @@ -115,6 +116,8 @@ void BerryDumpErrorAndClear(bvm *vm, bool berry_console) { if (top >= 2 && be_isstring(vm, -1) && be_isstring(vm, -2)) { if (berry_console) { berry_log_C(PSTR(D_LOG_BERRY "Exception> '%s' - %s"), be_tostring(berry.vm, -2), be_tostring(berry.vm, -1)); + be_tracestack(vm); + top = be_top(vm); // update top after dump } else { AddLog(LOG_LEVEL_ERROR, PSTR(D_LOG_BERRY "Exception> '%s' - %s"), be_tostring(berry.vm, -2), be_tostring(berry.vm, -1)); }