-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from sj-i/refactor-trace-reader
Refactor trace reader
- Loading branch information
Showing
27 changed files
with
1,358 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Lib\FFI; | ||
|
||
use FFI\CData; | ||
use PhpProfiler\Lib\PhpInternals\CastedCData; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
interface CastedTypeProvider | ||
{ | ||
/** @return CastedCData<CData> */ | ||
public function readAs(string $ctype_name, CData $buffer): CastedCData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Lib\PhpInternals\Types\C; | ||
|
||
use FFI\CData; | ||
use PhpProfiler\Lib\PhpInternals\CastedCData; | ||
use PhpProfiler\Lib\Process\Pointer\Dereferencable; | ||
use PhpProfiler\Lib\Process\Pointer\Pointer; | ||
|
||
final class RawString implements Dereferencable | ||
{ | ||
/** @psalm-suppress PropertyNotSetInConstructor */ | ||
public string $value; | ||
|
||
/** @param CastedCData<CData> $cdata */ | ||
public function __construct( | ||
private CastedCData $cdata, | ||
private int $len, | ||
) { | ||
unset($this->value); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function __get(string $field_name): string | ||
{ | ||
return match ($field_name) { | ||
'value' => $this->value = substr( | ||
\FFI::string($this->cdata->casted), | ||
0, | ||
$this->len | ||
), | ||
}; | ||
} | ||
|
||
public static function getCTypeName(): string | ||
{ | ||
return 'char[0]'; | ||
} | ||
|
||
/** @param CastedCData<CData> $casted_cdata */ | ||
public static function fromCastedCData( | ||
CastedCData $casted_cdata, | ||
Pointer $pointer | ||
): static { | ||
return new self($casted_cdata, $pointer->size); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Lib/PhpInternals/Types/Zend/ZendCastedTypeProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Lib\PhpInternals\Types\Zend; | ||
|
||
use FFI\CData; | ||
use PhpProfiler\Lib\FFI\CastedTypeProvider; | ||
use PhpProfiler\Lib\PhpInternals\CastedCData; | ||
use PhpProfiler\Lib\PhpInternals\ZendTypeReader; | ||
|
||
class ZendCastedTypeProvider implements CastedTypeProvider | ||
{ | ||
public function __construct( | ||
private ZendTypeReader $zend_type_reader, | ||
) { | ||
} | ||
|
||
public function readAs(string $ctype_name, CData $buffer): CastedCData | ||
{ | ||
/** @var CastedCData<CData> */ | ||
return $this->zend_type_reader->readAs($ctype_name, $buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Lib\PhpInternals\Types\Zend; | ||
|
||
use FFI\PhpInternals\zend_class_entry; | ||
use PhpProfiler\Lib\PhpInternals\CastedCData; | ||
use PhpProfiler\Lib\Process\Pointer\Dereferencable; | ||
use PhpProfiler\Lib\Process\Pointer\Dereferencer; | ||
use PhpProfiler\Lib\Process\Pointer\Pointer; | ||
|
||
final class ZendClassEntry implements Dereferencable | ||
{ | ||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
* @var Pointer<ZendString> | ||
*/ | ||
public Pointer $name; | ||
|
||
/** @param CastedCData<zend_class_entry> $casted_cdata */ | ||
public function __construct( | ||
private CastedCData $casted_cdata, | ||
) { | ||
unset($this->name); | ||
} | ||
|
||
public function __get(string $field_name) | ||
{ | ||
return match ($field_name) { | ||
'name' => $this->name = Pointer::fromCData( | ||
ZendString::class, | ||
$this->casted_cdata->casted->name, | ||
), | ||
}; | ||
} | ||
|
||
public static function getCTypeName(): string | ||
{ | ||
return 'zend_class_entry'; | ||
} | ||
|
||
public static function fromCastedCData( | ||
CastedCData $casted_cdata, | ||
Pointer $pointer | ||
): static { | ||
/** @var CastedCData<zend_class_entry> $casted_cdata */ | ||
return new self($casted_cdata); | ||
} | ||
|
||
public function getClassName(Dereferencer $dereferencer): string | ||
{ | ||
$string = $dereferencer->deref($this->name); | ||
$val = $string->getValuePointer($this->name); | ||
return (string)$dereferencer->deref($val); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Lib\PhpInternals\Types\Zend; | ||
|
||
use FFI\PhpInternals\zend_execute_data; | ||
use PhpProfiler\Lib\PhpInternals\CastedCData; | ||
use PhpProfiler\Lib\Process\Pointer\Dereferencable; | ||
use PhpProfiler\Lib\Process\Pointer\Dereferencer; | ||
use PhpProfiler\Lib\Process\Pointer\Pointer; | ||
|
||
final class ZendExecuteData implements Dereferencable | ||
{ | ||
/** @var Pointer<ZendFunction>|null */ | ||
public ?Pointer $func; | ||
|
||
/** @var Pointer<ZendExecuteData>|null */ | ||
public ?Pointer $prev_execute_data; | ||
|
||
/** @var Pointer<ZendOp>|null */ | ||
public ?Pointer $opline; | ||
|
||
/** @param CastedCData<zend_execute_data> $casted_cdata */ | ||
public function __construct( | ||
private CastedCData $casted_cdata, | ||
) { | ||
unset($this->func); | ||
unset($this->prev_execute_data); | ||
unset($this->opline); | ||
} | ||
|
||
public function __get(string $field_name): mixed | ||
{ | ||
return match ($field_name) { | ||
'func' => $this->casted_cdata->casted->func !== null | ||
? Pointer::fromCData( | ||
ZendFunction::class, | ||
$this->casted_cdata->casted->func, | ||
) | ||
: null | ||
, | ||
'prev_execute_data' => $this->casted_cdata->casted->prev_execute_data !== null | ||
? Pointer::fromCData( | ||
ZendExecuteData::class, | ||
$this->casted_cdata->casted->prev_execute_data, | ||
) | ||
: null | ||
, | ||
'opline' => $this->casted_cdata->casted->opline !== null | ||
? Pointer::fromCData( | ||
ZendOp::class, | ||
$this->casted_cdata->casted->opline | ||
) | ||
: null | ||
, | ||
}; | ||
} | ||
|
||
public static function getCTypeName(): string | ||
{ | ||
return 'zend_execute_data'; | ||
} | ||
|
||
public static function fromCastedCData( | ||
CastedCData $casted_cdata, | ||
Pointer $pointer | ||
): static { | ||
/** @var CastedCData<zend_execute_data> $casted_cdata */ | ||
return new self($casted_cdata); | ||
} | ||
|
||
public function getFunctionName(Dereferencer $dereferencer): ?string | ||
{ | ||
if (is_null($this->func)) { | ||
return null; | ||
} | ||
$func = $dereferencer->deref($this->func); | ||
return $func->getFullyQualifiedFunctionName($dereferencer); | ||
} | ||
} |
Oops, something went wrong.