We can get Invalid Handle (6) if the main thread
has exited. */
if (err != ERROR_INVALID_HANDLE && err != ERROR_ACCESS_DENIED)
- warning (_("SuspendThread (tid=0x%x) failed. (winerr %u)"),
- (unsigned) tid, (unsigned) err);
+ warning (_("SuspendThread (tid=0x%x) failed. (winerr %u: %s)"),
+ (unsigned) tid, (unsigned) err, strwinerror (err));
suspended = -1;
}
else
if (ResumeThread (h) == (DWORD) -1)
{
DWORD err = GetLastError ();
- warning (_("warning: ResumeThread (tid=0x%x) failed. (winerr %u)"),
- (unsigned) tid, (unsigned) err);
+ warning (_("warning: ResumeThread (tid=0x%x) failed. (winerr %u: %s)"),
+ (unsigned) tid, (unsigned) err, strwinerror (err));
}
}
suspended = 0;
len = GetModuleFileNameEx (handle,
dh_buf, pathbuf, exe_name_max_len);
if (len == 0)
- error (_("Error getting executable filename: %u."),
- (unsigned) GetLastError ());
+ {
+ unsigned err = (unsigned) GetLastError ();
+ error (_("Error getting executable filename (error %u): %s"),
+ err, strwinerror (err));
+ }
if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, exe_name_ret,
exe_name_max_len) < 0)
error (_("Error converting executable filename to POSIX: %d."), errno);
len = GetModuleFileNameEx (handle,
dh_buf, exe_name_ret, exe_name_max_len);
if (len == 0)
- error (_("Error getting executable filename: %u."),
- (unsigned) GetLastError ());
+ {
+ unsigned err = (unsigned) GetLastError ();
+ error (_("Error getting executable filename (error %u): %s"),
+ err, strwinerror (err));
+ }
#endif
return 1; /* success */
check (BOOL ok, const char *file, int line)
{
if (!ok)
- gdb_printf ("error return %s:%d was %u\n", file, line,
- (unsigned) GetLastError ());
+ {
+ unsigned err = (unsigned) GetLastError ();
+ gdb_printf ("error return %s:%d was %u: %s\n", file, line,
+ err, strwinerror (err));
+ }
}
/* See nat/windows-nat.h. */
res = continue_last_debug_event (continue_status, debug_events);
if (!res)
- error (_("Failed to resume program execution"
- " (ContinueDebugEvent failed, error %u)"),
- (unsigned int) GetLastError ());
+ {
+ unsigned err = (unsigned) GetLastError ();
+ error (_("Failed to resume program execution"
+ " (ContinueDebugEvent failed, error %u: %s)"),
+ err, strwinerror (err));
+ }
return res;
}
windows_process.open_process_used = 1;
else
{
- error (_("OpenProcess call failed, GetLastError = %u"),
- (unsigned) GetLastError ());
+ unsigned err = (unsigned) GetLastError ();
+ error (_("OpenProcess call failed, GetLastError = %u: %s"),
+ err, strwinerror (err));
/* We can not debug anything in that case. */
}
add_thread (ptid_t (windows_process.current_event.dwProcessId, 0,
#endif
if (!ok)
- error (_("Can't attach to process %u (error %u)"),
- (unsigned) pid, (unsigned) GetLastError ());
+ {
+ unsigned err = (unsigned) GetLastError ();
+ error (_("Can't attach to process %u (error %u: %s)"),
+ (unsigned) pid, err, strwinerror (err));
+ }
DebugSetProcessKillOnExit (FALSE);
resume (ptid, 0, GDB_SIGNAL_0);
if (!DebugActiveProcessStop (windows_process.current_event.dwProcessId))
- error (_("Can't detach process %u (error %u)"),
- (unsigned) windows_process.current_event.dwProcessId,
- (unsigned) GetLastError ());
+ {
+ unsigned err = (unsigned) GetLastError ();
+ error (_("Can't detach process %u (error %u: %s)"),
+ (unsigned) windows_process.current_event.dwProcessId,
+ err, strwinerror (err));
+ }
DebugSetProcessKillOnExit (FALSE);
target_announce_detach (from_tty);
tty = CreateFileA (inferior_tty.c_str (), GENERIC_READ | GENERIC_WRITE,
0, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (tty == INVALID_HANDLE_VALUE)
- warning (_("Warning: Failed to open TTY %s, error %#x."),
- inferior_tty.c_str (), (unsigned) GetLastError ());
+ {
+ unsigned err = (unsigned) GetLastError ();
+ warning (_("Warning: Failed to open TTY %s, error %#x: %s"),
+ inferior_tty.c_str (), err, strwinerror (err));
+ }
}
if (redirected || tty != INVALID_HANDLE_VALUE)
{
#endif /* !__CYGWIN__ */
if (!ret)
- error (_("Error creating process %s, (error %u)."),
- exec_file, (unsigned) GetLastError ());
+ {
+ unsigned err = (unsigned) GetLastError ();
+ error (_("Error creating process %s, (error %u: %s)"),
+ exec_file, err, strwinerror (err));
+ }
#ifdef __x86_64__
BOOL wow64;
#define _T(x) TEXT (x)
#endif
-#ifndef COUNTOF
-#define COUNTOF(STR) (sizeof (STR) / sizeof ((STR)[0]))
-#endif
-
int using_threads = 1;
const struct target_desc *win32_tdesc;
(*the_low_target.store_inferior_register) (regcache, th, regno);
}
-/* Map the Windows error number in ERROR to a locale-dependent error
- message string and return a pointer to it. Typically, the values
- for ERROR come from GetLastError.
-
- The string pointed to shall not be modified by the application,
- but may be overwritten by a subsequent call to strwinerror
-
- The strwinerror function does not change the current setting
- of GetLastError. */
-
-char *
-strwinerror (DWORD error)
-{
- static char buf[1024];
- TCHAR *msgbuf;
- DWORD lasterr = GetLastError ();
- DWORD chars = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
- | FORMAT_MESSAGE_ALLOCATE_BUFFER,
- NULL,
- error,
- 0, /* Default language */
- (LPTSTR) &msgbuf,
- 0,
- NULL);
- if (chars != 0)
- {
- /* If there is an \r\n appended, zap it. */
- if (chars >= 2
- && msgbuf[chars - 2] == '\r'
- && msgbuf[chars - 1] == '\n')
- {
- chars -= 2;
- msgbuf[chars] = 0;
- }
-
- if (chars > ((COUNTOF (buf)) - 1))
- {
- chars = COUNTOF (buf) - 1;
- msgbuf [chars] = 0;
- }
-
-#ifdef UNICODE
- wcstombs (buf, msgbuf, chars + 1);
-#else
- strncpy (buf, msgbuf, chars + 1);
-#endif
- LocalFree (msgbuf);
- }
- else
- sprintf (buf, "unknown win32 error (%u)", (unsigned) error);
-
- SetLastError (lasterr);
- return buf;
-}
-
static BOOL
create_process (const char *program, char *args,
DWORD flags, PROCESS_INFORMATION *pi)
/* Retrieve the context for this thread, if not already retrieved. */
extern void win32_require_context (windows_nat::windows_thread_info *th);
-/* Map the Windows error number in ERROR to a locale-dependent error
- message string and return a pointer to it. Typically, the values
- for ERROR come from GetLastError.
-
- The string pointed to shall not be modified by the application,
- but may be overwritten by a subsequent call to strwinerror
-
- The strwinerror function does not change the current setting
- of GetLastError. */
-extern char * strwinerror (DWORD error);
-
#endif /* GDBSERVER_WIN32_LOW_H */
#include "common-defs.h"
#include "errors.h"
+#ifdef USE_WIN32API
+#include <windows.h>
+#endif /* USE_WIN32API */
/* See gdbsupport/errors.h. */
internal_vwarning (file, line, fmt, ap);
va_end (ap);
}
+
+#ifdef USE_WIN32API
+
+/* See errors.h. */
+
+const char *
+strwinerror (ULONGEST error)
+{
+ static char buf[1024];
+ TCHAR *msgbuf;
+ DWORD lasterr = GetLastError ();
+ DWORD chars = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+ NULL,
+ error,
+ 0, /* Default language */
+ (LPTSTR) &msgbuf,
+ 0,
+ NULL);
+ if (chars != 0)
+ {
+ /* If there is an \r\n appended, zap it. */
+ if (chars >= 2
+ && msgbuf[chars - 2] == '\r'
+ && msgbuf[chars - 1] == '\n')
+ {
+ chars -= 2;
+ msgbuf[chars] = 0;
+ }
+
+ if (chars > ARRAY_SIZE (buf) - 1)
+ {
+ chars = ARRAY_SIZE (buf) - 1;
+ msgbuf [chars] = 0;
+ }
+
+#ifdef UNICODE
+ wcstombs (buf, msgbuf, chars + 1);
+#else
+ strncpy (buf, msgbuf, chars + 1);
+#endif
+ LocalFree (msgbuf);
+ }
+ else
+ sprintf (buf, "unknown win32 error (%u)", (unsigned) error);
+
+ SetLastError (lasterr);
+ return buf;
+}
+
+#endif /* USE_WIN32API */
extern void flush_streams ();
+#ifdef USE_WIN32API
+
+/* Map the Windows error number in ERROR to a locale-dependent error
+ message string and return a pointer to it. Typically, the values
+ for ERROR come from GetLastError.
+
+ The string pointed to shall not be modified by the application,
+ but may be overwritten by a subsequent call to strwinerror
+
+ The strwinerror function does not change the current setting
+ of GetLastError. */
+
+extern const char *strwinerror (ULONGEST error);
+
+#endif /* USE_WIN32API */
+
#endif /* COMMON_ERRORS_H */