read_file
Read C/C++ source files with ifdef-filtered content that matches the current build configuration, preserving line numbers by replacing inactive branches with blank lines.
Instructions
Read a complete C/C++ source file with ifdef-filtered content —
only code that actually compiles for the current build configuration.
Inactive #ifdef branches are replaced with blank lines (preserving
original line numbers).
Use this to read a file without leaving the fw-context ecosystem.
Unlike generic file readers, this tool returns build-accurate content:
code gated behind #ifdef BOARD_V2 stays visible only when
BOARD_V2 is actually defined for this build. Line numbers match
the original file — inactive branches appear as blank lines.
For reading a single function body with libclang exact extents use
get_source. For body + callers + callees in one call use
get_symbol_context. For a structural overview without content use
get_file_map. For searching patterns across files use
search_content.
Read-only. No side effects. Falls back to raw disk content (with a
warning) when the indexed files.content column is empty — e.g. on
a legacy index that predates this feature. Run fw-context index
to populate the ifdef-filtered content.
Args:
file_path: Path relative to project root, or just the filename.
E.g. src/main.cpp or main.cpp.
project_root: Project root. Auto-detected if omitted.
Returns:
dict: {file (str), language (str — "c" or "cpp"),
mtime (float), lines (int — total line count),
content (str — the complete ifdef-filtered file text),
warning (str, optional — when reading from raw disk instead of
indexed content)}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to source file — relative to project root or just filename. | |
| project_root | No | Project root. Auto-detected if omitted. |