source: trunk/bin/phpdop.phpr @ 1338

Last change on this file since 1338 was 1338, checked in by moo, 12 months ago

phpdop: show jumpouts/jmpins

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1#! /usr/bin/php
2<?php
3
4$srcdir = dirname(__FILE__);
5require_once("$srcdir/../lib/Decompiler.class.php");
6if (file_exists("$srcdir/phpdc.debug.php")) {
7    include("$srcdir/phpdc.debug.php");
8}
9
10function get_op($op)
11{
12    switch ($op['op_type']) {
13    case 1: // CONST
14        return var_export($op['constant'], true);
15
16    case 2: // IS_TMP_VAR
17        return 't@' . $op['var'];
18
19    case 4:
20        return 'v$' . $op['var'];
21
22    case 8: // UNUSED
23        if (isset($op['opline_num'])) {
24            return 'l#' . $op['opline_num'];
25        }
26        else {
27            return '-';
28        }
29
30    default:
31        return $op['op_type'] . $op['var'];
32    }
33}
34
35function dump_opcodes($op_array, $indent = '')
36{
37    global $decompiler;
38
39    $types = array('result' => 5, 'op1' => 20, 'op2' => 20);
40    $opcodes = &$op_array['opcodes'];
41    $decompiler->fixOpcode($opcodes);
42    $decompiler->buildJmpInfo($op_array);
43    foreach ($opcodes as $line => $op) {
44        echo $indent;
45        echo sprintf("%3d ", $op['lineno']);
46        echo sprintf("%3d ", $line);
47        $name = xcache_get_opcode($op['opcode']);
48
49        if (substr($name, 0, 5) == 'ZEND_') {
50            $name = substr($name, 5);
51        }
52        echo str_pad($name, 25);
53
54        foreach ($types as $t => $len) {
55            echo str_pad(isset($op[$t]) ? get_op($op[$t]) : "", $len);
56        }
57        printf("%5s", isset($op['extended_value']) ?  $op['extended_value'] : "");
58        if (isset($op['jmpouts']) || isset($op['jmpins'])) {
59            printf("%10s %10s"
60                    , (isset($op['jmpouts']) ? '>' . implode(',', $op['jmpouts']) : '')
61                    , (isset($op['jmpins']) ? '<' . implode(',', $op['jmpins']) : '')
62                    );
63        }
64        if (isset($op['isCatchBegin'])) {
65            echo 'CB';
66        }
67
68        echo "\n";
69    }
70}
71
72function dump_function($name, $func, $indent = '')
73{
74    if (isset($func['op_array'])) {
75        $op_array = $func['op_array'];
76        unset($func['op_array']);
77    }
78    else {
79        $op_array = null;
80    }
81    var_dump($func);
82    echo $indent, 'function ', $name, "\n";
83    if (isset($op_array)) {
84        dump_opcodes($op_array, "  " . $indent);
85    }
86}
87
88function dump_class($name, $class, $indent = '')
89{
90    if (isset($class['function_table'])) {
91        $funcs = $class['function_table'];
92        unset($class['function_table']);
93    }
94    else {
95        $funcs = null;
96    }
97    echo $indent, 'class ', $name, "\n";
98    if (isset($funcs)) {
99        foreach ($funcs as $name => $func) {
100            dump_function($name, $func, "  " . $indent);
101        }
102    }
103}
104
105if (!isset($argv[1])) {
106    die("Usage: $argv[0] <file>\n");
107}
108$decompiler = new Decompiler();
109if (isset($argv[2])) {
110    eval('$pk = ' . file_get_contents($argv[2]) . ';');
111}
112else {
113    $pk = xcache_dasm_file($argv[1]);
114}
115$op_array = $funcs = $classes = null;
116if (isset($pk['op_array'])) {
117    $op_array = $pk['op_array'];
118    unset($pk['op_array']);
119}
120if (isset($pk['function_table'])) {
121    $funcs = $pk['function_table'];
122    unset($pk['function_table']);
123}
124if (isset($pk['class_table'])) {
125    $classes = $pk['class_table'];
126    unset($pk['class_table']);
127}
128var_dump($pk);
129if (isset($classes)) {
130    foreach ($classes as $name => $class) {
131        dump_class($name, $class);
132    }
133}
134if (isset($funcs)) {
135    foreach ($funcs as $name => $func) {
136        dump_function($name, $func);
137    }
138}
139if (isset($op_array)) {
140    dump_opcodes($op_array);
141}
142
Note: See TracBrowser for help on using the repository browser.