diagnostics icon indicating copy to clipboard operation
diagnostics copied to clipboard

Add support of standard streams redirection in dbgshim

Open okodron opened this issue 8 years ago • 0 comments

Currently it's impossible to redirect input/output streams of the process created with CreateProcessForLaunch(). Such feature can be useful for debugger implementation for Unix. However PAL version of CreateProcessW supports stream redirection. I propose to extend the API of the dbgshim library with something like this:

EXTERN_C HRESULT
CreateProcessForLaunchEx(
    __in LPWSTR lpCommandLine,
    __in BOOL bSuspendProcess,
    __in LPVOID lpEnvironment,
    __in LPCWSTR lpCurrentDirectory,
    __out PDWORD pProcessId,
    __out HANDLE *pResumeHandle,
    __out HANDLE *pStdInHandle,
    __out HANDLE *pStdOutHandle,
    __out HANDLE *pStdErrHandle);

Also a special portable API for HANDLE reading and writing will be added:

typedef VOID (*PREADHANDLE_CALLBACK)(PVOID pBuffer, DWORD dwBufferSizeInBytes, PVOID parameter);

EXTERN_C HRESULT
RegisterForStandardOutput(
    __in HANDLE hStdOutHandle,
    __in PREADHANDLE_CALLBACK pfnOutCallback,
    __in HANDLE hStdErrHandle,
    __in PREADHANDLE_CALLBACK pfnErrCallback,
    __in PVOID parameter,
    __out PVOID *ppListenerToken);

EXTERN_C HRESULT
WriteStandardHandle(
    __in HANDLE hStdInHandle,
    __in LPCVOID lpBuffer,
    __in DWORD dwNumberOfBytesToWrite,
    __out DWORD *pdwNumberOfBytesWritten
);

EXTERN_C HRESULT
CloseStandardHandle(
    __in HANDLE hStandardHandle);

In such case debugger can handle input/output of the newly created process in a portable way.

okodron avatar Apr 02 '18 15:04 okodron