Skip to content

Commit 024c444

Browse files
committed
Update debug information
1 parent 32d51c2 commit 024c444

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

src/core/JavaClassInvoker.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,21 @@ public function debug(): void
115115

116116
$methodName = $cpInfo[$this->debugTraces['method']->getNameIndex()]->getString();
117117
$descriptor = Formatter::parseSignature($cpInfo[$this->debugTraces['method']->getDescriptorIndex()]->getString());
118-
$formattedArguments = implode(
119-
', ',
120-
array_map(
121-
function ($argument) {
122-
$arrayBrackets = str_repeat('[]', $argument['deep_array']);
123-
if ($argument['type'] === 'class') {
124-
return $argument['class_name'] . $arrayBrackets;
125-
}
126-
return $argument['type'] . $arrayBrackets;
127-
},
128-
$descriptor['arguments']
118+
$formattedArguments = str_replace(
119+
'/',
120+
'.',
121+
implode(
122+
', ',
123+
array_map(
124+
function ($argument) {
125+
$arrayBrackets = str_repeat('[]', $argument['deep_array']);
126+
if ($argument['type'] === 'class') {
127+
return $argument['class_name'] . $arrayBrackets;
128+
}
129+
return $argument['type'] . $arrayBrackets;
130+
},
131+
$descriptor['arguments']
132+
)
129133
)
130134
);
131135

@@ -141,13 +145,25 @@ function ($argument) {
141145
printf(ltrim("$methodAccessibility $type $methodName($formattedArguments)\n", ' '));
142146
printf("\n");
143147
printf("[code]\n");
148+
149+
$codeCounter = 0;
144150
printf(
145151
"%s\n",
146152
implode(
147153
"\n",
148154
array_map(
149-
function ($code) {
150-
return '<0x' . implode('> <0x', $code) . '>';
155+
function ($codes) use (&$codeCounter) {
156+
return implode(
157+
' ',
158+
array_map(
159+
function ($code) use (&$codeCounter) {
160+
$isMnemonic = in_array($codeCounter, $this->debugTraces['mnemonic_indexes']);
161+
$codeCounter++;
162+
return ($isMnemonic ? "\e[1m\e[35m" : "") . "<0x{$code}>" . ($isMnemonic ? "\e[m" : "");
163+
},
164+
$codes
165+
)
166+
);
151167
},
152168
array_chunk(str_split(bin2hex($this->debugTraces['raw_code']), 2), 20)
153169
)

src/core/jvm/invoker/Invokable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function __call($name, $arguments)
6464
// debug code attribution with HEX
6565
$this->debugTraces['raw_code'] = $codeAttribute->getCode();
6666
$this->debugTraces['method'] = $method;
67+
$this->debugTraces['mnemonic_indexes'] = [];
6768
$this->debugTraces['executed'] = [];
6869

6970
$reader = new BinaryReader($handle);
@@ -90,6 +91,7 @@ public function __call($name, $arguments)
9091

9192
$fullName = '\\PHPJava\\Kernel\\Mnemonics\\' . $mnemonic;
9293
$this->debugTraces['executed'][] = [$opcode, $mnemonic, $localStorage, $stacks, $pointer];
94+
$this->debugTraces['mnemonic_indexes'][] = $pointer;
9395

9496
/**
9597
* @var OperationInterface|Accumulator|ConstantPool $executor

0 commit comments

Comments
 (0)