1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00
esp8266/tools/sdk/lwip2/include/gluedebug.h
Earle F. Philhower, III d979b57d76
Upgrade to GCC 10.1 toolchain (#6294)
* Upgrade to GCC 9.1 toolchain

* Rebuilt using pure GNU binutils and GCC

Remove dependencies on earlier forked GNU utilities (gcc-xtensa,
binutils-gdb-xtensa) and just use GCC sources, unmodified (except for
patches in the esp-quick-toolchain directories).

* Rebuild bearssl using new toolchain

* Fix GDBstub linkage options

GDB works with pure GNU GCC and pure GNU binutils now.  Still warnings
galore, but tested with the example sketch in the docs.

* Fix digitalRead alias warning

* Remove gdb stub warnings w/a pragma

* Fix deprecated implicit copy ctors in IP code

Fix some warnings present in GCC8/9 in the IPAddress code

In AddressListIterator there was a copy constructor which simply copied
the structure bit-for-bit.  That's the default operation, so remove it
to avoid the warning there.

IPAddress, add a default copy constructor since the other copy
constructors are simply parsing from one format into a native ip_addr_t.

@d-a-v, can you give these a look over and see if they're good (since
IP stuff is really your domain).

* Fix AxTLS alias function defs to match real code

* Fix WiFiClientSecure implicit default copy ctor

These both use shared-ptrs to handle refcnts to allocated data, so using
the default copy constructor is fine (and has been in use for a long
time).

* Dummy size for heap to avoid GCC 8/9 warnings

Make GCC think _heap_start is large enough to avoid the basic (and
incorrect) bounds-checking warnings it produces.  The size chosen is
arbitrary and does not affect the actual size of the heap in any way.

* Make heap an undefined extend array

Instead of a bogus size, use an indefinite size for the heap to avoid
GCC warnings

* Trivial tab to space fix

* Update SDFat to remove FatFile warnings

* Fix ticker function cast warnings in GCC 9

The callback function is defined to take a (void*) as parameter, but our
templates let users use anything that fits inside sizeof(void*) to be
passed in.  Add pragmas to stop GCC warnings about this, since we
already check the size of the type will fit in the allocated space.

* Remove GCC support fcn that's in ROM

Manually delete the divdi3.so from the libgcc.a library by running the
updated EQT's 9.1-post script.

* Make exceptions work again, get std::regex up

Exceptions are broken on all builds (GCC4.8-9.1) due to the removal of
the PROGMEM non-32b read exception handler (added in the unstable
pre3.0.0).

Build the exception code with -mforce-l32 and patch
accordingly to avoid LoadStore errors.

Apply patches to select portions of the regex lib which use _stype_
(which is now in flash).

* Rebuild Bearssl using latest GCC push

* Automate building of BearSSL and LWIP w/new toolchain

* Workaround g++ template section problem for exception strings

G++ seems to throw out the section attributes for templates.  This means
that the __EXCSTR(a synonym for "PSTR()") is ignored and exception.what
strings are stored in RODATA, eating up RAM.

Workaround by using the linker to place the strings keying off their name
("*__exception_what__*").

* Rebuild moving exception.what to unique names

Exception.whats are now all in __exception_what__ and can be moved by
the linker to flash.  Works aroung G++ issue with segments being lost in
templates.

* Rebuild with new LWIP locking

* Update to latest libs, save iram

Move two GCC FP support routines out of iram since they are in ROM
already, saving some add'l IRAM.  Same list as gcc 4.8.

* Update BearSSL to latest release

* Fix umm_perf reference to ROM function

* Fix "reinterpret_case is not a constexpr" error

In GCC 9 (and 8 from what I read on SO), a cast of a const int to a
function pointer (via explicit or implicit reinterpret_cast) is not a
constexpr.
````
/home/earle/Arduino/hardware/esp8266com/esp8266/cores/esp8266/umm_malloc/umm_performance.cpp:45:36: error: a reinterpret_cast is not a constant expression
   45 | int constexpr (*_rom_putc1)(int) = (int (*)(int))(void*)0x40001dcc;
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
````

Remove the constexpr, potentially increasing heap usage by 4 bytes in
debug mode.

* Update libc.a to latest rev

* Full rebuild of toolchain and libs

* Upgrade to GCC 9.2, released in August 2019

Add builds for all 5 cross-compiles to pass CI

* Move to --std=gnu++14 (C++14 + GNU extensions)

