On this page

Debugging and profiling builds

Disambiguation (tenon build --profile vs tenon profile):

  • tenon build --profile / tenon run --profile (covered on this page) is a build mode flag that compiles native C with -g -O2 and frame pointers so external native profilers (perf, Instruments, addr2line) can sample tn_<name> symbols.
  • tenon profile [--dev] [path] [--json] [-- args...] is a separate built-in runtime profiler subcommand that compiles with TRT_PROFILE=1 / TRT_STATS=1, executes the program, and reports wall time, arena allocations/copies/peak bytes, top function hotspots, and static copy/check counts. See Mental Model & Concepts.

tenon build --debug and tenon run --debug compile with -g -Og and frame pointers. tenon build --profile / tenon run --profile use -g -O2 and frame pointers for optimized external profiling. The --debug and --profile flags are mutually exclusive. tenon build and tenon build --release remain optimized without debug information, while plain tenon run uses the dev C backend. Debug and profile modes map temporary build paths to the entry module directory and cache separately by mode.

Generated C uses #line directives to map functions and the C main wrapper to Tenon source lines. Compiler glue maps to a .tn.c pseudo-file. DWARF and source mapping are for the C backend; the interpreter emits no DWARF.

Use addr2line to resolve an address, readelf --debug-dump=line to inspect line tables, or objdump -dl to view disassembly with source. For profiling, run perf record -g ./program then perf report; samples are attributed to tn_<name> symbols. perf may require a suitable perf_event_paranoid setting. GDB is expected to work but is untested; Windows and macOS are untested.

tenon build --debug app.tn -o app
addr2line -e app 0xADDRESS
readelf --debug-dump=line app
objdump -dl app
tenon build --profile app.tn -o app
perf record -g ./app
perf report