Skip to content

Commit

Permalink
Merged pull request #516
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Nov 7, 2019
2 parents e503686 + 0e16291 commit 659fc16
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 123 deletions.
21 changes: 3 additions & 18 deletions php_xdebug.h
Expand Up @@ -34,6 +34,7 @@
#include "debugger/debugger.h"
#include "gcstats/gc_stats.h"
#include "profiler/profiler.h"
#include "tracing/tracing.h"
#include "lib/compat.h"
#include "lib/hash.h"
#include "lib/llist.h"
Expand Down Expand Up @@ -228,21 +229,6 @@ struct xdebug_base_info {
} settings;
};

struct xdebug_trace_info {
xdebug_trace_handler_t *trace_handler;
void *trace_context;

struct {
zend_bool auto_trace;
zend_bool trace_enable_trigger;
char *trace_enable_trigger_value;
char *trace_output_dir;
char *trace_output_name;
zend_long trace_options;
zend_long trace_format;
} settings;
};

struct xdebug_library_info
{
zend_execute_data *active_execute_data;
Expand All @@ -254,18 +240,19 @@ struct xdebug_library_info
ZEND_BEGIN_MODULE_GLOBALS(xdebug)
struct xdebug_base_info base;
struct xdebug_library_info library;
struct xdebug_trace_info trace;
struct {
xdebug_coverage_globals_t coverage;
xdebug_debugger_globals_t debugger;
xdebug_gc_stats_globals_t gc_stats;
xdebug_profiler_globals_t profiler;
xdebug_tracing_globals_t tracing;
} globals;
struct {
xdebug_coverage_settings_t coverage;
xdebug_debugger_settings_t debugger;
xdebug_gc_stats_settings_t gc_stats;
xdebug_profiler_settings_t profiler;
xdebug_tracing_settings_t tracing;
} settings;
ZEND_END_MODULE_GLOBALS(xdebug)

Expand All @@ -277,10 +264,8 @@ ZEND_END_MODULE_GLOBALS(xdebug)

#define XG_BASE(v) (XG(base.v))
#define XG_LIB(v ) (XG(library.v))
#define XG_TRACE(v) (XG(trace.v))

#define XINI_BASE(v) (XG(base.settings.v))
#define XINI_TRACE(v) (XG(trace.settings.v))

/* Needed for code coverage as Zend doesn't always add EXT_STMT when expected */
#define XDEBUG_SET_OPCODE_OVERRIDE_COMMON(oc) \
Expand Down
56 changes: 8 additions & 48 deletions src/base/base.c
Expand Up @@ -320,21 +320,9 @@ static void xdebug_execute_ex(zend_execute_data *execute_data TSRMLS_DC)
}

if (XG_BASE(level) == 0) {
/* Start profiler if requested, and we're in main script */
xdebug_profiler_init_if_requested(op_array);

/* Start auto-tracer if requested, and we're in main script */
if (
(XINI_TRACE(auto_trace) || xdebug_trigger_enabled(XINI_TRACE(trace_enable_trigger), "XDEBUG_TRACE", XINI_TRACE(trace_enable_trigger_value) TSRMLS_CC))
&& XINI_TRACE(trace_output_dir) && strlen(XINI_TRACE(trace_output_dir))
) {
/* In case we do an auto-trace we are not interested in the return
* value, but we still have to free it. */
xdfree(xdebug_start_trace(NULL, STR_NAME_VAL(op_array->filename), XINI_TRACE(trace_options) TSRMLS_CC));
}

/* Start GC stats collector if requested, and we're in main script */
xdebug_gcstats_init_if_requested(op_array);
xdebug_profiler_init_if_requested(op_array);
xdebug_tracing_init_if_requested(op_array);
}
}

Expand All @@ -352,9 +340,8 @@ static void xdebug_execute_ex(zend_execute_data *execute_data TSRMLS_DC)
}

function_nr = XG_BASE(function_count);
if (!fse->filtered_tracing && XG_TRACE(trace_context) && (XG_TRACE(trace_handler)->function_entry)) {
XG_TRACE(trace_handler)->function_entry(XG_TRACE(trace_context), fse, function_nr TSRMLS_CC);
}

xdebug_tracing_execute_ex(function_nr, fse);

