Skip to content

Commit

Permalink
Add DBGp Proxy IDE Key support (#137)
Browse files Browse the repository at this point in the history
* Add DBGp Proxy IDE key support

* Don't check IDE key in unrelated tests

* Test for IDE key
  • Loading branch information
MichaelGooden authored Jul 28, 2021
1 parent cb5d358 commit 467813a
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/remote_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class RemoteDebugger : public DebuggerModeBase {

ssize_t send_init_event_message();

char *yasd_debugger_get_ide_key();
int parse_feature_set_cmd();
int parse_feature_get_cmd();
int parse_stdout_cmd();
Expand Down
1 change: 1 addition & 0 deletions php_yasd.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ ZEND_BEGIN_MODULE_GLOBALS(yasd)
int remote_autostart;
int remote_connect_back;
char *remote_mode;
char *ide_key;
ZEND_END_MODULE_GLOBALS(yasd)

extern ZEND_DECLARE_MODULE_GLOBALS(yasd);
Expand Down
13 changes: 12 additions & 1 deletion src/remote_debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ ssize_t RemoteDebugger::send_init_event_message() {
.set_debugger_name("Yasd")
.set_debugger_version(PHP_YASD_VERSION)
.set_fileuri("file://" + std::string(yasd::util::execution::get_filename()))
.set_idekey("hantaohuang")
.set_idekey(yasd_debugger_get_ide_key())
.set_language("PHP")
.set_language_version(PHP_VERSION)
.set_url("https://github.com/swoole/yasd");
Expand All @@ -206,6 +206,17 @@ ssize_t RemoteDebugger::send_init_event_message() {
return send_doc(doc.get());
}

char *RemoteDebugger::yasd_debugger_get_ide_key(void) {
char *ide_key;

ide_key = getenv("DBGP_IDEKEY");
if (ide_key && *ide_key) {
return ide_key;
}

return YASD_G(ide_key);
}

ssize_t RemoteDebugger::send_doc(tinyxml2::XMLDocument *doc) {
ssize_t ret;
yasd::Dbgp::make_message(doc, buffer);
Expand Down
1 change: 1 addition & 0 deletions tests/extension_ini/yasd.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ yasd.remote_host=127.0.0.1
yasd.remote_port=9000
yasd.max_executed_opline_num=50000
yasd.depth=1
xdebug.idekey=yasd-test
2 changes: 1 addition & 1 deletion tests/yasd_debugger/remote_mode/eval.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->st
?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://%s" language="PHP" xdebug:language_version="%s" protocol_version="1.0" appid="%s" idekey="hantaohuang"><engine version="%s"><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://%s" language="PHP" xdebug:language_version="%s" protocol_version="1.0" appid="%s" idekey=%s><engine version="%s"><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> eval -i 1 -- aW5pX2dldCgneWFzZC5kZWJ1Z19tb2RlJyk7
<?xml version="1.0" encoding="iso-8859-1"?>
Expand Down
2 changes: 1 addition & 1 deletion tests/yasd_debugger/remote_mode/feature_set.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->st
?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://%s" language="PHP" xdebug:language_version="%s" protocol_version="1.0" appid="%s" idekey="hantaohuang"><engine version="%s"><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://%s" language="PHP" xdebug:language_version="%s" protocol_version="1.0" appid="%s" idekey=%s><engine version="%s"><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> feature_set -i 1 -n show_hidden -v 1
<?xml version="1.0" encoding="iso-8859-1"?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $basename = basename(__FILE__, '.php');
$filename = realpath(dirname(__FILE__) . "/{$basename}.inc");

$code1 = base64_encode("isset(\$_SERVER['PHP_IDE_CONFIG'])");
$code2 = base64_encode("(string)(ini_get('xdebug.coverage_enable').';'.ini_get('xdebug.profiler_enable').';'.ini_get('xdebug.remote_autostart').';'.ini_get('xdebug.remote_connect_back').';'.ini_get('xdebug.remote_mode'))");
$code2 = base64_encode("(string)(ini_get('xdebug.coverage_enable').';'.ini_get('xdebug.profiler_enable').';'.ini_get('xdebug.remote_autostart').';'.ini_get('xdebug.remote_connect_back').';'.ini_get('xdebug.remote_mode').';'.ini_get('xdebug.ide_key'))");

$commands = [
"eval -- {$code1}",
Expand All @@ -32,14 +32,14 @@ $client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->st
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="1"><property type="bool"><![CDATA[0]]></property></response>

-> eval -i 2 -- KHN0cmluZykoaW5pX2dldCgneGRlYnVnLmNvdmVyYWdlX2VuYWJsZScpLic7Jy5pbmlfZ2V0KCd4ZGVidWcucHJvZmlsZXJfZW5hYmxlJykuJzsnLmluaV9nZXQoJ3hkZWJ1Zy5yZW1vdGVfYXV0b3N0YXJ0JykuJzsnLmluaV9nZXQoJ3hkZWJ1Zy5yZW1vdGVfY29ubmVjdF9iYWNrJykuJzsnLmluaV9nZXQoJ3hkZWJ1Zy5yZW1vdGVfbW9kZScpKQ==
-> eval -i 2 -- KHN0cmluZykoaW5pX2dldCgneGRlYnVnLmNvdmVyYWdlX2VuYWJsZScpLic7Jy5pbmlfZ2V0KCd4ZGVidWcucHJvZmlsZXJfZW5hYmxlJykuJzsnLmluaV9nZXQoJ3hkZWJ1Zy5yZW1vdGVfYXV0b3N0YXJ0JykuJzsnLmluaV9nZXQoJ3hkZWJ1Zy5yZW1vdGVfY29ubmVjdF9iYWNrJykuJzsnLmluaV9nZXQoJ3hkZWJ1Zy5yZW1vdGVfbW9kZScpLic7Jy5pbmlfZ2V0KCd4ZGVidWcuaWRlX2tleScpKQ==
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="2"><property type="string" size="11" encoding="base64"><![CDATA[MTsxOzE7MDtyZXE=]]></property></response>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="2"><property type="string" size="12" encoding="base64"><![CDATA[MTsxOzE7MDtyZXE7]]></property></response>

-> run -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="3" status="stopping" reason="ok"/>

-> stop -i 4
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="4" status="stopped" reason="ok"/>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="4" status="stopped" reason="ok"/>
4 changes: 4 additions & 0 deletions tests/yasd_debugger/remote_mode/phpstorm/idekey.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

return;
?>
39 changes: 39 additions & 0 deletions tests/yasd_debugger/remote_mode/phpstorm/idekey.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
phpstorm: idekey
--SKIPIF--
--FILE--
<?php

use Yasd\DbgpClient;

require dirname(__DIR__, 3) . '/Include/bootstrap.php';

$basename = basename(__FILE__, '.php');
$filename = realpath(dirname(__FILE__) . "/{$basename}.inc");

$code1 = base64_encode("ini_get('xdebug.ide_key')");

$commands = [
"eval -- {$code1}",
"run",
"stop"
];

$client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->start();

?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri=%s language="PHP" xdebug:language_version=%s protocol_version="1.0" appid=%s idekey="yasd-test"><engine version=%s><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> eval -i 1 -- aW5pX2dldCgneGRlYnVnLmlkZV9rZXknKQ==
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="1"><property type="bool"><![CDATA[0]]></property></response>

-> run -i 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="stopping" reason="ok"/>

-> stop -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="3" status="stopped" reason="ok"/>
2 changes: 1 addition & 1 deletion tests/yasd_debugger/remote_mode/stdout.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $client = (new DbgpClient())->setCommands($commands)->setTestFile($filename)->st
?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://%s" language="PHP" xdebug:language_version="%s" protocol_version="1.0" appid="%s" idekey="hantaohuang"><engine version="%s"><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://%s" language="PHP" xdebug:language_version="%s" protocol_version="1.0" appid="%s" idekey=%s><engine version="%s"><![CDATA[Yasd]]></engine><author><![CDATA[Codinghuang]]></author><url><![CDATA[https://github.com/swoole/yasd]]></url><copyright><![CDATA[Copyright (c) 2020-2021 by Codinghuang]]></copyright></init>

-> stdout -i 1
<?xml version="1.0" encoding="iso-8859-1"?>
Expand Down
2 changes: 2 additions & 0 deletions yasd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ STD_PHP_INI_ENTRY("xdebug.remote_connect_back", "0", PHP_INI_ALL, OnUpdateLong,
remote_autostart, zend_yasd_globals, yasd_globals)
STD_PHP_INI_ENTRY("xdebug.remote_mode", "req", PHP_INI_ALL, OnUpdateString,
remote_mode, zend_yasd_globals, yasd_globals)
STD_PHP_INI_ENTRY("xdebug.idekey", "hantaohuang", PHP_INI_ALL, OnUpdateStringUnempty,
ide_key, zend_yasd_globals, yasd_globals)
PHP_INI_END()
// clang-format on

Expand Down

0 comments on commit 467813a

Please sign in to comment.