#!/usr/bin/env python3 # trunk-ignore-all(ruff/F821) # trunk-ignore-all(flake8/F821): For SConstruct imports # # Opt-in DWARF, for source-level flash attribution (bin/flash_attribution.py). # # Set MESHTASTIC_DEBUG_INFO=1 in the environment to turn it on; the build is # untouched otherwise. Debug info lands in non-allocated .debug_* sections, so an # image built this way is the same size as the shipping one - measured on # nrf52_promicro_diy_tcxo, 0xE8610 with DWARF vs 0xE8618 without. # # Two things make this less obvious than "add -g": # # 1. nrf52.ini's build_unflags strips -g, -g0..-g3 and -ggdb2/3, so the usual # spellings are removed again after we add them. -gdwarf-4 is not in that # list and survives. # 2. Under -flto the final code is generated by lto1 during the LINK, so debug # info has to be requested on the link line as well. With -gdwarf-4 only on # the compile line, ~96% of an LTO'd nRF52 image resolves to "??" - the only # code carrying line info is what nrf52_lto.py holds out of LTO, plus the # precompiled vendor archives. Adding it to LINKFLAGS takes that to ~30%, # the rest being blobs with no source to point at (newlib, CryptoCell, BSEC) # and read-only data sharing .text. import os Import("env") if os.environ.get("MESHTASTIC_DEBUG_INFO", "") not in ("", "0"): env.Append(CCFLAGS=["-gdwarf-4"], LINKFLAGS=["-gdwarf-4"]) print("debug_info: DWARF enabled for size attribution (image size is unaffected)")