View Issue Details

IDProjectCategoryView StatusLast Update
0002134XdebugStep Debuggingpublic2022-12-08 18:51
Reporterbarel Assigned Toderick  
PrioritylowSeverityminorReproducibilityalways
Status closedResolutionno change required 
OSUbuntu 
Product Version3.1.5 
Fixed in Version3.2.0 
Summary0002134: Xdebug stops at the line where the exception is created, not where it is thrown
Description

If you create an Exception object by using new Exception... and then later in the code you throw this object and Xdebug is set to break on exception, the line where the code will stop is the line where the exception is created, not where it is thrown, which is very unintuitive

Steps To Reproduce

Run the test xdebug/tests/debugger/bug01218-002.phpt. Once the exception breakpoint is thrown you will see this response:

<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file://bug01218.inc" lineno="12" exception="StringCodeException" code="SomeString"><![CDATA[test]]></xdebug:message></response>

I would expect to see this response:

<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file://bug01218.inc" lineno="15" exception="StringCodeException" code="SomeString"><![CDATA[test]]></xdebug:message></response>

as the line where the exception is thrown is line 15, not line 12

Additional Information

Have only tested it with PHP 7.4 but I expect this to happen in all supported PHP versions as the test is the same for all of them

TagsNo tags attached.
Operating SystemUbuntu
PHP Version7.4.30-7.4.39

Activities

derick

2022-11-03 09:41

administrator   ~0006435

This is the correct behaviour. The <xdebug:message section is not where the exception was thrown, but where it was created. It reproduces the information that is stored in the Exception itself, and is analogous to doing this:

  1 <?php
  2 $a = new Exception;
  3 
  4 
  5 var_dump($a);

Which also results in:

/tmp/foo.php:5:
class Exception#1 (7) {
  protected $message =>
  string(0) ""
  private string $string =>
  string(0) ""
  protected $code =>
  int(0)
  protected string $file =>
  string(12) "/tmp/foo.php"
  protected int $line =>
  int(2)
  private array $trace =>
  array(0) {
  }
  private ?Throwable $previous =>
  NULL
}

If you want to know the current execution location, you need to send the stack_get DBGp command.

cheers,
Derick

derick

2022-11-03 09:43

administrator   ~0006436

I might be changing my mind on this...

derick

2022-11-08 18:18

administrator   ~0006443

https://github.com/xdebug/xdebug/pull/868

Issue History

Date Modified Username Field Change
2022-11-03 07:35 barel New Issue
2022-11-03 09:41 derick Assigned To => derick
2022-11-03 09:41 derick Status new => resolved
2022-11-03 09:41 derick Resolution open => no change required
2022-11-03 09:41 derick Note Added: 0006435
2022-11-03 09:43 derick Status resolved => acknowledged
2022-11-03 09:43 derick Note Added: 0006436
2022-11-08 18:18 derick Status acknowledged => closed
2022-11-08 18:18 derick Fixed in Version => 3.2dev
2022-11-08 18:18 derick Note Added: 0006443
2022-11-10 09:50 derick Fixed in Version 3.2dev => 3.2.0RC2
2022-12-08 18:51 derick Fixed in Version 3.2.0RC2 => 3.2.0