I am porting an old DOS Ada program to Win32 on NT. I have a task which handles input via ReadConsoleInput. When the program runs outside GDB, keys are processed via this task. When I call ReadConsoleInput from this task within GDB, I get error code 6 (ERROR_INVALID_HANDLE). The handle is the same as when running without GDB. Any clues as to why GDB would affect the reading of the console input? Code Sample Follows: task body Console_task is use Win32; use type Win32.Winnt.HANDLE; use type Interfaces.C.Unsigned_Long; function Scan_Code_To_Key_Stroke is new Unchecked_Conversion( Win32.BYTE, KEY_STROKE_CLASS.PRIMITIVE_TYPE ); function To_Int is new Unchecked_Conversion( Win32.Winnt.HANDLE, Integer ); hConsole_In : Win32.Winnt.HANDLE; In_Rec : aliased Win32.Wincon.INPUT_RECORD; Num_Read : aliased Win32.DWORD; Success : Win32.BOOL := 0; KeyEv : Win32.Wincon.KEY_EVENT_RECORD; KeyStroke : KEY_STROKE_CLASS.PRIMITIVE_TYPE; ALT_KEY_PRESSED : Win32.DWORD := Win32.Wincon.RIGHT_ALT_PRESSED or Win32.Wincon.LEFT_ALT_PRESSED; CTRL_KEY_PRESSED : Win32.DWORD := Win32.Wincon.RIGHT_CTRL_PRESSED or Win32.Wincon.LEFT_CTRL_PRESSED; LSB : Win32.BYTE; ErrorInt : Integer; begin accept Start; HConsole_In := Win32.Winbase.GetStdHandle( Win32.Winbase.STD_INPUT_HANDLE); if HConsole_In = Win32.Winbase.INVALID_HANDLE_VALUE then ErrorInt := Integer( Win32.Winbase.GetLastError ); Debug_IO.Log( ErrorInt, "Console_Task called GetStdHandle"); end if; loop Success := Win32.Wincon.ReadConsoleInput( hConsoleInput => hConsole_In, lpBuffer => In_Rec'Unchecked_Access, nLength => 1, lpNumberOfEventsRead => Num_Read'Unchecked_Access ); if Success = 0 then ErrorInt := Integer( Win32.Winbase.GetLastError ); Key_Fail := Key_Fail + 1; if Key_Fail = 20 then -- Always get here when in GDB, never get here out of GDB Debug_IO.Log("Key_Fail = 20", "Console_Task"); Debug_IO.Log( ErrorInt, "Fail"); Debug_IO.Log( To_Int( HConsole_In), "hConsole_In"); -- Check to see if the Std Input has been changed by GDB??? HConsole_In := Win32.Winbase.GetStdHandle( Win32.Winbase.STD_INPUT_HANDLE); Debug_IO.Log( To_Int( HConsole_In), "hConsole_In"); end if; else Key_Count := Key_Count + 1; if Key_Count = 20 then -- Always get here without GDB, never get here in GDB Debug_IO.Log("Key_Count = 20", "Console_Task"); end if; case In_Rec.EventType is when Win32.Wincon.KEY_EVENT => -- type KEY_EVENT_RECORD is -- wincon.h:41 -- record -- bKeyDown : Win32.BOOL; -- wincon.h:42 -- wRepeatCount : Win32.WORD; -- wincon.h:43 -- wVirtualKeyCode : Win32.WORD; -- wincon.h:44 -- wVirtualScanCode : Win32.WORD; -- wincon.h:45 -- uChar : union_anonymous0_t; -- wincon.h:49 -- dwControlKeyState: Win32.DWORD; -- wincon.h:50 -- end record; KeyEv := In_Rec.Event.KeyEvent; -- -- Set the "special" keys if the appropriate bit mask -- of the Control Key State does not equal 0 -- SELF.ALT_PRESSED := 0 /= ( KeyEv.dwControlKeyState and ALT_KEY_PRESSED ); SELF.CONTROL_PRESSED := 0 /= ( KeyEv.dwControlKeyState and CTRL_KEY_PRESSED ); SELF.EXTENDED_KEY := 0 /= ( KeyEv.dwControlKeyState and Wincon.ENHANCED_KEY ); SELF.SHIFT_PRESSED := 0 /= ( KeyEv.dwControlKeyState and Wincon.SHIFT_PRESSED ); -- Process Keys on the Down Stroke if KeyEv.bKeyDown = 1 then -- set spinner to show interrupt being processed MSG.Set_Spinner_Char( SELF => SELF.SPINNER.all, CHAR => 'U' ); LSB := Win32.Utils.LOBYTE( KeyEv.WVirtualScanCode ); KeyStroke := Scan_Code_To_Key_Stroke( LSB ); Process_Normal_Keystroke( KeyStroke ); MSG.Change_Spinner( SELF => SELF.SPINNER.all ); end if; when others => null; end case; end if; end loop; end Console_Task;