Skip to content

feat(esp32): record debug info relative to the project root (#1414) - #1777

Merged
zackees merged 2 commits into
mainfrom
agent/dwarf-prefix-map
Oct 29, 2026
Merged

zackees merged 2 commits into
mainfrom
agent/dwarf-prefix-map

Conversation

@zackees

@zackees zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member

Makes the ESP32 build record debug-info paths relative to the project root, so
two byte-identical sketches in two directories compile to identical objects
and a compiler cache can serve the second one. First half of #1414
finding 1.

Why

The compiler records its working directory as DW_AT_comp_dir (absolute), so a
fresh project directory always produced a fresh object even though the flags and
source bytes were identical. That is the persist_failed: "same cache key produced different staged output bytes" mechanism #1347 documented for the
framework stage, reaching the sketch stage: #1414 measured one real compiler
execution per fresh directory, ~1.3 s for a blink.

Verified on this host with host gcc — two directories, same source, same flags:

NO FLAG:   6ac1535d… main.o (a)   2616d4d6… main.o (b)      different
WITH FLAG: 1076a916… mapped.o (a) 1076a916… mapped.o (b)    identical
DW_AT_comp_dir: .

What

  • fbuild_paths::BuildLayout::debug_prefix_map_args() (+ free
    debug_prefix_map_args(project_dir, build_dir)) returns
    -fdebug-prefix-map=<project>=.. compile_cwd_from_output already anchors
    the compile workspace at the project root and passes sources
    project-relative, so this makes DW_AT_comp_dir and every recorded source
    path location-independent. A build root outside the project
    (FBUILD_BUILD_DIR, explicit override) is mapped too, to the stable label
    fbuild-build, because stages that compile into it have no .fbuild
    component and pass absolute paths.
  • ESP32 orchestrator adds those flags to user_flags next to the existing
    -fmacro-prefix-map flags, before the user's own build_flags so a user map
    still wins.
  • rebuild_signature: -f{debug,file,macro}-prefix-map=OLD=NEW now normalizes
    OLD like any other path-bearing flag value. Without this the new flag would
    put the project path into the signature and give every project a unique core
    cache key — exactly the cache it exists to fill.

-fdebug-prefix-map and not -ffile-prefix-map: the umbrella spelling is
GCC 8+, while avr-gcc 7.3 and the legacy ESP32 GCC 5 only have the debug
variant, and __FILE__ is already covered by the existing -fmacro-prefix-map
flags. Debug info is the part that was not covered.

Cost / behaviour change

  • One-time full cold rebuild on ESP32 (the compile flags change, so cached
    objects and the core-cache key are invalidated once).
  • Debug info no longer contains absolute paths: DW_AT_comp_dir is ., and
    source names are the same project-relative ones already on the command line.
    Start gdb/lldb from the project root and it finds the files. A debugger
    started elsewhere needs set substitute-path <project> .. addr2line wants
    -p/a relative path, or set substitute-path.

Tests

  • crates/fbuild-paths: 4 new tests (build dir inside project → one flag;
    external build root → fbuild-build label; build dir == project → one flag;
    remap targets identical for two different project paths).
  • crates/fbuild-build-engine: 1 new test — two projects with the same
    -fdebug-prefix-map produce the same project-anchored rebuild signature,
    while a different remap target still differs.

Scope: #1414 finding 1 only. Findings 2 (compile-core-variant having compiled
nothing) and 4 (esptool re-proved per build) were already shipped in
#1537/#1559 and #1547; finding 5 (~930 ms unattributed) is still open and is
about adding phases before optimizing blind.

DW_AT_comp_dir was absolute, so two identical sketches in two directories
compiled to different objects and zccache could never serve the second one
(#1347's persist_failed mechanism, measured at ~1.3 s per fresh dir in
#1414 finding 1).

BuildLayout::debug_prefix_map_args emits -fdebug-prefix-map=<project>=.
(the compile workspace is already anchored at the project root and sources
are project-relative), plus a fbuild-build label when the build root sits
outside the project. The ESP32 orchestrator adds them next to the existing
-fmacro-prefix-map flags, before user build_flags.

rebuild_signature normalizes the OLD path of -f{debug,file,macro}-prefix-map
so the new flag does not give every project a unique core-cache key.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

`crates/fbuild-paths/src/lib.rs` crossed the 1000-LOC gate (1107) when the
debug-prefix-map code landed, and the LOC Gate job rejects any .rs file over
1000 lines that was not already over it on the base commit.

Move `DEBUG_PREFIX_MAP_ROOT`, the free `debug_prefix_map_args` function and
the `BuildLayout::debug_prefix_map_args` impl block into
`debug_prefix_map.rs`, with the tests in the sibling
`debug_prefix_map_tests.rs` (the crate's existing convention). lib.rs is back
to 998 LOC.

Also route the "is the build root inside the project" decision through
`fbuild_core::path::normalize_for_key` instead of a raw `Path::starts_with`
(`ban_raw_path_prefix_compare`, #952): a raw-vs-canonicalized pair would
otherwise emit a second, conflicting map for a build root that is already
covered by the project map.

No behavior change for normalized inputs: same flags, same order.
@zackees
zackees added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit cdd0b9e Oct 29, 2026
35 checks passed
@zackees
zackees deleted the agent/dwarf-prefix-map branch November 5, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant