dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.95k stars 4.65k forks source link

Unable to obtain target process exit code on Linux/Mac with CoreCLR debugging services #43731

Open gregg-miskelly opened 3 years ago

gregg-miskelly commented 3 years ago

Description

On Linux/Mac the exit code of the target process is obtained through waitpid (Linux docs, Apple docs, PAL code that makes use of it). However, unlike on Windows -- if multiple places in a process are calling waitpid, unless the WNOWAIT flag is used (which doesn't seem to exist OSX), then my understanding is that this will prevent other callers from obtaining the exit code.

The debugging services open a HANDLE to the target process (as expected) through the PAL, which means that they may wind up 'owning' the exit code of the target process, but they don't, at least as far as I know, wind up propagating this exit code to the debugger.

The potential fixes I can think of are:

  1. Add a new 'managed callback' interface with another version of the ExitProcess method which provides the exit code to the debugger if the debugging services were able to obtain it. -or-
  2. Make changes to the PAL (ex: new fake access right to indicate that waitpid should be used) and opt-into them with the debugging services to avoid 'owning' the exit code. Thus the calling debugger can reliably use waitpid to obtain the exit code.

Regression?

No, this has never worked on Linux/Mac

ghost commented 3 years ago

Tagging subscribers to this area: @tommcdon See info in area-owners.md if you want to be subscribed.

pavel-orekhov commented 3 years ago

same problem was in netcoredbg cc @kfrolov @viewizard

viewizard commented 3 years ago

Yes, we also faced with this issue and temporary added hook for waitpid in netcoredbg code - https://github.com/Samsung/netcoredbg/blob/0809b8aa1a80c88b35a04106fbfeb9f5be42853e/src/debugger/manageddebugger.cpp#L41-L127