fse->execute_data = EG(current_execute_data)->prev_execute_data;
#if PHP_VERSION_ID >= 70100
Expand Down Expand Up @@ -409,24 +396,7 @@ static void xdebug_execute_ex(zend_execute_data *execute_data TSRMLS_DC)
}


if (!fse->filtered_tracing && XG_TRACE(trace_context) && (XG_TRACE(trace_handler)->function_exit)) {
XG_TRACE(trace_handler)->function_exit(XG_TRACE(trace_context), fse, function_nr TSRMLS_CC);
}

/* Store return value in the trace file */
if (!fse->filtered_tracing && XINI_BASE(collect_return) && XG_TRACE(trace_context)) {
if (execute_data && execute_data->return_value) {
if (op_array->fn_flags & ZEND_ACC_GENERATOR) {
if (XG_TRACE(trace_handler)->generator_return_value) {
XG_TRACE(trace_handler)->generator_return_value(XG_TRACE(trace_context), fse, function_nr, (zend_generator*) execute_data->return_value TSRMLS_CC);
}
} else {
if (XG_TRACE(trace_handler)->return_value) {
XG_TRACE(trace_handler)->return_value(XG_TRACE(trace_context), fse, function_nr, execute_data->return_value TSRMLS_CC);
}
}
}
}
xdebug_tracing_execute_ex_end(function_nr, fse, execute_data);

