Skip to content

AOT: Debug symbols and source map for compiled binaries (-y flag) #75

@PurHur

Description

@PurHur

Problem

bin/compile.php -y emits .bc / .s beside the binary for debugging, but multi-file phpc build --project and deployed CGI binaries still lack practical PHP source line → native PC mapping when scripts segfault or print wrong output (#764).

Operators debugging empty stdout or native crashes need gdb/lldb without manually correlating LLVM IR.

Goal

Improve debuggability for AOT web binaries:

  1. Optional DWARF or line tables: PHP file:line → native address
  2. Document debugging workflow for examples/003-MiniWebApp/.phpc/bin/app
  3. Optional: per-module CFG dump in project build output dir

Implementation hints

Piece Files Notes
AOT emit lib/AOT/Linker.php, LLVM IR builder -g / DIBuilder line info from compile unit paths
CLI bin/compile.php, lib/Cli/PhpcBuild.php -y already dumps IR; extend --debug-symbols flag
Project build lib/Cli/PhpcBuild.php --project Emit build/debug/ with .s per unit when env set
Docs docs/deploy-web-aot.md, #445 gdb ./app, bt, map to Router.php:line

Suggested workflow (acceptance demo)

phpc build --project examples/003-MiniWebApp -y
gdb -batch -ex run -ex bt --args env QUERY_STRING=route=home ./examples/003-MiniWebApp/.phpc/bin/app
# backtrace shows PHP file:line when DWARF present

Acceptance criteria

Dependencies

Priority

Medium — production deploy + #764 triage.

Related

Verification

make docker-build-22
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  ./phpc build -y -o /tmp/dbg examples/000-HelloWorld/example.php

Links

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions