Skip to content

Commit

Permalink
Fix microsoft#1695: Handle IDE, launcher, debug server, and no-debug …
Browse files Browse the repository at this point in the history
…disconnect

Fix microsoft#1721 "runInTerminal" is broken on non-Windows platforms.

Fix microsoft#1722: Output is not captured in "noDebug" with "runInTerminal"

Groundwork for microsoft#1713: adapter: multiple concurrent sessions

Move "launch" request parsing and debuggee process spawning, PID reporting and tracking, stdio "output" capture, and exit code reporting into launcher. Launcher now communicates to the adapter via a full-fledged message channel.

Refactor adapter. Add an abstraction for a debug session, and treat IDE, launcher, and debug server as separate components managed by that session.

Improve adapter logging to capture information about current debug session, and current message handler if any.

Fix reporting exceptions from message handlers.
  • Loading branch information
int19h committed Sep 7, 2019
1 parent 7623560 commit 6a371b9
Show file tree
Hide file tree
Showing 20 changed files with 1,737 additions and 1,861 deletions.
68 changes: 30 additions & 38 deletions src/ptvsd/adapter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,44 @@

import argparse
import locale
import os
import sys

# WARNING: ptvsd and submodules must not be imported on top level in this module,
# and should be imported locally inside main() instead.

# Force absolute path on Python 2.
__file__ = os.path.abspath(__file__)


def main(args):
import ptvsd
from ptvsd.common import log, options
from ptvsd.adapter import channels
from ptvsd.common import log, options as common_options
from ptvsd.adapter import session, options as adapter_options

if args.cls and args.debug_server is not None:
print("\033c")
if args.cls:
sys.stderr.write("\033c")

options.log_dir = args.log_dir
log.stderr_levels |= {"info"}
if args.log_stderr:
adapter_options.log_stderr = True

common_options.log_dir = args.log_dir
log.filename_prefix = "ptvsd.adapter"
log.stderr_levels |= {"info"}
log.to_file()
log.describe_environment("ptvsd.adapter startup environment:")

session = session.Session()
if args.debug_server is None:
address = None
session.connect_to_ide()
else:
address = ("localhost", args.debug_server)
# If in debugServer mode, log "debug" to stderr as well.
log.stderr_levels |= {"debug"}

chan = channels.Channels()
ide = chan.connect_to_ide(address)

ide.start()
ide.send_event(
"output",
{
"category": "telemetry",
"output": "ptvsd.adapter",
"data": {"version": ptvsd.__version__},
},
)
# If in debugServer mode, log everything to stderr.
log.stderr_levels |= set(log.LEVELS)
with session.accept_connection_from_ide(("localhost", args.debug_server)):
pass
session.wait()

# Wait until the IDE debug session is over - everything interesting is going to
# be happening on the background threads running the IDE and the server message
# loops from here on.
ide.wait()

# Make sure the server message loop is also done, but only if the server connection
# has been established.
server = chan.server()
if server is not None:
server.wait()


def _parse_argv():
def _parse_argv(argv):
parser = argparse.ArgumentParser()

parser.add_argument(
Expand All @@ -83,7 +68,14 @@ def _parse_argv():
help="enable logging and use DIR to save adapter logs",
)

return parser.parse_args()
parser.add_argument(
"--log-stderr", action="store_true", help="enable logging to stderr"
)

args = parser.parse_args(argv[1:])
if args.debug_server is None and args.log_stderr:
parser.error("--log-stderr can only be used with --debug-server")
return args


if __name__ == "__main__":
Expand Down Expand Up @@ -117,4 +109,4 @@ def _parse_argv():
# Load locale settings.
locale.setlocale(locale.LC_ALL, "")

main(_parse_argv())
main(_parse_argv(sys.argv))
154 changes: 0 additions & 154 deletions src/ptvsd/adapter/channels.py

This file was deleted.

Loading

0 comments on commit 6a371b9

Please sign in to comment.