Skip to content

Commit

Permalink
Support phpstorm (#22)
Browse files Browse the repository at this point in the history
* Support phpstorm
  • Loading branch information
huanghantao authored Dec 13, 2020
1 parent 878f3fe commit 590689b
Show file tree
Hide file tree
Showing 12 changed files with 685 additions and 75 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ mkinstalldirs

# debug
debug
test.php
header.php
composer.json
composer.lock
vendor
Expand Down
3 changes: 3 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo "header.php" . PHP_EOL;
4 changes: 3 additions & 1 deletion include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# endif

zend_bool yasd_zend_hash_is_recursive(zend_array* ht);
zend_bool yasd_zend_hash_apply_protection_begin(zend_array* ht);
zend_bool yasd_zend_hash_apply_protection_end(zend_array* ht);

static void yasd_zend_update_property_null_ex(zend_class_entry *scope, zval *object, zend_string *s) {
zval tmp;
Expand Down Expand Up @@ -110,4 +112,4 @@ enum Color {

#define YASD_MSG_SIZE 16384

extern char yasd_info_buf[YASD_MSG_SIZE];
extern char yasd_info_buf[YASD_MSG_SIZE];
17 changes: 13 additions & 4 deletions include/remote_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ class RemoteDebugger : public DebuggerModeBase {
int execute_cmd();

void init_response_xml_root_node(tinyxml2::XMLElement *root, std::string cmd);
void init_xml_property_node(
tinyxml2::XMLElement *child, std::string name, zval *value, int level = 0, bool encoding = false);
void init_local_variables_xml_child_node(tinyxml2::XMLElement *root);
void init_superglobal_variables_xml_child_node(tinyxml2::XMLElement *root);
void init_user_defined_constant_variables_xml_child_node(tinyxml2::XMLElement *root);
void set_property_value_xml_property_node(tinyxml2::XMLElement *child,
std::string name,
zval *value,
bool encoding = false);

void init_zend_array_element_xml_property_node(
tinyxml2::XMLElement *child, std::string name, zval *value, int level = 0, bool encoding = false);

void init_zend_object_property_xml_property_node(
tinyxml2::XMLElement *child, std::string name, zval *value, int level = 0, bool encoding = false);

public:
RemoteDebugger() {}
Expand All @@ -63,13 +67,18 @@ class RemoteDebugger : public DebuggerModeBase {

ssize_t send_init_event_message();

int parse_feature_set_cmd();
int parse_stdout_cmd();
int parse_status_cmd();
int parse_eval_cmd();
int parse_breakpoint_list_cmd();
int parse_breakpoint_set_cmd();
int parse_breakpoint_set_exception_cmd();
int parse_run_cmd();
int parse_stack_get_cmd();
int parse_context_names_cmd();
int parse_context_get_cmd();
int parse_property_get_cmd();
int parse_stop_cmd();

void register_cmd_handler();
Expand Down
11 changes: 10 additions & 1 deletion include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Util {

static HashTable *get_defined_vars();
static zval *find_variable(std::string var_name);
static zval *find_variable(zend_array *symbol_table, std::string var_name);
static void print_var(std::string var_name);
static void print_property(std::string obj_name, std::string property_name);

Expand Down Expand Up @@ -62,6 +63,14 @@ class Util {

static bool is_hit_watch_point();

static bool is_integer(const std::string & s);
static bool is_integer(const std::string &s);

static bool eval(char *str, zval *retval_ptr, char *string_name);

static zend_array *get_properties(zval *zobj);

static std::string get_option_value(const std::vector<std::string> &options, std::string option);

static zval *fetch_zval_by_fullname(std::string fullname);
};
} // namespace yasd
28 changes: 28 additions & 0 deletions include/zend_property_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
+----------------------------------------------------------------------+
| Yasd |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: codinghuang <[email protected]> |
+----------------------------------------------------------------------+
*/
#pragma once

#include <string>

#include "main/php.h"

namespace yasd {
class ZendPropertyInfo {
public:
zend_string *property_name;
zval *value;
};
} // namespace yasd
1 change: 1 addition & 0 deletions php_yasd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ZEND_BEGIN_MODULE_GLOBALS(yasd)
char *debug_mode;
char *remote_host;
uint16_t remote_port;
uint16_t depth;
ZEND_END_MODULE_GLOBALS(yasd)

extern ZEND_DECLARE_MODULE_GLOBALS(yasd);
Expand Down
46 changes: 46 additions & 0 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,54 @@ char yasd_info_buf[YASD_MSG_SIZE];
zend_bool yasd_zend_hash_is_recursive(zend_array* ht) {
return (ZEND_HASH_GET_APPLY_COUNT(ht) > 0);
}

zend_bool yasd_zend_hash_apply_protection_begin(zend_array* ht) {
if (!ht) {
return 1;
}
if (ZEND_HASH_GET_APPLY_COUNT(ht) > 0) {
return 0;
}
if (ZEND_HASH_APPLY_PROTECTION(ht)) {
ZEND_HASH_INC_APPLY_COUNT(ht);
}
return 1;
}

zend_bool yasd_zend_hash_apply_protection_end(zend_array* ht) {
if (!ht) {
return 1;
}
if (ZEND_HASH_GET_APPLY_COUNT(ht) == 0) {
return 0;
}
if (ZEND_HASH_APPLY_PROTECTION(ht)) {
ZEND_HASH_DEC_APPLY_COUNT(ht);
}
return 1;
}
#else /* PHP 7.3 or later */
zend_bool yasd_zend_hash_is_recursive(zend_array* ht) {
return GC_IS_RECURSIVE(ht);
}

zend_bool yasd_zend_hash_apply_protection_begin(zend_array* ht) {
if (GC_IS_RECURSIVE(ht)) {
return 0;
}
if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) {
GC_PROTECT_RECURSION(ht);
}
return 1;
}

zend_bool yasd_zend_hash_apply_protection_end(zend_array* ht) {
if (!GC_IS_RECURSIVE(ht)) {
return 0;
}
if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) {
GC_UNPROTECT_RECURSION(ht);
}
return 1;
}
#endif
Loading

0 comments on commit 590689b

Please sign in to comment.