private string GetOutputDebugString(OUTPUT_DEBUG_STRING_INFO debugString) { if (_processInformation == null) { return("<no process handle>"); } // Note: Sometimes when debugging unit tests, we get AccessViolationException reading bytes from the debuggee. #if false return("<no processed>"); #else var isUnicode = (debugString.fUnicode != 0); var byteCount = (uint)(debugString.nDebugStringLength * (isUnicode ? sizeof(char) : sizeof(byte))); var bytes = new byte[byteCount]; uint bytesRead; if (!Win32.Processes.NativeMethods.ReadProcessMemory(_processInformation.ProcessHandle, debugString.lpDebugStringData, bytes, byteCount, out bytesRead)) { return(string.Format("<error getting debug string from process: {0}>", new LastWin32ErrorException().Message)); } var message = (isUnicode ? Conversion.UnicodeToUnicode(bytes) : Conversion.AnsiToUnicode(bytes)); message = message.TrimEnd('\r', '\n'); return(message); #endif }