Skip to content

Commit d4aa500

Browse files
committed
add implementations of addrx and constx for DWARF expressions
1 parent e618f62 commit d4aa500

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the sj-i/php-profiler package.
5+
*
6+
* (c) sji <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace PhpProfiler\Lib\Dwarf\Expression\Opcodes\LiteralEncodings;
15+
16+
use PhpProfiler\Lib\Dwarf\Expression\ExpressionContext;
17+
use PhpProfiler\Lib\Dwarf\Expression\Opcodes\Opcode;
18+
use PhpProfiler\Lib\Dwarf\Expression\Stack;
19+
20+
final class AddrConstX implements Opcode
21+
{
22+
public function __construct(
23+
private ExpressionContext $expression_context,
24+
) {
25+
}
26+
27+
public function execute(Stack $stack, ...$operands): int
28+
{
29+
$unit_die = $this->expression_context->getCompilationUnit()->unit_die;
30+
$address_table = $this->expression_context->getExecutableFile()->debug_addr->address_table;
31+
$address_base = $unit_die->getAddressBase();
32+
$address = $operands[0] * $address_table->address_table_header->address_size + $address_base;
33+
$index = $address / $address_table->address_table_header->address_size;
34+
35+
$stack->push($address_table->addresses[$index]);
36+
return 1;
37+
}
38+
}

src/Lib/Dwarf/Expression/Operation.php

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ public function getOpcode(ExpressionContext $expression_context): Opcode
221221
self::DW_OP_const8s, self::DW_OP_const8u,
222222
self::DW_OP_consts, self::DW_OP_constu
223223
=> new Constant(),
224+
self::DW_OP_constx, self::DW_OP_addrx
225+
=> new AddrConstX($expression_context),
224226
};
225227
}
226228

0 commit comments

Comments
 (0)