xdebug / vscode-php-debug

PHP Debug Adapter for Visual Studio Code 🐞⛔
MIT License
771 stars 176 forks source link

Breakpoints work but not on autoloaded classes #488

Closed C-Collamar closed 3 years ago

C-Collamar commented 3 years ago

PHP version: 7.4.14 XDebug version: 3.0.2 Adapter version: 1.14.5

My launch.json:


{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "log": true,
            "pathMappings": {
                "/app": "${workspaceFolder}/app"
            }
        }
    ]
}

XDebug php.ini config:


zend_extension = "C:/Users/ccoll/AppData/Roaming/php-7.4.14-Win32-vc15-x64/ext/php_xdebug-3.0.2-7.4-vc15-x86_64.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.discover_client_host = true
xdebug.log = "C:/Users/ccoll/Desktop/xdebug.log"

XDebug logfile (from setting xdebug.remote_log in php.ini):

[7076] Log opened at 2117-03-21 02:20:02.157637
[7076] [Step Debug] INFO: Checking remote connect back address.
[7076] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[7076] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[7076] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 127.0.0.1:9003.
[7076] [Step Debug] INFO: Connected to debugging client: 127.0.0.1:9003 (from REMOTE_ADDR HTTP header). :-)
[7076] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///C:/Users/ccoll/Documents/repositories/some-repo/public/index.php" language="PHP" xdebug:language_version="7.4.14RC1" protocol_version="1.0" appid="7076"><engine version="3.0.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2021 by Derick Rethans]]></copyright></init>

[7076] [Step Debug] <- breakpoint_list -i 1
[7076] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>

[7076] [Step Debug] <- breakpoint_set -i 2 -t line -f file:///app/Http/Controllers/Some/Controller.php -n 34
[7076] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="70760038"></response>

[7076] [Step Debug] <- breakpoint_list -i 3
[7076] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="3"><breakpoint type="line" filename="file:///app/Http/Controllers/Some/Controller.php" lineno="34" state="enabled" hit_count="0" hit_value="0" id="70760038"></breakpoint></response>

[7076] [Step Debug] <- breakpoint_list -i 4
[7076] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="4"><breakpoint type="line" filename="file:///app/Http/Controllers/Some/Controller.php" lineno="34" state="enabled" hit_count="0" hit_value="0" id="70760038"></breakpoint></response>

[7076] [Step Debug] <- run -i 5
[7076] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="5" status="stopping" reason="ok"></response>

[7076] [Step Debug] <- stop -i 6
[7076] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="6" status="stopped" reason="ok"></response>

[7076] Log closed at 2117-03-21 02:20:02.157637

Adapter logfile (from setting "log": true in launch.json):

<- launchResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 2,
  command: 'launch',
  success: true
}

new connection 1
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'started', threadId: 1 }
}

<- initializedEvent
InitializedEvent { seq: 0, type: 'event', event: 'initialized' }

-> setBreakpointsRequest
{
  command: 'setBreakpoints',
  arguments: {
    source: {
      name: 'PaymentController.php',
      path: 'c:\\Users\\ccoll\\Documents\\repositories\\some-repo\\app\\Http\\Controllers\\Some\\Controller.php'
    },
    lines: [ 34 ],
    breakpoints: [ { line: 34 } ],
    sourceModified: false
  },
  type: 'request',
  seq: 3
}

<- setBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 3,
  command: 'setBreakpoints',
  success: true,
  body: { breakpoints: [ { verified: true, line: 34 } ] }
}

-> setFunctionBreakpointsRequest
{
  command: 'setFunctionBreakpoints',
  arguments: { breakpoints: [] },
  type: 'request',
  seq: 4
}

Code snippet to reproduce:

I have setup xdebug multiple times before and got them working without problems, but that was for version 2. Here's a sample snippet for testing, in the context of a simple Laravel application.


Illuminate\Support\Facades\Route::get('/foo', function() {
    $a = 'foo';
    return $a; // 👈 a breakpoint set here works (execution is paused for step-debugging)
});

Route::get('/bar', [ App\Http\Controllers\Some\Controller::class, 'handle' ]); // 👈 any breakpoints set inside the Controller::handle method don't pause the execution
zobo commented 3 years ago

Hello @C-Collamar, thanks for the report.

There are a few strange things here. From Xdebug log: Script starts in file:///C:/Users/ccoll/Documents/repositories/some-repo/public/index.php But then the breakpoint is set to file:///app/Http/Controllers/Some/Controller.php

On the other hand, vscode tells de adapter to set BP at c:\\Users\\ccoll\\Documents\\repositories\\some-repo\\app\\Http\\Controllers\\Some\\Controller.php

I'm guessing you have some path mapping set up in launch.json?

Another way to debug this is that in the place where you wanted to place a breakpoint you add the php function call xdebug_break(); Xdebug will do a breakpoint there, and you can see if vscode reacts correctly.

If it does not, can you please generate the report again (both log files) and also add the breakpoint that does work.

Best, Damjan

C-Collamar commented 3 years ago

Thanks for looking to this @zobo!

The contents of my launch.json is basically the same as above (without VS Code's auto-generated comments). As stated in my launch.json, my only path mapping is to map the path "/app" to "${workspaceFolder}/app".

I tried xdebug_break() and it works. It pauses the execution for step-debugging in VS Code, but it pauses on the next line, not on the line where xdebug_break() is invoked. Is that intentional? Because of it, unless I click Step Over twice, the step-debugger looks like it's not moving. To demonstrate, see the screen recording 1.mp4.

https://user-images.githubusercontent.com/19512843/106678384-9409df80-65f5-11eb-8bd8-05617c814953.mp4

In case you might still need it, here are the xdebug and adapter logs I regenerated by doing the following in 2.mp4. In this demonstration, I was expecting that when I continue the execution, it would eventually pause in line 13, but it didn't, and just continued on.

https://user-images.githubusercontent.com/19512843/106679888-7a1dcc00-65f8-11eb-8ecb-07ad8a35a952.mp4

xdebug.log adapter.log

I hope this helps.

zobo commented 3 years ago

Hi. I had a quick look. First, I tried xdebug_break() realy does "break" on the next line. So the stopped execution on line 12 is OK. Even the "step after xdebug_break()" is the same here. Perhaps is an issue for Xdebug. So that's OK too.

The breakpoint issue is still the same:

breakpoint_set -i 2 -t line -f file:///app/Http/Controllers/Some/Controller.php -n 13

<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:///C:/Users/ccoll/Documents/repositories/beatrix-laravel7-restapi/app/Http/Controllers/Some/Controller.php" lineno="12"></xdebug:message></response>

Please remove this part from you launch.json

            "pathMappings": {
                "/app": "${workspaceFolder}/app"
            }

Best, Damjan

C-Collamar commented 3 years ago

Oh right! Silly me. Thank you so much @zobo, it's working now.