Skip to content

Commit d83f8a5

Browse files
authored
Merge pull request #422 from reliforp/fix-version-detection
Fix the target PHP version detection on some cases
2 parents 8d0c6d5 + 5d0abad commit d83f8a5

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/Command/Inspector/GetEgAddressCommand.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Reli\Lib\Elf\Parser\ElfParserException;
2222
use Reli\Lib\Elf\Tls\TlsFinderException;
2323
use Reli\Lib\PhpProcessReader\PhpGlobalsFinder;
24+
use Reli\Lib\PhpProcessReader\PhpVersionDetector;
2425
use Reli\Lib\Process\MemoryReader\MemoryReaderException;
2526
use Reli\Lib\Elf\Process\ProcessSymbolReaderException;
2627
use Symfony\Component\Console\Command\Command;
@@ -37,6 +38,7 @@ public function __construct(
3738
private TargetPhpSettingsFromConsoleInput $target_php_settings_from_console_input,
3839
private TargetProcessSettingsFromConsoleInput $target_process_settings_from_console_input,
3940
private TargetProcessResolver $target_process_resolver,
41+
private PhpVersionDetector $php_version_detector,
4042
private RetryingLoopProvider $retrying_loop_provider,
4143
) {
4244
parent::__construct();
@@ -65,11 +67,16 @@ public function execute(InputInterface $input, OutputInterface $output): int
6567

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

70+
$target_php_settings_version_decided = $this->php_version_detector->decidePhpVersion(
71+
$process_specifier,
72+
$target_php_settings
73+
);
74+
6875
// see the comment at GetTraceCommand::execute()
6976
$eg_address = $this->retrying_loop_provider->do(
7077
try: fn () => $this->php_globals_finder->findExecutorGlobals(
7178
$process_specifier,
72-
$target_php_settings
79+
$target_php_settings_version_decided
7380
),
7481
retry_on: [\Throwable::class],
7582
max_retry: 10,

src/Command/Inspector/MemoryCommand.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,14 @@ public function execute(InputInterface $input, OutputInterface $output): int
7777
defer($scope_guard, fn () => $this->process_stopper->resume($process_specifier->pid));
7878
}
7979

80-
$eg_address = $this->php_globals_finder->findExecutorGlobals($process_specifier, $target_php_settings);
81-
$cg_address = $this->php_globals_finder->findCompilerGlobals($process_specifier, $target_php_settings);
80+
$eg_address = $this->php_globals_finder->findExecutorGlobals(
81+
$process_specifier,
82+
$target_php_settings_version_decided
83+
);
84+
$cg_address = $this->php_globals_finder->findCompilerGlobals(
85+
$process_specifier,
86+
$target_php_settings_version_decided
87+
);
8288

8389
$collected_memories = $this->memory_locations_collector->collectAll(
8490
$process_specifier,

src/Lib/PhpProcessReader/PhpGlobalsFinder.php

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function getSymbolReader(
7676
}
7777

7878
/**
79+
* @param TargetPhpSettings<value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS>> $target_php_settings
7980
* @throws ElfParserException
8081
* @throws MemoryReaderException
8182
* @throws ProcessSymbolReaderException
@@ -93,6 +94,7 @@ public function findExecutorGlobals(
9394
}
9495

9596
/**
97+
* @param TargetPhpSettings<value-of<ZendTypeReader::ALL_SUPPORTED_VERSIONS>> $target_php_settings
9698
* @throws ElfParserException
9799
* @throws MemoryReaderException
98100
* @throws ProcessSymbolReaderException

0 commit comments

Comments
 (0)