xdebug / vscode-php-debug

PHP Debug Adapter for Visual Studio Code 🐞⛔
MIT License
768 stars 175 forks source link

XDEBUG on WSL2 and Docker doesn't found correct breakpoint file #900

Closed sharak closed 1 year ago

sharak commented 1 year ago

PHP version: 8.2.5-fpm (inside docker) Xdebug version: 3.2.0 VS Code extension version: v1.32.1

Your launch.json:

{
    "name": "Listen for Xdebug",
     "type": "php",
     "request": "launch",
     "hostname": "0.0.0.0",
     "port": 9003,
     "log": true,
     "pathMappings": {
         "/app": "{$workspaceFolder}"
     }
}

Xdebug php.ini config:

[xdebug]
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
Xdebug logfile (from setting `xdebug.log` in php.ini) ``` [7] Log opened at 2023-05-02 12:15:56.636296 [7] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003. [7] [Step Debug] INFO: Connected to debugging client: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port). [7] [Step Debug] -> [7] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1 [7] [Step Debug] -> [7] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1 [7] [Step Debug] -> [7] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1 [7] [Step Debug] -> [7] [Step Debug] <- feature_set -i 4 -n breakpoint_include_return_value -v 1 [7] [Step Debug] -> [7] [Step Debug] <- feature_set -i 5 -n max_children -v 100 [7] [Step Debug] -> [7] [Step Debug] <- breakpoint_set -i 6 -t line -f file:///home/projects/sesame-service/public/index.php -n 6 [7] [Step Debug] WARN: Breakpoint file name does not exist: /home/projects/sesame-service/public/index.php (No such file or directory). [7] [Step Debug] -> [7] [Step Debug] <- run -i 7 [7] [Step Debug] -> [7] [Step Debug] <- stack_get -i 8 [7] [Step Debug] -> [7] [Step Debug] <- context_names -i 9 -d 0 [7] [Step Debug] -> [7] [Step Debug] <- context_get -i 10 -d 0 -c 0 [7] [Step Debug] -> [7] [Step Debug] <- run -i 11 [7] [Step Debug] -> [7] [Step Debug] <- stop -i 12 [7] [Step Debug] -> [7] Log closed at 2023-05-02 12:16:13.501425 ```
VS Code extension logfile (from setting `"log": true` in launch.json) ``` Listening on { address: '0.0.0.0', family: 'IPv4', port: 9003 } <- launchResponse Response { seq: 0, type: 'response', request_seq: 2, command: 'launch', success: true } <- initializedEvent InitializedEvent { seq: 0, type: 'event', event: 'initialized' } -> setBreakpointsRequest { command: 'setBreakpoints', arguments: { source: { name: 'index.php', path: '/home/projects/sesame-service/public/index.php' }, lines: [ 6 ], breakpoints: [ { line: 6 } ], sourceModified: false }, type: 'request', seq: 3 } <- setBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 3, command: 'setBreakpoints', success: true, body: { breakpoints: [ { verified: true, line: 6, source: { name: 'index.php', path: '/home/projects/sesame-service/public/index.php' }, id: 1 } ] } } -> setFunctionBreakpointsRequest { command: 'setFunctionBreakpoints', arguments: { breakpoints: [] }, type: 'request', seq: 4 } <- setFunctionBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 4, command: 'setFunctionBreakpoints', success: true, body: { breakpoints: [] } } -> setExceptionBreakpointsRequest { command: 'setExceptionBreakpoints', arguments: { filters: [] }, type: 'request', seq: 5 } <- setExceptionBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 5, command: 'setExceptionBreakpoints', success: true, body: { breakpoints: [] } } -> configurationDoneRequest { command: 'configurationDone', type: 'request', seq: 6 } <- configurationDoneResponse Response { seq: 0, type: 'response', request_seq: 6, command: 'configurationDone', success: true } -> threadsRequest { command: 'threads', type: 'request', seq: 7 } <- threadsResponse Response { seq: 0, type: 'response', request_seq: 7, command: 'threads', success: true, body: { threads: [] } } new connection 1 from 127.0.0.1 xd(1) -> xd(1) <- feature_set -i 1 -n resolved_breakpoints -v 1 xd(1) -> xd(1) <- feature_set -i 2 -n notify_ok -v 1 xd(1) -> xd(1) <- feature_set -i 3 -n extended_properties -v 1 xd(1) -> xd(1) <- feature_set -i 4 -n breakpoint_include_return_value -v 1 xd(1) -> xd(1) <- feature_set -i 5 -n max_children -v 100 xd(1) -> <- threadEvent ThreadEvent { seq: 0, type: 'event', event: 'thread', body: { reason: 'started', threadId: 1 } } xd(1) <- breakpoint_set -i 6 -t line -f file:///home/projects/sesame-service/public/index.php -n 6 xd(1) -> <- breakpointEvent BreakpointEvent { seq: 0, type: 'event', event: 'breakpoint', body: { reason: 'changed', breakpoint: { id: 1, verified: false } } } xd(1) <- run -i 7 xd(1) -> <- stoppedEvent StoppedEvent { seq: 0, type: 'event', event: 'stopped', body: { reason: 'breakpoint', threadId: 1, allThreadsStopped: false } } -> threadsRequest { command: 'threads', type: 'request', seq: 8 } <- threadsResponse Response { seq: 0, type: 'response', request_seq: 8, command: 'threads', success: true, body: { threads: [ Thread { id: 1, name: 'Request 1 (2:11:55 PM)' } ] } } -> stackTraceRequest { command: 'stackTrace', arguments: { threadId: 1, startFrame: 0, levels: 20 }, type: 'request', seq: 9 } xd(1) <- stack_get -i 8 -> threadsRequest { command: 'threads', type: 'request', seq: 10 } <- threadsResponse Response { seq: 0, type: 'response', request_seq: 10, command: 'threads', success: true, body: { threads: [ Thread { id: 1, name: 'Request 1 (2:11:55 PM)' } ] } } xd(1) -> <- stackTraceResponse Response { seq: 0, type: 'response', request_seq: 9, command: 'stackTrace', success: true, body: { totalFrames: 1, stackFrames: [ { id: 1, name: '{main}', source: { name: 'index.php', path: '/mnt/c/Users/Usuario/AppData/Local/Programs/Microsoft VS Code/{$workspaceFolder}/public/index.php' }, line: 6, column: 1 } ] } } -> stackTraceRequest { command: 'stackTrace', arguments: { threadId: 1, startFrame: 0, levels: 20 }, type: 'request', seq: 11 } xd(1) <- stack_get -i 9 xd(1) -> <- stackTraceResponse Response { seq: 0, type: 'response', request_seq: 11, command: 'stackTrace', success: true, body: { totalFrames: 1, stackFrames: [ { id: 2, name: '{main}', source: { name: 'index.php', path: '/mnt/c/Users/Usuario/AppData/Local/Programs/Microsoft VS Code/{$workspaceFolder}/public/index.php' }, line: 6, column: 1 } ] } } -> scopesRequest { command: 'scopes', arguments: { frameId: 1 }, type: 'request', seq: 12 } xd(1) <- context_names -i 10 -d 0 xd(1) -> <- scopesResponse Response { seq: 0, type: 'response', request_seq: 12, command: 'scopes', success: true, body: { scopes: [ Scope { name: 'Locals', variablesReference: 1, expensive: false }, Scope { name: 'Superglobals', variablesReference: 2, expensive: false }, Scope { name: 'User defined constants', variablesReference: 3, expensive: false } ] } } -> variablesRequest { command: 'variables', arguments: { variablesReference: 1 }, type: 'request', seq: 13 } xd(1) <- context_get -i 11 -d 0 -c 0 xd(1) -> <- variablesResponse Response { seq: 0, type: 'response', request_seq: 13, command: 'variables', success: true, body: { variables: [] } } ```

When we start a debugging session and define a breakpoint the debugger does not stop at the defined breakpoint. xdebug_info displays the following: image

If we set an xdebug_break(), it tries to open a file that does not exist inside the /mnt/c/Users/User/AppData/Local/Programs/Microsoft VS Code/{$workspaceFolder} folder.

If we remove the hostname line from the launch.json file the debugger says that it cannot connect to host.docker.internal:9003.

The application is accessed through an nginx proxy that resolves to the php container in docker.

zobo commented 1 year ago

In your pathMappings you have a typo. Instead of {$workspaceFolder} try ${workspaceFolder}. You can look at this page for reference: https://code.visualstudio.com/docs/editor/variables-reference

sharak commented 1 year ago

OMG! What a fool! 😅

It works, obviously. A whole morning lost for a typo.

Thank you and sorry for the foolishness 😕

zobo commented 1 year ago

Don't worry. There is a proverb I like to user when this happens to me: Couldn't see the forest for the trees.