Allow olly to attach to an external process #45
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows olly to attach to an external process by directory and PID. That is, it implements #41.
I understand that @tmcgilchrist mentioned here that he has already started working on an implementation, I hope I am not stepping on toes with this.
The primary non-obvious difference between this and the existing code in
launch.ml
is thatUnix.wait
cannot be used to determine if the process is still alive (you can onlywait
for children), and soUnix.kill pid 0
is used instead. According to the POSIX specification ofkill
:and
So
should work portably on Unix.
Olly currently already doesn't work on Windows due to how
Unix
handles PIDs (badly). I leave figuring out what to do with that for a later PR.The second major change is how to actually handle this at the command line. Ideally, as mentioned here, we could do something like
olly gc-stats --attach pid
, while still allowingolly gc-stats /path/to/program
.Cmdliner
has no clean way to express this, so I just specify--attach
as a normal option and fail (still with a command line parsing error) if none/both are specified.I also made
EXECUTABLE
be a sequence of arguments rather than just one space-split one, this makes expressing the above slightly easier. It is also in-line with existing tools likeperf record
orgdb --args
, and allows olly to pass arguments (and execute programs) containing spaces. This part is technically backwards-incompatible, if that's a problem.