| 1 | #! /usr/bin/php |
|---|
| 2 | <?php |
|---|
| 3 | |
|---|
| 4 | $srcdir = dirname(__FILE__); |
|---|
| 5 | if (file_exists("$srcdir/phpdc.debug.php")) { |
|---|
| 6 | include("$srcdir/phpdc.debug.php"); |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | function get_op($op) |
|---|
| 10 | { |
|---|
| 11 | switch ($op['op_type']) { |
|---|
| 12 | case 1: // CONST |
|---|
| 13 | return var_export($op['u.constant'], true); |
|---|
| 14 | |
|---|
| 15 | case 2: // IS_TMP_VAR |
|---|
| 16 | return 't@' . $op['u.var']; |
|---|
| 17 | |
|---|
| 18 | case 4: |
|---|
| 19 | return 'v$' . $op['u.var']; |
|---|
| 20 | |
|---|
| 21 | case 8: // UNUSED |
|---|
| 22 | if (isset($op['u.opline_num'])) { |
|---|
| 23 | return 'l#' . $op['u.opline_num']; |
|---|
| 24 | } |
|---|
| 25 | else { |
|---|
| 26 | return '-'; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | default: |
|---|
| 30 | return $op['op_type'] . $op['u.var']; |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | function dump_opcodes($op_array, $indent = '') |
|---|
| 35 | { |
|---|
| 36 | $types = array('result' => 5, 'op1' => 20, 'op2' => 20); |
|---|
| 37 | foreach ($op_array as $line => $op) { |
|---|
| 38 | echo $indent; |
|---|
| 39 | echo sprintf("%3d ", $op['lineno']); |
|---|
| 40 | echo sprintf("%3x ", $line); |
|---|
| 41 | $name = xcache_get_opcode($op['opcode']); |
|---|
| 42 | |
|---|
| 43 | if (substr($name, 0, 5) == 'ZEND_') { |
|---|
| 44 | $name = substr($name, 5); |
|---|
| 45 | } |
|---|
| 46 | echo str_pad($name, 25); |
|---|
| 47 | |
|---|
| 48 | foreach ($types as $t => $len) { |
|---|
| 49 | echo str_pad(isset($op[$t]) ? get_op($op[$t]) : "", $len); |
|---|
| 50 | } |
|---|
| 51 | printf("%5s", isset($op['extended_value']) ? $op['extended_value'] : ""); |
|---|
| 52 | |
|---|
| 53 | echo "\n"; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | function dump_function($name, $func, $indent = '') |
|---|
| 58 | { |
|---|
| 59 | if (isset($func['op_array'])) { |
|---|
| 60 | $op_array = $func['op_array']; |
|---|
| 61 | unset($func['op_array']); |
|---|
| 62 | } |
|---|
| 63 | else { |
|---|
| 64 | $op_array = null; |
|---|
| 65 | } |
|---|
| 66 | var_dump($func); |
|---|
| 67 | echo $indent, 'function ', $name, "\n"; |
|---|
| 68 | if (isset($op_array)) { |
|---|
| 69 | dump_opcodes($op_array['opcodes'], " " . $indent); |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | function dump_class($name, $class, $indent = '') |
|---|
| 74 | { |
|---|
| 75 | if (isset($class['function_table'])) { |
|---|
| 76 | $funcs = $class['function_table']; |
|---|
| 77 | unset($class['function_table']); |
|---|
| 78 | } |
|---|
| 79 | else { |
|---|
| 80 | $funcs = null; |
|---|
| 81 | } |
|---|
| 82 | echo $indent, 'class ', $name, "\n"; |
|---|
| 83 | if (isset($funcs)) { |
|---|
| 84 | foreach ($funcs as $name => $func) { |
|---|
| 85 | dump_function($name, $func, " " . $indent); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | if (!isset($argv[1])) { |
|---|
| 91 | die("Usage: $argv[0] <file>\n"); |
|---|
| 92 | } |
|---|
| 93 | $pk = xcache_dasm_file($argv[1]); |
|---|
| 94 | $op_array = $funcs = $classes = null; |
|---|
| 95 | if (isset($pk['op_array'])) { |
|---|
| 96 | $op_array = $pk['op_array']; |
|---|
| 97 | unset($pk['op_array']); |
|---|
| 98 | } |
|---|
| 99 | if (isset($pk['function_table'])) { |
|---|
| 100 | $funcs = $pk['function_table']; |
|---|
| 101 | unset($pk['function_table']); |
|---|
| 102 | } |
|---|
| 103 | if (isset($pk['class_table'])) { |
|---|
| 104 | $classes = $pk['class_table']; |
|---|
| 105 | unset($pk['class_table']); |
|---|
| 106 | } |
|---|
| 107 | var_dump($pk); |
|---|
| 108 | if (isset($op_array)) { |
|---|
| 109 | dump_opcodes($op_array['opcodes']); |
|---|
| 110 | } |
|---|
| 111 | if (isset($funcs)) { |
|---|
| 112 | foreach ($funcs as $name => $func) { |
|---|
| 113 | dump_function($name, $func); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | if (isset($classes)) { |
|---|
| 117 | foreach ($classes as $name => $class) { |
|---|
| 118 | dump_class($name, $class); |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | |
|---|