You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Relay correct source paths in DWARF debug info (#2303)
## Motivation for the change, related issues
It is possible to build php-wasm with DWARF debug info today, but
actually using the debugger to step through source lines requires
additional configuration to map original source file paths (from Docker)
to actual source file paths in the host OS.
The purpose of this PR is to set the correct source paths at build time
so folks can debug php-wasm without additional configuration.
This is not just a matter of convenience. Some debuggers (VSCode) only
allow a single path mapping, so we cannot step into source files from
different directory subtrees at the same time (for example, php-src and
php_wasm.c). It would be simpler, faster, and more complete for
debugging with DWARF to work out of the box.
## Implementation details
This PR adds compilation flags like the following to establish
compilation dir and source file paths relative to that:
-
`-fdebug-compilation-dir=${OUTPUT_DIR_FOR_SOURCE_MAP_BASE}/${PHP_VERSION_ESCAPED}/`
-
`-fdebug-prefix-map=/root/php_wasm.c=${DEBUG_OFFSET_TO_PHP_WASM_PACKAGE}/compile/php/php_wasm.c`
## Testing Instructions (or ideally a Blueprint)
### For php-wasm/node
- Build a version of PHP for php-wasm/node
- Set a breakpoint at the beginning of `run_cli()` in `php_wasm.c`
- Run the "Debug PHP-WASM CLI with DWARF Symbols" target in VSCode
- Select the version of PHP built with debug info
- Observe you hit the breakpoint
- Step through execution and into a php-src file to demonstrate that
mapping works
### For php-wasm/web
- Build a version of PHP for php-wasm/web
- Run `npm run dev`
- Launch Chrome Canary
- Install the [C/C++ DevTools Support (DWARF)
extension](https://chromewebstore.google.com/detail/cc++-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb)
if you don't already have it
- Navigate to http://127.0.0.1:5400/website-server/
- Select the version of PHP built with debug info
- Open the devtools Sources tab
- Try to open `php_wasm.c`. If the file shows up, it indicates there are
DWARF mappings to that file.
- Try to open `zend_alloc.c`. If the file shows up, it indicates the
DWARF mappings to PHP source files are working.
- Set a breakpoint at an interesting place and try to hit it.
0 commit comments