Commit graph

179 commits

Author SHA1 Message Date
Karthik Nadig
9ece432dff
Attach to pid support (#1701)
* Fix launcher test

* Attach to pid support

* Address comments.

* Minor tweaks
2019-08-19 14:08:23 -07:00
Pavel Minaev
e94980f86c Do not load ptvsd.server (and hence, pydevd) unless the subpackage is loaded explicitly or via a public API entrypoint that requires it.
Move docstrings to top-level package, and update them to reflect the current behavior.

Remove unused code in ptvsd.common.log.

Move sys.path/prefix/site_packages logging into ptvsd.common.log, and log it from adapter and server to the same level of detail as the tests.

Fix injected code snipped for attach-by-PID.

Fix some Unicode issues in adapter and tests.

Refactor Timeline, debug.Session, and start methods.
2019-08-18 11:43:23 -07:00
Karthik Nadig
6eb65d8a7e
Support for noDebug (#1696)
* noDebug mode support

* Ensure we get the debuggee pid on launch

* Fix state change bug

* Tweaking pid retreival

* Use makefile and simplify pid retreival

* Addressing comments

* Run formatter

* Change name common.socket to common.sockets

* Add some timeouts

* Fix linter
2019-08-17 20:23:06 -07:00
Pavel Minaev
99c0a5d82d Fix #1697: Adapter doesn't handle "env" properly in "internalConsole" mode on Python 2.7
Encode environment variables on Python 2.

Fix #1659: Debuggee output breaks adapter with "internalConsole"

Use os.devnull for debuggee stdin, and redirect debuggee stdout to stderr.

Capture output for debuggee stdout and stderr, generate DAP "output" events from it, and suppress the same coming from the debug server.
2019-08-16 22:26:12 -07:00
Pavel Minaev
9f37496b4c Fix parsing "host" and "post" in "attach" request. 2019-08-12 14:48:01 -07:00
Pavel Minaev
c5feeea05b Fix ptvsd.server command line parsing for filenames on Python 2. 2019-08-12 14:44:44 -07:00
Karthik Nadig
0f6a9bb1d6
Update tests to use python debug adapter (#1660)
* Initial fix for launch

* Minor fixes

* Succesful launch tests

* More launch test fixes

* Some bit of cleanup

* Fix linter

* More cleanup

* Attach using import

*  Fix circular importing

* Support attach via command line

* Backchannel and Other test fixes

* Linter fix

* Python path fix in test

* Fix lint after rebase

* Support exitCode in tests

* More fixes after rebase

* Fix expected exit code

* Remove changes to MessageDict __call__

* Remove hold subprocess event
2019-08-12 13:53:24 -07:00
Pavel Minaev
981b1d1559 Fix #1648: Messaging does not allow reverse requests
Separate message parsing and message handling into separate threads.

Remove nested message handling in request handlers via `yield`, since it is incompatible with the new split model, and replace it with NO_RESPONSE and Request.respond() to defer responses until later.

Change Message.cant_handle() and Message.isnt_valid() to respond to the request and return the exception, instead of raising it, to accommodate NO_RESPONSE scenarios where a failure needs to be reported later.

Fix #1678: Do not rely on "processId" being returned by "runInTerminal" request

Extract debuggee PID from the "process" event sent by the debug server.

Fix #1679: "exited" event sometimes reports "exitCode": null

Report it as -1 if it cannot be retrieved from the debuggee process.

Fix #1680: Fatal errors in message loop do not fail fast

os._exit() immediately if a fatal error occurs in message parsing or message handling background threads.
2019-08-11 19:46:54 -07:00
Pavel Minaev
7256e99b52 Use a separate exception type NoMoreMessages to indicate end-of-stream for JSON messaging, to avoid leaking EOFError from disk I/O or from another stream not being properly reported as errors. 2019-08-11 19:46:54 -07:00
Karthik Nadig
b61c05a3e5
Set don't trace patterns from the debug server (#1676) 2019-08-09 15:55:35 -07:00
Karthik Nadig
84cac1499e
Cancel wait for attach if IDE is disconnected (#1657)
* Cancel wait for attach if IDE is disconnected

* Remove cancel wait wrapper

* cleanup
2019-08-05 16:17:58 -07:00
Karthik Nadig
ebf4629ca8
Add --log-dir switch to adapter (#1653)
* Add --log-dir switch to adapter

* Address comments
2019-08-02 19:30:40 -07:00
Karthik Nadig
e093c86fba
#1449, #1498, partially #1448 (#1651)
* Remove wrapper and in-proc support code

* Fixing up multiproc patching

* Address comments

* Import cleanup

* More cleanup

* Remove loopback fast path

* Disable IDE disconnect unpause-ing

* Add missing file to do not trace
2019-08-02 13:08:07 -07:00
Pavel Minaev
0ea50467aa Fix #1488: Handling launch (spawn ptvsd) (#1647)
Fix #1605: Debuggee process lifetime management
Mitigate #1637: log.exception() doesn't capture the full stack

Handle "launch" request, parse and validate the debug configuration, and spawn the debuggee process with debug server.

Track debuggee process and its subprocesses, and kill them as needed.

Refactor Singleton and ThreadSafeSingleton to allow for easier synchronization between IDE and server message handlers without excessive locking.

Fix various corner cases and race conditions in disconnect scenarios.

Make log.exception() log the calling stack, not just the exception stack.

Add JSON property validation to MessageDict.

Add --log-stderr switch to the server to enable full logging to stderr.

Add --cls switch to the adapter to reset terminal before logging anything (for convenience when debugging it).

Add some printf-debugging helpers.
2019-07-31 13:05:06 -07:00
Karthik Nadig
4581c52de7
Add initialize request (#1618) 2019-07-23 13:29:25 -07:00
Pavel Minaev
527a17cdce Fix #1614: Test run times out on Python 2.7 (#1615)
Close the watchdog message channel from the test process side after "stop" command is sent and acknowledged.
2019-07-22 22:21:01 -07:00
Pavel Minaev
061f5e9721 Fix linting issues. 2019-07-22 17:01:53 -07:00
Pavel Minaev
6727665878 Fix #1612: Parse and expose DAP capabilities
Add ptvsd.adapter.contract module as a single access point for capabilities and other immutable IDE and server metadata.

Change the semantics of Channels.server() to enable checks for disconnected server.

Fix "disconnect" and "terminate" handling when not connected to debug server.

Do best-effort handling of "ptvsd_systemInfo" if not connected to debug server.
2019-07-22 17:01:53 -07:00
Pavel Minaev
b08e8e2233 Fix Message.is_response() 2019-07-22 17:01:53 -07:00
Pavel Minaev
e87025d664 Provide backwards compatibility with "from ptvsd.__main__ import main". 2019-07-22 17:01:53 -07:00
Pavel Minaev
b2d5414d0e Reformat code. 2019-07-22 17:01:53 -07:00
Pavel Minaev
5c6f3779d3 Add Message.request() helper for synchronous requests that wait for response.
Add Message.is_response() helper.

Add Message.payload helper accessor that redirects to Message.arguments or Message.body as appropriate.
2019-07-22 17:01:53 -07:00
Pavel Minaev
ffbbf64832 Add docstring to ptvsd.adapter.options 2019-07-22 17:01:53 -07:00
Pavel Minaev
7973e5beac Fix sys.path patching when running ptvsd without -m. 2019-07-22 17:01:53 -07:00
Karthik Nadig
6aa8134125
Add launcher script that handles wait-on-* feature (#1609)
* Add launcher script that handles wait-on-* feature

* Address comments

* Improve argument parsing

* Add tests

* Address test comments
2019-07-19 13:51:51 -07:00
Karthik Nadig
d50e63eaa7
Move debugger attached state into pydevd (#1610)
* Move debugger attached state into pydevd

* Fix linter

* Fix tests
2019-07-19 13:50:38 -07:00
Pavel Minaev
045fb03888 Detect and log watchdog errors in the tests process.
Do not indent messages that are arrays in the log, to reduce watchdog log verbosity.
2019-07-18 10:13:02 -07:00
Pavel Minaev
becee1f697 Properly handle partial writes in JsonIOStream. 2019-07-18 10:13:02 -07:00
Pavel Minaev
1da62fa7b2 Fix JsonIOStream.read_json not correctly detecting EOF over pipes. 2019-07-18 10:13:02 -07:00
Pavel Minaev
44ca8fa3fc Fix #1555: Child process watchdog for tests
Implement per-test-runner out-of-process watchdog for processes spawned by tests.

Add file logging for tests and watchdog.

Improve stdio capture in debug.Session when test fails.

Remove redundant logging in debug.Session.
2019-07-18 10:13:02 -07:00
Pavel Minaev
8d189c8e91 Improve timeline logging for DAP messages:
Show only the metadata necessary to identify the message to reduce verbosiy.

Use JSON representation for easy matching against message logs.
2019-07-18 10:13:02 -07:00
Karthik Nadig
60434f405d
Minor fixes to get debugger working (#1597) 2019-07-15 19:45:28 -07:00
Karthik Nadig
d24a39de31
Create client socket and connect to debug server (#1595)
* Create client socket and connect to debug server

* Addressing comments

* Some minor fixes
2019-07-15 14:35:47 -07:00
Pavel Minaev
c03206972d Fix remaining tests to reflect the debug adapter refactoring changes.
Fix Flask and Django multiprocess tests.

Fix test logs not being captured by pytest.

Fix "import debug_me" check improperly applied in tests where it is unnecessary.

Fix some clarifying patterns not respecting the underlying pattern.

Add pattern helpers for strings: starting_with, ending_with, containing.

Move DAP test helpers to a separate module, and add a helper for frames.

Add support for line markers when setting breakpoints and matching frames.

Assorted test fixes around handling of Unicode and paths.
2019-07-11 16:19:06 -07:00
Pavel Minaev
af768a7611 Blacken more modules. 2019-07-08 12:03:31 -07:00
Pavel Minaev
42bbc0946d Test fixes. 2019-07-08 12:03:31 -07:00
Pavel Minaev
0f76b660ed Fix and refactor debugServer mode for ptvsd.adapter. (#1567)
Add launch.json for convenient testing of ptvsd.adapter.

Various minor fixes.
2019-07-08 11:38:25 -07:00
Karthik Nadig
e14ae2c0f9
Add option to connect to adapter via port from IDE (#1562)
* Add option to connect to adapter via port from IDE

* Addressing comments.
2019-07-03 20:11:36 -07:00
Pavel Minaev
773ecb5643 Fix #1552: attach_socket_import tests hang waiting for "process" event
Preload codecs used by ptvsd and pydevd to avoid deadlocks when calling wait_for_attach()  while importing a module on Python 2.
2019-07-02 22:38:37 -07:00
Pavel Minaev
82b62b77b5 Fix #1551: Backchannel failures in tests
Fix various bugs around handling of disconnect in JsonIOStream and JsonMessageChannel.

Fix handling of DAP "terminated" event in debug.Session.

Add --ptvsd-logs and --pydevd-logs switches to pytest.

Improve message logging to fully capture the raw message data in the logs if deserialization fails.

Log all debuggee environment variables in debug.Session, and improve log readability.
2019-07-02 17:05:51 -07:00
Karthik Nadig
833011d901
Custom pydevd event to support InputRequested (#1546) 2019-07-01 10:24:51 -07:00
Karthik Nadig
8d75d6d819
Test refactoring migrated to new api (#1544)
* Update ANY to some

* Refactor breakpoint lines in tests

* Replace old import and emable debug with debug_me

* Remove unused code

* Fix some linter issues

* Change from some.such_that to some.str.such_that

* Linting with black
2019-06-28 16:27:38 -07:00
Pavel Minaev
f71f0a5b0a Tests refactoring. (#1543) 2019-06-28 10:13:00 -07:00
Karthik Nadig
b29c459ff8
Migrate bunch of requests, Fix #1491, Fix #1492, Fix #1493 (#1517)
* Migrate bunch of requests, Fix #1491, #1492, #1493

* Use new api

* Tweak some requests

* fix linter

* Address comments.

* linter fixes
2019-06-21 16:44:17 -07:00
Pavel Minaev
5b10a74698 Blacken newly written code. 2019-06-19 01:06:57 -07:00
Pavel Minaev
b9e02b9e79
Fix and improve comments and docstrings 2019-06-19 00:58:30 -07:00
Pavel Minaev
106f9a8852
Fix outdated comment 2019-06-19 00:13:21 -07:00
Pavel Minaev
1e6ba092d3 Refactor messaging:
- better propagation of messages and errors
- implicit error handling for invalid messages
- fix various issues related to disconnecting

Fix messaging tests.

Separate formatter from logging for reuse.

Add more Python 2/3 compatibility helpers.
2019-06-18 18:08:49 -07:00
Pavel Minaev
336d8609a7 Fix and refactor message propagation API. 2019-06-12 13:24:08 -07:00
Pavel Minaev
deedc8f57b Fix #1486: Message processing/forwarding loop
Implements the main message loops for IDE and debug server communication channels, and framework for DAP message handlers.

Lays out scaffolding for debuggee process management and connectivity.

Implements generic message propagation between IDE and debug server.

Partially implements playback of the initialization sequence when debug server is connected (without validation).

Implements `initialize`, `disconnect`, and `terminate` DAP messages.

Partially implements `attach`, `launch`, and `configurationDone` DAP messages.
2019-06-10 14:58:54 -07:00