Fixed issue #1016: Support for pause-execution - #477
Conversation
derickr
left a comment
There was a problem hiding this comment.
I've left a whole bunch of comments, they mostly come down to:
- use constants, and refactor into helper functions
- add explanations why you've made specific changes (as comments on the PR)
- watch your spaces
In addition, please name the PR (and commits) according to precedence:
1a2b402
bd9061f to
5db727b
Compare
Thanks for your patience. I fixed those problems. Please review it. |
7df226d to
f654587
Compare
|
It's going to take me some time to get to this, as I'll be away from the "office" over the next few weeks. I am intending to get this patch into v3.0, but as it's quite a big and scary change, it's unlikely I will want to put this in the upcoming PHP 7.4 compat release (v2.8). In any case, right now there is a merge conflict, so if you could rebase (on master) and resolve that, that'd be great. |
1ec3f10 to
47db039
Compare
7317300 to
01718da
Compare
|
@derickr Pause-execution is really necessary for investigating what's happening for user's program. And this feature-request have existed for almost six years(2013-2019). It's time to get it done. And if you have any question about this pr, feel free to comment. |
01718da to
38d4ed2
Compare
38d4ed2 to
35c2a44
Compare
e97b91b to
932b56c
Compare
0e9e65b to
2032214
Compare
|
@derickr This PR is ready to merge, could you please to review this? |
@derickr And, I forked vscode-php-debug to support this feature: robberphex/vscode-php-debug@3b611f2 (https://marketplace.visualstudio.com/items?itemName=robberphex.php-debug) I think this PR is work well. |
ea067e2 to
dace0ad
Compare
|
I'm going to have to spend some proper time understanding this new code, as with a PR you're not only asking me to merge it, but also maintain the new code. I don't know or use vscode, nor would I know how to build it. I think I would like that we walk through your changes in an audio/video call at some point (in the new year). For now, would you please refrain from rebasing and force-pushing this (unless there is a merge conflict), as it takes CI on AppVeyor about 3 hours to build...which stops me from merging other PRs. cheers, |
| } | ||
| } | ||
|
|
||
| if(xdebug_is_debug_connection_active_for_current_pid()) { |
There was a problem hiding this comment.
Add a space between if and ( please.
| } | ||
|
|
||
| static int xdebug_dbgp_cmdloop(xdebug_con *context, int bail) | ||
| int xdebug_dbgp_cmdloop(xdebug_con *context, int block, int bail TSRMLS_DC) |
There was a problem hiding this comment.
TSRMLS_DC/TSRMLS_CC and friends no longer mean anything in PHP 7, so please don't re-add them.
| } | ||
|
|
||
| static void send_message_ex(xdebug_con *context, xdebug_xml_node *message, int stage) | ||
| static int xdebug_is_paused(int status) { |
There was a problem hiding this comment.
I would probably rename this function to is_debugger_paused. There is no need to prefix with xdebug_ for static functions, and just is_paused doesn't really mean anything without the context of the debugger.
Please also add a new line before { please.
| #define REASON_EXCEPTION 3 | ||
|
|
||
| #define XDEBUG_CMDLOOP_BLOCK 1 | ||
| #define XDEBUG_CMDLOOP_NONBLOCK 0 |
There was a problem hiding this comment.
Can you swap them so they count up like all the others? :-)
| $debugClient->sendCommand($conn, 'run', 1); | ||
|
|
||
| $debugClient->sendCommand($conn, 'status', 2); | ||
| $debugClient->doRead($conn, (string)2); |
There was a problem hiding this comment.
Why the (string) cast here instead of just using "2"?
| xdebug_xml_node_dtor(response); | ||
|
|
||
| xdebug_dbgp_cmdloop(context, 0); | ||
| xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_BLOCK, 0 TSRMLS_CC); |
There was a problem hiding this comment.
The TSRMC_CC should go here, and I think it would also make sense to add a constant for the 0/1 here (for example XDEBUG_CMDLOOP_BAIL for the invocation on line 2717)
|
|
||
| ret = -1; | ||
| } | ||
| ret = command->handler((xdebug_xml_node**) &retval, context, args TSRMLS_CC); |
There was a problem hiding this comment.
I don't quite understand why you can get away with removing all this code :-) Especially the checks for POST_MORTEM and the command->flags should be checked.
Could this then be the (only) place where it needs checking for "is paused" and whether this command can support a "paused" state as I described near context_get
Also: no TSRMLS_CC, please.
|
|
||
| if (!xdebug_is_paused(XG_DBG(status))) { | ||
| RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_COMMAND_UNAVAILABLE); | ||
| } |
There was a problem hiding this comment.
Is there a reason why this command can't be run when the debugger is not paused? I also see this being done for most (if not all) commands, so would it instead not be nicer to add whether a command can be run when not paused into the structure list at https://github.com/xdebug/xdebug/pull/477/files#diff-ec26437df5ade1abeb51e1c4cd21aa2bR219, and then make this check once before the command handler gets called (at https://github.com/xdebug/xdebug/pull/477/files#diff-ec26437df5ade1abeb51e1c4cd21aa2bR2354 )?
| } | ||
|
|
||
| xdebug_debugger_error_cb(error_filename, error_lineno, type, error_type_str, buffer); | ||
| xdebug_debugger_error_cb(error_filename, error_lineno, type, error_type_str, buffer, block); |
There was a problem hiding this comment.
As block here can't really have a different value than XDEBUG_CMDLOOP_NONBLOCK, I think I would prefer there not to be a variable for it.
| if (!CMD_OPTION_SET('f')) { | ||
| if ((fse = xdebug_get_stack_tail())) { | ||
| if (!xdebug_is_paused(XG_DBG(status))) { | ||
| RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_COMMAND_UNAVAILABLE); |
There was a problem hiding this comment.
You mention in your document
"And, we cannot execute … source command without file option."
Why is this exactly?
862d70e to
ff014fd
Compare
derickr
left a comment
There was a problem hiding this comment.
A few more questions - sorry :-)
| if (xdebug_is_debug_connection_active_for_current_pid() && XG_DBG(breakpoints_allowed)) { | ||
| if (!handle_breakpoints(fse, breakpoint_type)) { | ||
| xdebug_mark_debug_connection_not_active(); | ||
| int block = XDEBUG_CMDLOOP_NONBLOCK; |
There was a problem hiding this comment.
block here is still defined as a variable, but only used with this value in line 461. No need for this extra variable.
| DBGP_FUNC_ENTRY(breakpoint_update, XDEBUG_DBGP_NONE) | ||
| DBGP_FUNC_ENTRY(break) | ||
| DBGP_FUNC_ENTRY(breakpoint_get) | ||
| DBGP_FUNC_ENTRY(breakpoint_list) |
There was a problem hiding this comment.
I see that you removed thee NONE/POST_MORTEM flag. Where is this now checked?
| } else { | ||
| error = xdebug_xml_node_init("error"); | ||
| xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", XDEBUG_ERROR_COMMAND_UNAVAILABLE), 0, 1); | ||
| ADD_REASON_MESSAGE(XDEBUG_ERROR_COMMAND_UNAVAILABLE); |
There was a problem hiding this comment.
The whole check for availability seems gone now. Some of this (such as the lastcmd stuft) is now done in every handler, but why do it there when it can be done once here? I am probably misunderstanding so I am hoping you can explain this to me when we chat about it.
|
|
||
|
|
||
| static char* xdebug_fd_read_line_delim(int socketfd, fd_buf *context, int type, unsigned char delim, int *length) | ||
| int xdebug_fd_read_line_delim(int socketfd, fd_buf *context, int type, int block, unsigned char delim, char **cmd, int *length) |
There was a problem hiding this comment.
You're introducing the block argument here, but I can't see it being used in the function.
ff014fd to
3e80c6d
Compare
derickr
left a comment
There was a problem hiding this comment.
I've checked what the protocol says about which commands you can run in the "running" state, it says in the 5th paragraph for 6.2:
If the debugger engine supports asynchronous commands, the IDE may also send commands while the debugger engine is in a 'run' state. These commands should be limited to commands such as the 'break' or 'status' commands for performance reasons, but this protocol does not impose such limitations.
Although other commands are allowed, I think we should stick to just allowing break and status.
3e80c6d to
f881fac
Compare
f881fac to
f38a21d
Compare
|
@derickr Hi, I've fixed tests. Could you pleas review this again? Thanks a lot. |
|
Since this is merged, so close this PR. |
Fix https://bugs.xdebug.org/view.php?id=1016.