php-src/scripts/gdb/debug_gdb_scripts_gen.php
Arnaud Le Blanc 9df1c930bf
GDB script improvements (#17227)
* Support IS_INDIRECT, IS_PTR, IS_ALIAS_PTR when printing zvals
* Pretty print the ce_flags field when pretty printing a zend_class_entry
* Pretty print the const flags when pretty printing a zend_class_constant
* Added a minimal zend_property_info pretty printer to pretty print the flags field
* Added minimal zend_function, zend_op_array, and zend_internal_function pretty printers: The string value is the function/method name, function type (user/internal), and location (when possible). The fn_flags field is pretty printed
* Added a minimal zend_op pretty printer to pretty print the opcode
* Added a zend_refcounted_h pretty printer to pretty print the type_info
* Added minimal pretty printers for zend_object and zend_array
* Print the type and address of pretty-printed structs
* Added gdb commands: print_fn_flags, print_ce_flags, print_prop_flags, print_const_flags, print_ref_type_info, print_opcode, dump_op_array
* Fields of type zend_string, zend_class_entry, zend_array are printed by default in all our pretty printers, using short representation
* Increased the maximum length of printed strings to 200 chars before truncation (was 50)
2025-01-30 12:22:07 +01:00

53 lines
1.5 KiB
PHP
Executable file

#!/usr/bin/env php
<?php
$rootDir = dirname(__DIR__, 2);
$mainDir = sprintf('%s/main', $rootDir);
$outputFile = sprintf('%s/debug_gdb_scripts.c', $mainDir);
printf("Generating %s\n", $outputFile);
$gdbscript = file_get_contents(sprintf("%s/.gdbinit", $rootDir));
$pyscript = file_get_contents(sprintf("%s/php_gdb.py", __DIR__));
// We can not inline .gdbinit, but we can embed it in the python script.
$pyscript = sprintf(
"gdb.execute('''\n%s\n''')\n%s",
addcslashes($gdbscript, '\'\\'),
$pyscript,
);
$ccode = sprintf(
<<<'C'
/*
* Generated by %s.
*
* This inlines .gdbinit and php_gdb.py into the .debug_gdb_scripts
* section of the binary, so that they can be found by gdb.
*
* See https://sourceware.org/gdb/current/onlinedocs/gdb.html/dotdebug_005fgdb_005fscripts-section.html#dotdebug_005fgdb_005fscripts-section
*/
asm(
".pushsection \".debug_gdb_scripts\", \"MS\",%%progbits,1\n"
".byte 4 /* Python Text */\n"
".ascii \"gdb.inlined-script\\n\"\n"
%s
".byte 0\n"
".popsection\n"
);
C,
basename(__FILE__),
implode("\n ", array_map(function ($line) {
$escapedPy = addcslashes($line."\n", "\"\n\\");
$escapedAsm = addcslashes(sprintf(".ascii \"%s\"\n", $escapedPy), "\"\n\\?");
return sprintf('"%s"', $escapedAsm);
}, explode("\n", $pyscript))),
);
$len = file_put_contents($outputFile, $ccode);
if ($len !== strlen($ccode)) {
printf("Failed\n");
exit(1);
}