Skip to content
Permalink
Browse files

tracing: Make functions and structures self-contained

  • Loading branch information...
derickr committed Nov 7, 2019
1 parent e503686 commit 284809eb5762a1343a90ce61bf2a53f2320b3f54
@@ -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"
@@ -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;
@@ -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)

@@ -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) \
@@ -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);
}
}

@@ -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
@@ -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);
@@ -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);
@@ -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 */
@@ -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);
@@ -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 |
@@ -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 {
@@ -21,7 +21,6 @@

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

typedef struct _xdebug_profiler_globals_t {
@@ -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"
@@ -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 |
@@ -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
{
@@ -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"
@@ -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 |
@@ -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
{
@@ -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"
@@ -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
{

0 comments on commit 284809e

Please sign in to comment.
You can’t perform that action at this time.