Close

Disabling all Compiler Optimizations in the Pi Pico SDK

A project log for Raspberry Pi Pico Emulator

Live-coding an Open-Source Pico Emulator from Scratch

uri-shakedUri Shaked 03/31/2021 at 11:580 Comments

During our last live-hacking session, we discovered the compiler optimizations were severely limiting our ability to debug the code in the emulator. Function inlining, code rearrangement and tail call optimizations made debugging with GDB much more challenging.

After digging a bit in the Pico SDK's build system, we learned about a flag that disables all the compiler optimizations, PICO_DEOPTIMIZED_DEBUG.

Here's the complete sequence of commands for building the Pico examples in debug mode and without any compiler optimizations:

cd ~/pico/pico-examples/
rm -rf build
mkdir build
cd build
export PICO_SDK_PATH=../../pico-sdk
cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_DEOPTIMIZED_DEBUG=1 ..
make -j4

It is also possible to build just a specific example, by running the make -j4 command in a subdirectory of the build directory. e.g., to only build hello_uart, we'll first change the directory to uart/hello_uart:

cd uart/hello_uart
make -j4

Discussions