Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Local attach #200

Closed
int19h opened this issue Mar 12, 2018 · 5 comments
Closed

Local attach #200

int19h opened this issue Mar 12, 2018 · 5 comments
Assignees

Comments

@int19h
Copy link
Contributor

int19h commented Mar 12, 2018

Need to investigate how to implement attaching directly to a local running process (i.e. not via remote debugging) with pydevd. We already ship the attach helper DLLs, but it's likely that they won't "just work", because of the way we deploy pydevd inside of our own package.

@int19h int19h added this to the VS stable milestone Mar 12, 2018
@int19h int19h self-assigned this Mar 12, 2018
@huguesv
Copy link
Contributor

huguesv commented May 1, 2018

FYI regarding local attach and Python 3.7: microsoft/PTVS#4145
Python 3.7 schedule is at https://www.python.org/dev/peps/pep-0537/

@MikhailArkhipov MikhailArkhipov modified the milestones: VS stable, June 2018 May 2, 2018
@karthiknadig karthiknadig modified the milestones: June 2018.2, Future Jun 6, 2018
@DonJayamanne
Copy link
Contributor

DonJayamanne commented Jun 22, 2018

@karthiknadig @MikhailArkhipov @int19h
Good news, I've managed to get this working. In fact it was fairly simple, now that we have ptvsd.enable_attach.

Highlevel Solution:

  • Use existing code in pydevd to inject arbitrary python code.
  • inject the code ptvsd.enable_attach
  • That's it

Lets talk about this Next week.

@int19h I looked at this because I was working on a totally different debugging scenario and came across the injection code in Pydev.

Drawbacks:

@fabioz
Copy link
Contributor

fabioz commented Jun 22, 2018

As a note, in the attach to process there's a provision to break into existing threads (specifically in https://github.com/Microsoft/ptvsd/blob/master/ptvsd/_vendored/pydevd/pydevd_attach_to_process/dll/attach.cpp#L1224 it sets the internal state to a thread and then calls the settrace in it).

This file is very close to the attach from ptvsd, so, it should be relatively straightforward to port the Python 3.7 fix from zooba/PTVS@62d6268.

@DonJayamanne
Copy link
Contributor

Here's the prototype code - https://github.com/DonJayamanne/ptvsd/commits/attach
We might need to change:

  • The way the debugger connects to VSC
  • End the session (debugger host in the process) when debugger is disconnected
    Based on the prototype, this should be very easy.

int19h added a commit to int19h/ptvsd that referenced this issue Sep 7, 2018
Add --pid option to ptvsd command line. When used, injects the debugger
into the process with the specified ID, such that it connects back to
the specified host/port.
int19h added a commit to int19h/ptvsd that referenced this issue Sep 7, 2018
Add --pid option to ptvsd command line. When used, injects the debugger
into the process with the specified ID, such that it connects back to
the specified host/port.
int19h added a commit to int19h/ptvsd that referenced this issue Sep 7, 2018
Add --pid option to ptvsd command line. When used, injects the debugger
into the process with the specified ID, such that it connects back to
the specified host/port.
int19h added a commit to int19h/ptvsd that referenced this issue Sep 7, 2018
Add --pid option to ptvsd command line. When used, injects the debugger
into the process with the specified ID, such that it connects back to
the specified host/port.
int19h added a commit to int19h/ptvsd that referenced this issue Sep 10, 2018
Add --pid option to ptvsd command line. When used, injects the debugger
into the process with the specified ID, such that it connects back to
the specified host/port.
int19h added a commit to int19h/ptvsd that referenced this issue Sep 11, 2018
Add --pid option to ptvsd command line. When used, injects the debugger
into the process with the specified ID, such that it connects back to
the specified host/port.
int19h added a commit to int19h/ptvsd that referenced this issue Sep 11, 2018
Add --pid option to ptvsd command line. When used, injects the debugger
into the process with the specified ID, such that it connects back to
the specified host/port.
@int19h
Copy link
Contributor Author

int19h commented Sep 14, 2018

API is probably a bit of a misnomer, since it's basically just a command line switch (or, alternatively, invoking main, passing the same arguments as argv parameter).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants