Vscode-php-debug: "error evaluating code" errors in debug console

Created on 3 Oct 2017  Â·  12Comments  Â·  Source: xdebug/vscode-php-debug

Note: duplicate of my Stack Exchange question

Hi:
After launching a debug session using "Listen for xdebug", I am able to type only a limited set of PHP commands into the debug console. I was expecting the ability to use any PHP command, as well as define my own functions and classes from the console, like a normal PHP REPL, or like PHP Storm's console implementation.

What works:

$x = 4
//4

$x
//4

$x = new stdClass();
//stdClass

$x = [];
//array(0)

($x) ? yes : no
// yes

(!$x) ? yes : no
// no

preg_replace('/dog/', 'cat', 'The quick brown fox jumps over the lazy dog.')
// "The quick brown fox jumps over the lazy cat."

request()
//Illuminate\Http\Request (Laravel helper methods work)

What doesn't Work:

echo "yes"
//error evaluating code

if ($x == 4) { echo "yes" }
//error evaluating code

for ($i=0; $i < 5; $i++) { }
//error evaluating code

function foo() {}
//error evaluating code

class SimpleClass {}
//error evaluating code

$var_dump($x)
//null

Is this normal? Thanks.

PHP version: 7.1.8
XDebug version: 2.5.5
Adapter version: 1.11.1

Your launch.json:

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "log": false,
            "localSourceRoot": "${workspaceRoot}/public"
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

XDebug php.ini config:

zend_extension=/usr/local/bin/xdebug.so

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

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

<- eval -i 21 -- ZWNobyAieWVzIg==
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="eval" transaction_id="21" status="break" reason="ok"><error code="206"><message><![CDATA[error evaluating code]]></message></error></response>

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

function foo() {}
error evaluating code
-> evaluateRequest
{ command: 'evaluate',
  arguments: { expression: 'function foo() {}', frameId: 66, context: 'repl' },
  type: 'request',
  seq: 21 }
<- evaluateResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 21,
  command: 'evaluate',

Code snippet to reproduce: type the following into debug console after launching a debug session:

function foo() {}

Most helpful comment

Hi,
I had the same problem and I resolved by cancel the watch variables list on VScode.
Apparently, when xdebug start and try to evaluate unreachable variable in the watch list make error.
I hope this is useful.
thanks

All 12 comments

This is not a bug of the adapter. In the logfile you post we sent XDebug echo "yes" in Base64. XDebug returns Error evaluating code. There is nothing the debug adapter does wrong here.
Also, have you tried suffixing your statement with a semicolon? echo "yes" is not valid PHP code, it doesn't work in other REPLs either: https://repl.it/MC3M/0

yes, it's' the same thing when I append a semi-colon. And in the repl link you shared "echo yes;" is valid PHP.

That still doesn't answer the question about the rest of the valid PHP commands. function foo() {} for example.

Is this possible or not?

I can't tell you, this adapter just forwards commands to XDebug. The logs tell me that it did so correctly, so please ask the XDebug community / open an issue at XDebug

Ok, thanks

On Oct 3, 2017 2:36 PM, "Felix Becker" notifications@github.com wrote:

I can't tell you, this adapter just forwards commands to XDebug. The logs
tell me that it did so correctly, so please ask the XDebug community / open
an issue at XDebug

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/felixfbecker/vscode-php-debug/issues/192#issuecomment-333986150,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAcP9Lm4AxqqtTiZ_nsNgNsXCXqmzBrWks5soqj2gaJpZM4PsyFC
.

Hi,
I had the same problem and I resolved by cancel the watch variables list on VScode.
Apparently, when xdebug start and try to evaluate unreachable variable in the watch list make error.
I hope this is useful.
thanks

Came here with my php debugger not working. @sbonifazzi 's hint was the right solution for me (thanks a lot!!).

Is this a problem with the debugger or vscode? A leftover watch variable breaking the debugger is definitely a pretty painful bug.

