aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-07-20 12:46:08 -0600
committerTom Tromey <tromey@adacore.com>2022-08-16 08:04:37 -0600
commit02d04eac24f497e34ac9869bac5bfb1e044a6b62 (patch)
tree5dbf104d58fe1abec6fe1338fb823c78a443de06 /gdb
parentec29a63c80602056bfc8533d230394d0db14b982 (diff)
downloadfsf-binutils-gdb-02d04eac24f497e34ac9869bac5bfb1e044a6b62.zip
fsf-binutils-gdb-02d04eac24f497e34ac9869bac5bfb1e044a6b62.tar.gz
fsf-binutils-gdb-02d04eac24f497e34ac9869bac5bfb1e044a6b62.tar.bz2
Use strwinerror in gdb/windows-nat.c
When working on windows-nat.c, it's useful to see an error message in addition to the error number given by GetLastError. This patch moves strwinerror from gdbserver to gdbsupport, and then updates windows-nat.c to use it. A couple of minor changes to strwinerror (constify the return type and use the ARRAY_SIZE macro) are also included.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/nat/windows-nat.c22
-rw-r--r--gdb/windows-nat.c51
2 files changed, 49 insertions, 24 deletions
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
index ea6e298..ba60b58 100644
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -95,8 +95,8 @@ windows_thread_info::suspend ()
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
@@ -113,8 +113,8 @@ windows_thread_info::resume ()
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;
@@ -204,8 +204,11 @@ windows_process_info::get_exec_module_filename (char *exe_name_ret,
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);
@@ -214,8 +217,11 @@ windows_process_info::get_exec_module_filename (char *exe_name_ret,
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 */
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 9265ed9..1e31037 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -325,8 +325,11 @@ static void
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. */
@@ -1160,9 +1163,12 @@ windows_continue (DWORD continue_status, int id, int killed)
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;
}
@@ -1179,8 +1185,9 @@ windows_nat_target::fake_create_process ()
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,
@@ -1887,8 +1894,11 @@ windows_nat_target::attach (const char *args, int from_tty)
#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);
@@ -1916,9 +1926,12 @@ windows_nat_target::detach (inferior *inf, int from_tty)
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);
@@ -2526,8 +2539,11 @@ windows_nat_target::create_inferior (const char *exec_file,
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)
{
@@ -2608,8 +2624,11 @@ windows_nat_target::create_inferior (const char *exec_file,
#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;