How to print all preprocessor flags in PlatformIO

In order to show the values of all preprocessor flags, set this in platformio.ini:

build_flags = -E -dM

Now rebuild and you’ll see an error message like

Linking .pio/build/ESP32/firmware.elf
.pio/build/ESP32/src/main.cpp.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
*** [.pio/build/ESP32/firmware.elf] Error 1

This error is expected since GCC will not produce object files as output but preprocessor output definitions!

Now open the respective “object” files in your text editor:

code .pio/build/ESP32/src/main.cpp.o

where ESP32 is the name of your build configuration in platformio.ini. You will see all the definitions like this:

#define VSPI 3
#define XTENSA_HWCIDVERS_T1030_3 12
#define GPIO_PIN19_INT_TYPE 0x00000007
#define CONFIG_LWIP_MAX_RAW_PCBS 16
#define XTENSA_HWVERSION_RD_2012_4 240004
#define SPI_CLOCK_DIV32 0x013c1001
#define VALUE_GET_FIELD(_r,_f) (((_r) >> (_f ##_S)) & (_f))
#define GPIO_FUNC40_IN_INV_SEL (BIT(6))
#define GPIO_SIG31_IN_SEL (BIT(7))
#define ETS_RWBLE_NMI_SOURCE 9
#define RTC_IO_PDAC1_DAC_S 19
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
#define RTC_IO_PDAC1_DAC_V 0xFF
#define XCHAL_INT30_TYPE XTHAL_INTTYPE_EXTERN_EDGE
#define _ETS_SET_INTLEVEL(intlevel) ({ unsigned __tmp; __asm__ __volatile__( "rsil   %0, " _ETSTR(intlevel) "\n" : "=a" (__tmp) : : "memory" ); })
#define B11101001 233
#define SPIWP_IN_IDX 4
#define MEMP_NUM_API_MSG MEMP_NUM_TCPIP_MSG_API
#define GPIO_FUNC74_IN_INV_SEL_M (BIT(6))
// ...