diff --git a/src/ptvsd/adapter/ide.py b/src/ptvsd/adapter/ide.py index 7f516bbd..bbf50c3e 100644 --- a/src/ptvsd/adapter/ide.py +++ b/src/ptvsd/adapter/ide.py @@ -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 diff --git a/tests/debug/session.py b/tests/debug/session.py index 5f18af83..03926dd4 100644 --- a/tests/debug/session.py +++ b/tests/debug/session.py @@ -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() diff --git a/tests/ptvsd/server/test_attach.py b/tests/ptvsd/server/test_attach.py index 636fc285..50037697 100644 --- a/tests/ptvsd/server/test_attach.py +++ b/tests/ptvsd/server/test_attach.py @@ -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):