Skip to content

Commit

Permalink
Merged pull request #543
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Jan 17, 2020
2 parents 98b7b3e + 9bd6c30 commit 51652b5
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/debugger/debugger.c
Expand Up @@ -289,7 +289,7 @@ void xdebug_debugger_throw_exception_hook(zend_class_entry * exception_ce, zval
/* Start JIT if requested and not yet enabled */
xdebug_do_jit();

if (xdebug_is_debug_connection_active_for_current_pid()) {
if (xdebug_is_debug_connection_active_for_current_pid() && XG_DBG(breakpoints_allowed)) {
int exception_breakpoint_found = 0;

/* Check if we have a wild card exception breakpoint */
Expand Down Expand Up @@ -701,10 +701,10 @@ static void resolve_breakpoints_for_eval(int eval_id, zend_op_array *opa)
xdebug_lines_list *lines_list;
char *eval_filename = xdebug_sprintf("dbgp://%d", eval_id);
zend_string *eval_string = zend_string_init(eval_filename, strlen(eval_filename), 0);

lines_list = get_file_function_line_list(eval_string);
add_function_to_lines_list(lines_list, opa);

resolve_breakpoints_for_function(lines_list, opa);

if (!xdebug_is_debug_connection_active_for_current_pid()) {
Expand All @@ -717,7 +717,7 @@ static void resolve_breakpoints_for_eval(int eval_id, zend_op_array *opa)
&(XG_DBG(context)),
eval_string
);

zend_string_release(eval_string);
xdfree(eval_filename);
}
Expand Down
6 changes: 3 additions & 3 deletions src/debugger/handler_dbgp.c
Expand Up @@ -1036,12 +1036,12 @@ static int xdebug_do_eval(char *eval_string, zval *ret_zval)
EG(error_reporting) = 0;
PG(track_errors) = 0;

/* Do evaluation */
XG_DBG(breakpoints_allowed) = 0;

/* Reset exception in case we're triggered while being in xdebug_throw_exception_hook */
EG(exception) = NULL;

/* Do evaluation */
zend_first_try {
res = zend_eval_string(eval_string, ret_zval, (char*) "xdebug://debug-eval");
} zend_end_try();
Expand Down Expand Up @@ -2827,7 +2827,7 @@ static void breakpoint_resolve_helper(void *rctxt, xdebug_hash_element *he)
xdebug_brk_info *brk_info;

brk_info = breakpoint_brk_info_fetch(admin->type, admin->key);

ctxt->context->handler->log(XDEBUG_LOG_DEBUG, "Breakpoint %d (type: %s)\n", admin->id, XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type));

/* Bail early if it's already resolved */
Expand Down Expand Up @@ -2862,7 +2862,7 @@ static void breakpoint_resolve_helper(void *rctxt, xdebug_hash_element *he)
}
}

/* Fetches the lines list for 'filename', and loops over all breakpoints to try
/* Fetches the lines list for 'filename', and loops over all breakpoints to try
* to resolve them at run-time */
int xdebug_dbgp_resolve_breakpoints(xdebug_con *context, zend_string *filename)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/debugger/bug01735.inc
@@ -0,0 +1,14 @@
<?php
error_reporting( -1 );
function error_handler( int $errno, string $errstr, ...$rest)
{
echo "IN ERROR HANDLER\n";
throw new ErrorException( $errstr );
}

set_error_handler( 'error_handler' );

$variable1 = 42;
$variable2 = 42;
$variable3 = 42;
?>
73 changes: 73 additions & 0 deletions tests/debugger/bug01735.phpt
@@ -0,0 +1,73 @@
--TEST--
Test for bug #1735: DBGp eval warning promoted to Exception causes out-of-sync responses
--SKIPIF--
<?php
require __DIR__ . '/../utils.inc';
check_reqs('dbgp');
?>
--INI--
xdebug.auto_trace=0
--FILE--
<?php
require 'dbgp/dbgpclient.php';

$filename = dirname(__FILE__) . '/bug01735.inc';

$commands = array(
'feature_set -n resolved_breakpoints -v 1',
'breakpoint_set -t exception -x *',
'step_into',
'breakpoint_set -t line -n 11',
'run',
'eval -- JHJlc3VsdEpzb24=',
'context_names',
'step_over',
'step_over',
'detach',
);

dbgpRunFile( $filename, $commands );
?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://bug01735.inc" language="PHP" xdebug:language_version="" protocol_version="1.0" appid="" idekey=""><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2099 by Derick Rethans]]></copyright></init>

-> feature_set -i 1 -n resolved_breakpoints -v 1
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>

-> breakpoint_set -i 2 -t exception -x *
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="" resolved="resolved"></response>

-> step_into -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="3" status="break" reason="ok"><xdebug:message filename="file://bug01735.inc" lineno="2"></xdebug:message></response>

-> breakpoint_set -i 4 -t line -n 11
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="" resolved="resolved"></response>

-> run -i 5
<?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="5" status="break" reason="ok"><xdebug:message filename="file://bug01735.inc" lineno="11"></xdebug:message></response>

-> eval -i 6 -- JHJlc3VsdEpzb24=
<?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="6" status="break" reason="ok"><error code="206"><message><![CDATA[error evaluating code]]></message></error></response>

-> context_names -i 7
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_names" transaction_id="7"><context name="Locals" id=""></context><context name="Superglobals" id=""></context><context name="User defined constants" id=""></context></response>

-> step_over -i 8
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_over" transaction_id="8" status="break" reason="ok"><xdebug:message filename="file://bug01735.inc" lineno="12"></xdebug:message></response>

-> step_over -i 9
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_over" transaction_id="9" status="break" reason="ok"><xdebug:message filename="file://bug01735.inc" lineno="13"></xdebug:message></response>

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

0 comments on commit 51652b5

Please sign in to comment.