From a9c2899fc7aee542b6bd9b50f5c75e321f410d68 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 1 Jan 2018 12:11:15 -0800 Subject: [PATCH 1/2] Remove warnings when NDEBUG build option used When building using the new NDEBUG option recently added, the assert() macro is defined to nothing. This leaves a few variables unused in the WiFi stack causing compiler warnings. Add in empty casts to remove these warnings. Does not affect actual assert use when NDEBUG is not defined. --- libraries/ESP8266WiFi/src/include/ClientContext.h | 1 + libraries/ESP8266WiFi/src/include/DataSource.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h index b3784d25ed..555625172f 100644 --- a/libraries/ESP8266WiFi/src/include/ClientContext.h +++ b/libraries/ESP8266WiFi/src/include/ClientContext.h @@ -503,6 +503,7 @@ class ClientContext err_t _connected(struct tcp_pcb *pcb, err_t err) { (void) err; + (void) pcb; assert(pcb == _pcb); assert(_connect_pending); esp_schedule(); diff --git a/libraries/ESP8266WiFi/src/include/DataSource.h b/libraries/ESP8266WiFi/src/include/DataSource.h index 77eb78b676..e5255797cb 100644 --- a/libraries/ESP8266WiFi/src/include/DataSource.h +++ b/libraries/ESP8266WiFi/src/include/DataSource.h @@ -31,12 +31,14 @@ class BufferDataSource : public DataSource { const uint8_t* get_buffer(size_t size) override { + (void) size; assert(_pos + size <= _size); return _data + _pos; } void release_buffer(const uint8_t* buffer, size_t size) override { + (void) buffer; assert(buffer == _data + _pos); _pos += size; } @@ -69,6 +71,7 @@ class BufferedStreamDataSource : public DataSource { _bufferSize = size; } size_t cb = _stream.readBytes(reinterpret_cast(_buffer.get()), size); + (void) cb; assert(cb == size); return _buffer.get(); } From a31cf3b738718b831225665d8db518fa22bc0892 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 2 Jan 2018 11:46:31 -0800 Subject: [PATCH 2/2] Add assertion condition output on Panic line The condition that failed was not being printed in the Panic line, and was in fact completely thrown away. Now print out that an assertion failed and show the condition on a failed assert(). >Panic : : Assertion '' failed. > >ctx: cont >sp: 3fff0240 end: 3fff0410 offset: 01a0 >>>stack>>> .... --- cores/esp8266/core_esp8266_postmortem.c | 8 +++++++- tools/sdk/libc/xtensa-lx106-elf/include/assert.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/core_esp8266_postmortem.c b/cores/esp8266/core_esp8266_postmortem.c index bfb0c06ac3..c93a77fe2e 100644 --- a/cores/esp8266/core_esp8266_postmortem.c +++ b/cores/esp8266/core_esp8266_postmortem.c @@ -38,6 +38,7 @@ extern cont_t g_cont; static const char* s_panic_file = 0; static int s_panic_line = 0; static const char* s_panic_func = 0; +static const char* s_panic_what = 0; static bool s_abort_called = false; @@ -85,6 +86,11 @@ void __wrap_system_restart_local() { ets_puts_P(s_panic_file); ets_printf(":%d ", s_panic_line); ets_puts_P(s_panic_func); + if (s_panic_what) { + ets_puts_P(PSTR(": Assertion '")); + ets_puts_P(s_panic_what); + ets_puts_P(PSTR("' failed.")); + } ets_puts_P(PSTR("\n")); } else if (s_abort_called) { @@ -203,10 +209,10 @@ void abort(){ } void __assert_func(const char *file, int line, const char *func, const char *what) { - (void) what; s_panic_file = file; s_panic_line = line; s_panic_func = func; + s_panic_what = what; gdb_do_break(); } diff --git a/tools/sdk/libc/xtensa-lx106-elf/include/assert.h b/tools/sdk/libc/xtensa-lx106-elf/include/assert.h index 17b6d85dd7..83801e34e0 100644 --- a/tools/sdk/libc/xtensa-lx106-elf/include/assert.h +++ b/tools/sdk/libc/xtensa-lx106-elf/include/assert.h @@ -15,7 +15,7 @@ extern "C" { # define assert(__e) ((void)0) #else # define assert(__e) ((__e) ? (void)0 : __assert_func (PSTR(__FILE__), __LINE__, \ - __ASSERT_FUNC, #__e)) + __ASSERT_FUNC, PSTR(#__e))) # ifndef __ASSERT_FUNC /* Use g++'s demangled names in C++. */