* Fix Ticker merge conflict

* Fix json merge conflict

* One more merge diff fix

* Reapply Ticker.h casting warning fixes for gcc9

* Update with fixes from Sming repo for PSTR and ASM

* Upgrade to -gnu4 toolchain

* Move to gnu5 build with add'l softFP from ROM

* Move add'l softFP from IRAM to flash

Per @mikee47, we miss sone add'l soft-FP routined in the linker which
makes them end up in IRAM.  Move them explicitly into flash, like a
couple others we have already done this for.

* Move to std=c++17/c17 in platform, remove abs/round

Move to C++17 and C17 standards on the compiler options.

Remove "register" from core since it is deprecated.

Remove the #define abs() and #define round() which a) overwrote the
C stdlib definitions, poorly, and b) broke the GCC core code which used
"abs" as an internal function name.

Now abs() returns an integer, and not whatever was being absoluted.
fabs() etc. can be used if users need fload/double suport.

round() returns a double now, which is basically what it was returning
in the original case since adding/subtracting by a FP.

* Use std::abs/round to replace the macro definitions

Per discussion w/@devyte, preserve the abs() and round() functionality
via the using statement.

* Remove using std::abs which conflicted with C lib headers

* Add 2nd arg (exception handler) to ets_isr_t

Disassembly of the ROM shows there are 2 params to the ets_isr_t
callback.  The first is the arg passed in, the second is a pointer to an
exception frame where you can get info about when the IRQ happened.

* Move the gdbstub example to a subdir

The Arduino IDE and the build CI don't build it without a subdir, so
make one for gdbstub's example so it's visible and tested.

* Fix ets_irq_arratch redefinition and core IRQ handlers

Remove a duplicated, different declaration for ets_irq_attach from
ets_sys.h.  It never really even matched the other declaration in the
same header.

Update the core to IRQ handlers to fix the prototype and include the
2nd, unused frame parameter.

* Actually rebuild the libc.a using GCC 9.2

* Fix SPISlave interrupt attach's 2nd parameter

* Rebuild eboot.elf with GCC 9

* Update to latest SoftwareSerial for Delegate fix

* Upgrade to GCC 9.3

* Rebuild all arch toolchains

* Move to GCC 10.1

* Merge master and fix eboot build

GCC10 now uses `-fno-common` so the eboot global variables were being
placed in IRAM.  Adjust the makefile and rebuild to fix.

* Built complete toolchain for all archs

* Pull in latest PSTR changes and fix GCC10.1 build

Somehow the prior GCC build's -mforce32 patch wasn't applying correctly,
but I was still able to get a binary.  Fixed.  Also pulled in latest
PSTR changes in progmem.h

* Update platform.io to platform C/C++ standards

* Use PR's toolchain in platformio build

* Fix several asm warnings in PIO build

* Optional stack smash protection -fstack-protector

Add a menu to enable GCC's built-in stack smash protection.  When a
subroutine goes past its end of stack, generate a crashdump on function
exit like:

````
GCC detected stack overrun
Stack corrupted, stack smash detected.

>>>stack>>>

ctx: cont
sp: 3fffff20 end: 3fffffc0 offset: 0000
3fffff20:  40202955 00000001 0000001c 4020287e
3fffff30:  feefeffe 000000fd 00000000 00000000
...
<<<stack<<<
````

Disabled by default because there is a small per-function code overhead
(and CPU time if the function is called very frequently and is very
small).

BearSSL and LWIP are not built using stack smash detection, yet.

* Fix duplicated stc=gnu99/c17 in build

* Dump faulting function PC in stack overflow

Report a fake exception to have the exception decoder print the actual
faulting function.  This won't tell you where in the function the issue
happened, but it will tell you the function name first and foremost.

* Rebuild with Platform.io JSON tag in release tgzs
2020-07-07 11:12:43 -07:00

135 lines
4.2 KiB
C

