Fix #1983: Attach to process: Support pid sent as a string from the extension

Allow "processId" in "attach" request to be a string, if it can be parsed as int.
This commit is contained in:
Pavel Minaev 2019-12-13 13:09:47 -08:00 committed by Pavel Minaev
parent ffbf0e16d1
commit a654c9834f
3 changed files with 22 additions and 2 deletions

View file

@ -304,13 +304,18 @@ class IDE(components.Component, sockets.ClientConnection):
# will be the one for the root debuggee process, but if it has exited already,
# it will be some subprocess.
pid = request("processId", int, optional=True)
pid = request("processId", (int, unicode), optional=True)
sub_pid = request("subProcessId", int, optional=True)
if pid != ():
if sub_pid != ():
raise request.isnt_valid(
'"processId" and "subProcessId" are mutually exclusive'
)
if not isinstance(pid, int):
try:
pid = int(pid)
except Exception:
raise request.isnt_valid('"processId" must be parseable as int')
ptvsd_args = request("ptvsdArgs", json.array(unicode))
servers.inject(pid, ptvsd_args)
timeout = 10

View file

@ -142,6 +142,11 @@ class Session(object):
)
"""The debug configuration for this session."""
self.before_request = lambda command, arguments: None
"""Invoked for every outgoing request in this session, allowing any final
tweaks to the request before it is sent.
"""
self.log_dir = (
None
if log.log_dir is None
@ -437,6 +442,8 @@ class Session(object):
)
def send_request(self, command, arguments=None, proceed=True):
self.before_request(command, arguments)
if self.timeline.is_frozen and proceed:
self.proceed()

View file

@ -130,7 +130,8 @@ def test_reattach(pyfile, target, run):
session2.request_continue()
def test_attach_by_pid(pyfile, target):
@pytest.mark.parametrize("pid_type", ["int", "str"])
def test_attach_by_pid(pyfile, target, pid_type):
@pyfile
def code_to_debug():
import debug_me # noqa
@ -147,6 +148,13 @@ def test_attach_by_pid(pyfile, target):
break
with debug.Session() as session:
def before_request(command, arguments):
if command == "attach":
assert isinstance(arguments["processId"], int)
if pid_type == "str":
arguments["processId"] = str(arguments["processId"])
session.before_request = before_request
session.config["redirectOutput"] = True
with session.attach_by_pid(target(code_to_debug), wait=False):