If you, like me, have come here by googling "vscode debugger throws error evaluating code" or something similar, @sbonifazzi 's hint is what you need.
Dayum! That could have taken days to find! Thanks m8, greatly appreciated!

Hi @worp1900 and @sbonifazzi , I'm lost... How can I cancel the watch variables list on VScode? Is the correct way to, for example, watch the result when I'm sending an echo in the debug console? I mean, something like this

PHP Code:

echo "hello world!";

Debug console:
hello world!

Thank you in advanced

PS: I'm using XAMPP in the same computer where I have installed VSCode.

My php.ini lines for XDebug are:

[XDebug]
; DLL path
zend_extension = C:\xampp\php\ext\php_xdebug-2.9.5-7.3-vc15-x86_64.dll
; Profiler setup
xdebug.profiler_append = 0
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "c:\xampp\tmp"
; Remote Debugger Setup (VSCode)
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.remote_log = "c:\xampp\tmp\xdebug.txt"
xdebug.remote_port = 81
xdebug.remote_cookie_expire_time = 36000
; Trace Setup
xdebug.trace_output_dir = "c:\xampp\tmp"
xdebug.collect_includes = true
xdebug.collect_params = 4

My launch.json code:

{
     // Use IntelliSense para saber los atributos posibles.
     // Mantenga el puntero para ver las descripciones de los existentes atributos.
     // Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
     "version": "0.2.0",
     "configurations": [
          {
               "name": "Listen for XDebug",
               "type": "php",
               "request": "launch",
               "port": 81,
               "externalConsole": true
          },
          {
               "name": "Launch currently open script",
               "type": "php",
               "request": "launch",
               "program": "${file}",
               "cwd": "${fileDirname}",
               "port": 81
          }
     ]
}

"Cancel the watch variables" means to delete the variables from VSCode's "Watch" List in the debug view. See the following screenshot. The red arrow indicates a button where you can delete all watch-expressions with once click.

Screenshot 2020-05-13 at 10 29 59

Seems like this may still be an issue. I don't have any watch variables to clear in my xdebug session within vscode. Yet, echo "yes"; responds with "error evaluating code".

There is definitely something strange here. However, after playing about with it, I've found that I can do the following:

  1. Remove all expressions from the watch.
  2. Run the debugger with a breakpoint.
  3. In the debug console, use get_defined_vars(); to see what variables are available at the pause point.
  4. Run print_r($VARIABLE, true); to output the contents of the variable.

This is how I can copy-paste the contents of arrays/objects from the debugger.

get_defined_vars ( );
array(1)
    options:array(8)

print_r($options, true);
"Array
(
    [option_1] => Array
        (...

Note: I do get an evaluation error with an echo "yes" command.

> echo "yes";
error evaluating code
> ; echo "yes";
null
> echo "yes"
error evaluating code
> echo yes
error evaluating code
> yes
"yes"

I've had an incredibly difficult experience with what I think is the same or a related issue.

Using PHP 7.3.21 on MacOS 10.15.7 (installed via Homebrew) and xdebug 2.9.6

I have no watch expressions at all in VS Code. I'm not even running a debugging session. But in any browser with xdebug installed (Chrome and FF), if I load a page that uses the following echo $this->view->someFunction() ? 'true' : 'false'; the entire page refuses to load (ERR_EMPTY_RESPONSE). If I _do_ setup a debugger and stop at the line before it, the function being called in the ternary returns false or true. But attempting to evaluate that ternary expression in the debugger console results in _'Error evaluating code'_.

If I load that page in Safari, which has no xdebug capabilities, it loads fine. If I run that same code in a php CLI, it runs fine. If I do start a debug session and load the page in FF or Chrome, with all the 5 default checkboxes for breakpoints (Notice, Warning, Error, Exception, Everything), that line is never caught.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PipCodeBoy picture PipCodeBoy  Â·  5Comments

leslieeilsel picture leslieeilsel  Â·  7Comments

bilogic picture bilogic  Â·  7Comments

eghoff1 picture eghoff1  Â·  10Comments

mitchellnemitz picture mitchellnemitz  Â·  11Comments