Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add toggle arg to xdebug command, fixes #3593 #5625

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions cmd/ddev/cmd/xdebug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ func TestCmdXdebug(t *testing.T) {
assert.NoError(err)
assert.Contains(string(out), "xdebug disabled")

out, err = exec.RunHostCommand(DdevBin, "xdebug", "toggle")
assert.NoError(err)
assert.Contains(string(out), "Enabled xdebug")

out, err = exec.RunHostCommand(DdevBin, "xdebug", "status")
assert.NoError(err)
assert.Contains(string(out), "xdebug enabled")

out, err = exec.RunHostCommand(DdevBin, "xdebug", "toggle")
assert.NoError(err)
assert.Contains(string(out), "Disabled xdebug")

out, err = exec.RunHostCommand(DdevBin, "xdebug", "status")
assert.NoError(err)
assert.Contains(string(out), "xdebug disabled")

_, err = exec.RunHostCommand(DdevBin, "stop")
assert.NoError(err, "Failed ddev stop with php=%v: %v", phpVersion, err)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/content/users/configuration/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ Whether Xdebug should be enabled for [step debugging](../debugging-profiling/ste

| Type | Default | Usage
| -- | -- | --
| :octicons-file-directory-16: project | `false` | Please leave this `false` in most cases. Most people use [`ddev xdebug`](../usage/commands.md#xdebug) and `ddev xdebug off` commands.
| :octicons-file-directory-16: project | `false` | Please leave this `false` in most cases. Most people use [`ddev xdebug`](../usage/commands.md#xdebug) and `ddev xdebug off` (or `ddev xdebug toggle`) commands.

## `xdebug_ide_location`

Expand Down
2 changes: 2 additions & 0 deletions docs/content/users/debugging-profiling/step-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All IDEs basically work the same, listening on a port and reacting when they’r
* Enable Xdebug by running [`ddev xdebug`](../usage/commands.md#xdebug) or `ddev xdebug on` from your project directory.
It will remain enabled until you start or restart the project.
* Disable Xdebug for better performance when not debugging with `ddev xdebug off`.
* Toggle Xdebug on and off easily with `ddev xdebug toggle`.
* `ddev xdebug status` will show Xdebug’s current status.
* You may need to open port 9003 in your firewall to allow Xdebug access. (See [Troubleshooting Xdebug](#troubleshooting-xdebug) below.)
* The IDE’s debug server port must be set to Xdebug’s default 9003, which is already the case in popular IDEs. If the unusual case that you have a port conflict, see [Using Xdebug on a Port Other than the Default 9003](#using-xdebug-on-a-port-other-than-the-default-9003) below.
Expand Down Expand Up @@ -122,6 +123,7 @@ Here are basic steps to take to sort out any difficulty:
* Temporarily disable any *firewall* or *VPN* if you’re having trouble. Xdebug is a network protocol, and the PHP process inside the web container must be able to establish a TCP connection to the listening IDE (PhpStorm, for example).
* Confirm that DDEV’s [`xdebug_ide_location`](../configuration/config.md#xdebugidelocation) config setting is set properly, which in most cases should be set to an empty string. Check both your project's `.ddev/config.yaml` and DDEV’s global `~/.ddev/global_config.yaml`.
* Use `ddev xdebug on` to enable Xdebug when you want it, and `ddev xdebug off` when you’re done with it.
* You can also use `ddev xdebug toggle` to easily toggle Xdebug on and off.
* Set a breakpoint at the first executable line of your `index.php`.
* Tell your IDE to start listening. (PhpStorm: click the telephone button, VS Code: run the debugger.)
* Use `curl` or a browser to create a web request. For example, `curl https://d10.ddev.site` or run `ddev exec curl localhost`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Although DDEV has more sophisticated profiling capabilities with [xhprof](xhprof
* Make an HTTP request to the DDEV project and the profile will be located in `.ddev/xdebug` directory.
* Analyze it with any call graph viewer, for example [kcachegrind](https://kcachegrind.github.io/html/Home.html).
* When you’re done, execute `ddev xdebug off` to avoid generating unneeded profile files.
* You can also toggle Xdebug on and off using `ddev xdebug toggle`.

## Information Links

Expand Down
2 changes: 1 addition & 1 deletion docs/content/users/usage/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Type `ddev` or `ddev -h` in a terminal window to see the available DDEV [command
* [`ddev composer`](../usage/commands.md#composer) runs Composer inside the container. For example, `ddev composer install` will do a full composer install for you without even needing Composer on your computer. See [developer tools](developer-tools.md#ddev-and-composer).
* [`ddev snapshot`](../usage/commands.md#snapshot) makes a very fast snapshot of your database that can be easily and quickly restored with [`ddev snapshot restore`](../usage/commands.md#snapshot-restore).
* [`ddev share`](../usage/commands.md#share) requires ngrok and at least a free account on [ngrok.com](https://ngrok.com) so you can let someone in the next office or on the other side of the planet see your project and what you’re working on. `ddev share -h` gives more info about how to set up ngrok.
* [`ddev xdebug`](../usage/commands.md#xdebug) enables Xdebug, `ddev xdebug off` disables it, and `ddev xdebug status` shows status.
* [`ddev xdebug`](../usage/commands.md#xdebug) enables Xdebug, `ddev xdebug off` disables it, and `ddev xdebug status` shows status. You can toggle Xdebug on and off easily using `ddev xdebug toggle`.
* [`ddev xhprof`](../usage/commands.md#xhprof) enables xhprof, `ddev xhprof off` disables it, and `ddev xhprof status` shows status.
* `ddev drush` (Drupal and Backdrop only) gives direct access to the `drush` CLI.
* `ddev artisan` (Laravel only) gives direct access to the Laravel `artisan` CLI.
Expand Down
3 changes: 3 additions & 0 deletions docs/content/users/usage/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,9 @@ ddev xdebug on

# Turn Xdebug off
ddev xdebug off

# Toggle Xdebug on and off
ddev xdebug toggle
```

## `xhprof`
Expand Down
27 changes: 25 additions & 2 deletions pkg/ddevapp/global_dotddev_assets/commands/web/xdebug
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file already has a mix of tabs and spaces for indentation so I'm really not sure what the indentation should be - and there's no guidance on that (at least that I could find) in https://ddev.readthedocs.io/en/stable/developers/building-contributing/#coding-style

Let me know if you want something specific to be done with the indents in this file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use spaces. You can add [skip ci] to the commit message to avoid running all the tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to make a commit here (will do a release soon, and want to merge it right now).

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## #ddev-generated
## Description: Enable or disable xdebug
## Usage: xdebug on|off|enable|disable|true|false|status
## Example: "ddev xdebug" (default is "on"), "ddev xdebug off", "ddev xdebug on", "ddev xdebug status"
## Usage: xdebug on|off|enable|disable|true|false|toggle|status
## Example: "ddev xdebug" (default is "on"), "ddev xdebug off", "ddev xdebug on", "ddev xdebug toggle", "ddev xdebug status"
## Execraw: false
## Flags: []

Expand All @@ -21,6 +21,29 @@ case $1 in
off|false|disable)
disable_xdebug
;;
toggle)
case ${xdebug_version} in
v3*)
status=$(php -r 'echo ini_get("xdebug.mode");' 2>/dev/null)
if [[ "${status}" =~ .*"debug".* ]]; then
disable_xdebug
else
enable_xdebug
fi
;;
v2*)
status=$(php -r 'echo ini_get("xdebug.remote_enable");')
if [ "${status}" = "1" ]; then
disable_xdebug
else
enable_xdebug
fi
;;
*)
enable_xdebug
;;
esac
;;
status)
case ${xdebug_version} in
v3*)
Expand Down