/* Check for return breakpoints */
xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_RETURN);
Expand Down Expand Up @@ -486,10 +456,7 @@ static void xdebug_execute_internal(zend_execute_data *current_execute_data, zva

function_nr = XG_BASE(function_count);

if (!fse->filtered_tracing && fse->function.type != XFUNC_ZEND_PASS && XG_TRACE(trace_context) && (XG_TRACE(trace_handler)->function_entry)) {
function_call_traced = 1;
XG_TRACE(trace_handler)->function_entry(XG_TRACE(trace_context), fse, function_nr TSRMLS_CC);
}
function_call_traced = xdebug_tracing_execute_internal(function_nr, fse);

/* Check for entry breakpoints */
xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_CALL);
Expand Down Expand Up @@ -519,15 +486,8 @@ static void xdebug_execute_internal(zend_execute_data *current_execute_data, zva
/* We only call the function_exit handler and return value handler if the
* function call was also traced. Otherwise we end up with return trace
* lines without a corresponding function call line. */
if (function_call_traced && !fse->filtered_tracing && XG_TRACE(trace_context)) {
if (fse->function.type != XFUNC_ZEND_PASS && (XG_TRACE(trace_handler)->function_exit)) {
XG_TRACE(trace_handler)->function_exit(XG_TRACE(trace_context), fse, function_nr TSRMLS_CC);
}

/* Store return value in the trace file */
if (XINI_BASE(collect_return) && fse->function.type != XFUNC_ZEND_PASS && return_value && XG_TRACE(trace_handler)->return_value) {
XG_TRACE(trace_handler)->return_value(XG_TRACE(trace_context), fse, function_nr, return_value TSRMLS_CC);
}
if (function_call_traced) {
xdebug_tracing_execute_internal_end(function_nr, fse, return_value);
}

/* Check for return breakpoints */
Expand Down
14 changes: 0 additions & 14 deletions src/lib/private.h
Expand Up @@ -228,20 +228,6 @@ function_stack_entry *xdebug_get_stack_head(TSRMLS_D);
function_stack_entry *xdebug_get_stack_frame(int nr TSRMLS_DC);
function_stack_entry *xdebug_get_stack_tail(TSRMLS_D);

typedef struct
{
void *(*init)(char *fname, char *script_filename, long options TSRMLS_DC);
void (*deinit)(void *ctxt TSRMLS_DC);
void (*write_header)(void *ctxt TSRMLS_DC);
void (*write_footer)(void *ctxt TSRMLS_DC);
char *(*get_filename)(void *ctxt TSRMLS_DC);
void (*function_entry)(void *ctxt, function_stack_entry *fse, int function_nr TSRMLS_DC);
void (*function_exit)(void *ctxt, function_stack_entry *fse, int function_nr TSRMLS_DC);
void (*return_value)(void *ctxt, function_stack_entry *fse, int function_nr, zval *return_value TSRMLS_DC);
void (*generator_return_value)(void *ctxt, function_stack_entry *fse, int function_nr, zend_generator *generator TSRMLS_DC);
void (*assignment)(void *ctxt, function_stack_entry *fse, char *full_varname, zval *value, char *right_full_varname, const char *op, char *file, int lineno TSRMLS_DC);
} xdebug_trace_handler_t;


xdebug_hash* xdebug_declared_var_hash_from_llist(xdebug_llist *list);
int xdebug_trigger_enabled(int setting, const char *var_name, char *var_value);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/var.c
Expand Up @@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2018 Derick Rethans |
| Copyright (c) 2002-2019 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.01 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
Expand Down Expand Up @@ -63,18 +63,18 @@ HashTable *xdebug_objdebug_pp(zval **zval_pp, int *is_tmp TSRMLS_DC)
HashTable *tmp;

if (!XG_BASE(in_debug_info) && object_or_ancestor_is_internal(dzval) && Z_OBJ_HANDLER(dzval, get_debug_info)) {
void *old_trace = XG_TRACE(trace_context);
void *original_trace_context;
zend_object *orig_exception;

XG_TRACE(trace_context) = NULL;
xdebug_tracing_save_trace_context(&original_trace_context);
XG_BASE(in_debug_info) = 1;
orig_exception = EG(exception);
EG(exception) = NULL;

tmp = Z_OBJ_HANDLER(dzval, get_debug_info)(&dzval, is_tmp TSRMLS_CC);

XG_BASE(in_debug_info) = 0;
XG_TRACE(trace_context) = old_trace;
xdebug_tracing_restore_trace_context(original_trace_context);
EG(exception) = orig_exception;
return tmp;
} else {
Expand Down
1 change: 0 additions & 1 deletion src/profiler/profiler.h
Expand Up @@ -21,7 +21,6 @@

#include "php.h"
#include "TSRM.h"
#include "php_xdebug.h"
#include "lib/private.h"

typedef struct _xdebug_profiler_globals_t {
Expand Down
2 changes: 2 additions & 0 deletions src/tracing/trace_computerized.c
Expand Up @@ -18,6 +18,8 @@
#include "php.h"
#include "ext/standard/php_string.h"

#include "php_xdebug.h"
#include "tracing_private.h"
#include "trace_computerized.h"

#include "lib/var.h"
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/trace_computerized.h
Expand Up @@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2018 Derick Rethans |
| Copyright (c) 2002-2019 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.01 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
Expand All @@ -18,7 +18,7 @@
#ifndef XDEBUG_TRACE_COMPUTERIZED_H
#define XDEBUG_TRACE_COMPUTERIZED_H

#include "tracing.h"
#include "tracing_private.h"

typedef struct _xdebug_trace_computerized_context
{
Expand Down
4 changes: 4 additions & 0 deletions src/tracing/trace_html.c
Expand Up @@ -15,6 +15,10 @@
| Authors: Derick Rethans <derick@xdebug.org> |
+----------------------------------------------------------------------+
*/
#include "php.h"

#include "php_xdebug.h"
#include "tracing_private.h"
#include "trace_html.h"

#include "lib/var.h"
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/trace_html.h
Expand Up @@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2018 Derick Rethans |
| Copyright (c) 2002-2019 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.01 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
Expand All @@ -18,7 +18,7 @@
#ifndef XDEBUG_TRACE_HTML_H
#define XDEBUG_TRACE_HTML_H

#include "tracing.h"
#include "tracing_private.h"

typedef struct _xdebug_trace_html_context
{
Expand Down
3 changes: 2 additions & 1 deletion src/tracing/trace_textual.c
Expand Up @@ -18,7 +18,8 @@
#include "php.h"
#include "ext/standard/php_string.h"

#include "tracing.h"
#include "php_xdebug.h"
#include "tracing_private.h"
#include "trace_textual.h"

#include "lib/var.h"
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/trace_textual.h
Expand Up @@ -18,7 +18,7 @@
#ifndef XDEBUG_TRACE_TEXTUAL_H
#define XDEBUG_TRACE_TEXTUAL_H

#include "tracing.h"
#include "tracing_private.h"

typedef struct _xdebug_trace_textual_context
{
Expand Down

0 comments on commit 659fc16

Please sign in to comment.