#ifndef __GLUE_DEBUG_H
#define __GLUE_DEBUG_H
// this file is commonly included by both sides of the glue
/////////////////////////////////////////////////////////////////////////////
// user-definable
// this is needed separately from lwipopts.h
// because it is shared by both sides of glue
#define UNDEBUG 1 // 0 or 1 (1: uassert removed)
#define UDEBUG 0 // 0 or 1 (glue debug)
#define UDUMP 0 // 0 or 1 (glue / dump packet)
#define UDEBUGINDEX 0 // 0 or 1 (show debug line number)
#define UDEBUGSTORE 0 // 0 or 1 (store debug into buffer until doprint_allow=1=serial-available)
#define ULWIPDEBUG 0 // 0 or 1 (trigger lwip debug)
#define ULWIPASSERT 0 // 0 or 1 (trigger lwip self-check, 0 saves flash)
#if ARDUINO
#define STRING_IN_FLASH 1 // *print("fmt is stored in flash")
#else
#define STRING_IN_FLASH 0 // *print("fmt is stored in flash")
#endif
#define ROTBUFLEN_BIT 11 // (UDEBUGSTORE=1) doprint()'s buffer: 11=2048B
#if ULWIPDEBUG
//#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT)
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH)
//#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON)
#endif
/////////////////////////////////////////////////////////////////////////////
// packet capture callback from esp side
#include <stdlib.h>
#define HAS_PHY_CAPTURE 1
#ifdef __cplusplus
extern "C" {
#endif
extern void (*phy_capture) (int netif_idx, const char* data, size_t len, int out, int success);
#ifdef __cplusplus
}
#endif
/////////////////////////////////////////////////////////////////////////////
#if ARDUINO
#include <sys/pgmspace.h>
#endif
#if UDEBUG && UDEBUGSTORE
#warning use 'doprint_allow=1' right after Serial is enabled
extern int doprint_allow;
#endif
// print definitions:
// uprint(): always used by glue, defined as doprint() in debug mode or nothing()
// os_printf(): can be redefined as doprint()
// doprint(): always print, can be os_printf_plus() or defined in doprint.c (buffered)
// in buffered mode: doprint_allow=1 is needed after Serial.begin
#if STRING_IN_FLASH && !defined(USE_OPTIMIZE_PRINTF)
#define USE_OPTIMIZE_PRINTF // at least used in arduino/esp8266
#endif
// os_printf_plus() missing in osapi.h (fixed in arduino's sdk-2.1):
//extern int os_printf_plus (const char * format, ...) __attribute__ ((format (printf, 1, 2)));
#include <osapi.h> // os_printf* definitions + ICACHE_RODATA_ATTR
#if UDEBUG && (UDEBUGINDEX || UDEBUGSTORE)
// doprint() is used
#undef os_printf
#define os_printf(x...) do { doprint(x); } while (0)
#if STRING_IN_FLASH
#define doprint(fmt, ...) \
do { \
static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = fmt; \
doprint_minus(flash_str, ##__VA_ARGS__); \
} while(0)
#else // !STRING_IN_FLASH
#define doprint(fmt, ...) doprint_minus(fmt, ##__VA_ARGS__)
#endif // !STRING_IN_FLASH
int doprint_minus (const char* format, ...) __attribute__ ((format (printf, 1, 2))); // format in flash
#else // !( UDEBUG && (UDEBUGINDEX || UDEBUGSTORE) )
#define doprint(x...) do { os_printf(x); } while (0)
#endif // !( UDEBUG && (UDEBUGINDEX || UDEBUGSTORE) )
#if UDEBUG
#define uprint(x...) do { doprint(x); } while (0)
#else
#define uprint(x...) do { (void)0; } while (0)
#endif
#if ARDUINO
#define udoassert(assertion...) \
do { if ((assertion) == 0) { \
static const char assrt[] ICACHE_RODATA_ATTR STORE_ATTR = #assertion " wrong@"; \
os_printf_plus(assrt); \
static const char assrt_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
os_printf_plus(assrt_file); \
static const char assrt_line[] ICACHE_RODATA_ATTR STORE_ATTR = ":%d\n"; \
os_printf_plus(assrt_line, __LINE__); \
uhalt(); \
} } while (0)
#else
#define udoassert(assertion...) do { if ((assertion) == 0) { os_printf("assert fail: " #assertion " @%s:%d\n", __FILE__, __LINE__); uhalt(); } } while (0)
#endif
#if UNDEBUG
#define uassert(assertion...) do { (void)0; } while (0)
#else // !defined(UNDEBUG)
#define uassert(assertion...) udoassert(assertion)
#endif // !defined(UNDEBUG)
#define ualwaysassert(assertion...) udoassert(assertion)
#define uerror(x...) do { doprint(x); } while (0)
#define uhalt() do { *((int*)0) = 0; /* this triggers gdb */ } while (0)
#define nl() do { uprint("\n"); } while (0)
#endif