You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `--host` option specifies the interface on which the debug server is listening for connections. To be able to attach from another machine, make sure that the server is listening on a public interface - using `0.0.0.0` will make it listen on all available interfaces:
28
+
The hostname passed to `--listen`specifies the interface on which the debug adapter will be listening for connections from DAP clients. It can be omitted, with only the port number specified:
29
29
```console
30
-
-m debugpy --host 0.0.0.0 --port 5678 myfile.py
30
+
-m debugpy --listen 5678 ...
31
+
```
32
+
in which case the default interface is 127.0.0.1.
33
+
34
+
To be able to attach from another machine, make sure that the adapter is listening on a public interface - using `0.0.0.0` will make it listen on all available interfaces:
35
+
```console
36
+
-m debugpy --listen 0.0.0.0:5678 myfile.py
31
37
```
32
38
This should only be done on secure networks, since anyone who can connect to the specified port can then execute arbitrary code within the debugged process.
33
39
@@ -36,100 +42,64 @@ To pass arguments to the script, just specify them after the filename. This work
36
42
### Debugging a module
37
43
To run a module, use the `-m` switch instead of filename:
Same as with scripts, command line arguments can be passed to the module by specifying them after the module name. All other debugpy switches work identically in this mode; in particular, `--wait` can be used to block execution until the IDE attaches.
47
+
Same as with scripts, command line arguments can be passed to the module by specifying them after the module name. All other debugpy switches work identically in this mode; in particular, `--wait-for-client` can be used to block execution until the client attaches.
42
48
43
49
### Attaching to a running process by ID
44
50
The following command injects the debugger into a process with a given PID that is running Python code. Once the command returns, a debugpy server is running within the process, as if that process was launched via `-m debugpy` itself.
At the beginning of your script, import debugpy, and call `debugpy.enable_attach()` to start the debug server. The default hostname is `0.0.0.0`, and the default port is 5678; these can be overridden by passing a `(host, port)` tuple as the first argument of `enable_attach()`.
57
+
At the beginning of your script, import debugpy, and call `debugpy.listen()` to start the debug adapter, passing a `(host, port)` tuple as the first argument.
52
58
```python
53
59
import debugpy
54
-
debugpy.enable_attach()
60
+
debugpy.listen(("localhost", 5678))
61
+
...
62
+
```
63
+
As with the `--listen` command line switch, hostname can be omitted, and defaults to `"127.0.0.1"`:
64
+
```python
65
+
debugpy.listen(5678)
55
66
...
56
67
```
57
68
58
-
### Waiting for the IDE to attach
59
-
Use the `debugpy.wait_for_attach()` function to block program execution until the IDE is attached.
69
+
### Waiting for the client to attach
70
+
Use the `debugpy.wait_for_client()` function to block program execution until the client is attached.
60
71
```python
61
72
import debugpy
62
-
debugpy.enable_attach()
63
-
debugpy.wait_for_attach() # blocks execution until IDE is attached
73
+
debugpy.listen(5678)
74
+
debugpy.wait_for_client() # blocks execution until client is attached
64
75
...
65
76
```
66
77
67
78
### `breakpoint()` function
68
-
In Python 3.7 and above, `debugpy` supports the standard `breakpoint()` function. Use `debugpy.break_into_debugger()` function for similar behavior and compatibility with older versions of Python (3.6 and below). If the debugger is attached when either of these functions is invoked, it will pause execution on the calling line, as if it had a breakpoint set. If there's no IDE attached, the functions do nothing, and the code continues to execute normally.
79
+
In Python 3.7 and above, `debugpy` supports the standard `breakpoint()` function. Use `debugpy.breakpoint()` function for similar behavior and compatibility with older versions of Python. If the debugger is attached when either of these functions is invoked, it will pause execution on the calling line, as if it had a breakpoint set. If there's no client attached, the functions do nothing, and the code continues to execute normally.
69
80
```python
70
81
import debugpy
71
-
debugpy.enable_attach()
82
+
debugpy.listen(...)
72
83
73
84
whileTrue:
74
85
...
75
-
breakpoint() # or debugpy.break_into_debugger() on <3.7
86
+
breakpoint() # or debugpy.breakpoint() on 3.6 and below
76
87
...
77
88
```
78
89
79
-
## Custom Protocol arguments
80
-
### Launch request arguments
81
-
```json5
82
-
{
83
-
"debugOptions": [
84
-
"RedirectOutput", // Whether to redirect stdout and stderr (see pydevd_comm.CMD_REDIRECT_OUTPUT)
85
-
"WaitOnNormalExit", // Wait for user input after user code exits normally
86
-
"WaitOnAbnormalExit", // Wait for user input after user code exits with error
"FixFilePathCase", // See FIX_FILE_PATH_CASE in wrapper.py
105
-
"DebugStdLib", // Whether to enable debugging of standard library functions
106
-
"WindowsClient", // Whether client OS is Windows
107
-
"UnixClient", // Whether client OS is Unix
108
-
"ShowReturnValue", // Show return values of functions
109
-
],
110
-
"pathMappings": [
111
-
{
112
-
"localRoot":"C:\\Project\\src", // Local root (where the IDE is running)
113
-
"remoteRoot":"/home/smith/proj"// Remote root (where remote code is running)
114
-
},
115
-
// Add more path mappings
116
-
]
117
-
}
118
-
```
119
-
120
90
## Debugger logging
121
91
122
-
To enable debugger internal logging via CLI, the `--log-dir` switch can be used:
92
+
To enable debugger internal logging via CLI, the `--log-to` switch can be used:
123
93
```console
124
-
-m debugpy --log-dir path/to/logs ...
94
+
-m debugpy --log-to path/to/logs ...
125
95
```
126
96
127
-
When using `enable_attach`, the same can be done with `log_dir` argument:
97
+
When using the API, the same can be done with `debugpy.log_to()`:
128
98
```py
129
-
debugpy.enable_attach(log_dir='path/to/logs')
99
+
debugpy.log_to('path/to/logs')
100
+
debugpy.listen(...)
130
101
```
131
102
132
103
In both cases, the environment variable `DEBUGPY_LOG_DIR` can also be set to the same effect.
133
104
134
105
When logging is enabled, debugpy will create several log files with names matching `debugpy*.log` in the specified directory, corresponding to different components of the debugger. When subprocess debugging is enabled, separate logs are created for every subprocess.
0 commit comments