Skip to content

Commit

Permalink
Merge pull request #422 from reliforp/fix-version-detection
Browse files Browse the repository at this point in the history
Fix the target PHP version detection on some cases
  • Loading branch information
sj-i authored Jan 27, 2024
2 parents 8d0c6d5 + 5d0abad commit d83f8a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Command/Inspector/GetEgAddressCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Reli\Lib\Elf\Parser\ElfParserException;
use Reli\Lib\Elf\Tls\TlsFinderException;
use Reli\Lib\PhpProcessReader\PhpGlobalsFinder;
use Reli\Lib\PhpProcessReader\PhpVersionDetector;
use Reli\Lib\Process\MemoryReader\MemoryReaderException;
use Reli\Lib\Elf\Process\ProcessSymbolReaderException;
use Symfony\Component\Console\Command\Command;
Expand All @@ -37,6 +38,7 @@ public function __construct(
private TargetPhpSettingsFromConsoleInput $target_php_settings_from_console_input,
private TargetProcessSettingsFromConsoleInput $target_process_settings_from_console_input,
private TargetProcessResolver $target_process_resolver,
private PhpVersionDetector $php_version_detector,
private RetryingLoopProvider $retrying_loop_provider,
) {
parent::__construct();
Expand Down Expand Up @@ -65,11 +67,16 @@ public function execute(InputInterface $input, OutputInterface $output): int

$process_specifier = $this->target_process_resolver->resolve($target_process_settings);

$target_php_settings_version_decided = $this->php_version_detector->decidePhpVersion(
$process_specifier,
$target_php_settings
);

// see the comment at GetTraceCommand::execute()
$eg_address = $this->retrying_loop_provider->do(
try: fn () => $this->php_globals_finder->findExecutorGlobals(
$process_specifier,
$target_php_settings
$target_php_settings_version_decided
),
retry_on: [\Throwable::class],
max_retry: 10,
Expand Down
10 changes: 8 additions & 2 deletions src/Command/Inspector/MemoryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ public function execute(InputInterface $input, OutputInterface $output): int
defer($scope_guard, fn () => $this->process_stopper->resume($process_specifier->pid));
}

$eg_address = $this->php_globals_finder->findExecutorGlobals($process_specifier, $target_php_settings);
$cg_address = $this->php_globals_finder->findCompilerGlobals($process_specifier, $target_php_settings);
$eg_address = $this->php_globals_finder->findExecutorGlobals(
$process_specifier,
$target_php_settings_version_decided
);
$cg_address = $this->php_globals_finder->findCompilerGlobals(
$process_specifier,
$target_php_settings_version_decided
);

$collected_memories = $this->memory_locations_collector->collectAll(
$process_specifier,
Expand Down
2 changes: 2 additions & 0 deletions src/Lib/PhpProcessReader/PhpGlobalsFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function getSymbolReader(
}

/**
* @param TargetPhpSettings<value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS>> $target_php_settings
* @throws ElfParserException
* @throws MemoryReaderException
* @throws ProcessSymbolReaderException
Expand All @@ -93,6 +94,7 @@ public function findExecutorGlobals(
}

/**
* @param TargetPhpSettings<value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS>> $target_php_settings
* @throws ElfParserException
* @throws MemoryReaderException
* @throws ProcessSymbolReaderException
Expand Down

0 comments on commit d83f8a5

Please sign in to comment.