source: trunk/bin/phpdop.phpr @ 1328

Last change on this file since 1328 was 1328, checked in by moo, 15 months ago

use dec for opline

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