]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce throw_winerror_with_name
authorTom Tromey <tromey@adacore.com>
Fri, 1 Sep 2023 17:01:33 +0000 (11:01 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 27 Nov 2023 19:55:14 +0000 (12:55 -0700)
This introduces throw_winerror_with_name, a Windows analog of
perror_with_name, and changes various places in gdb to call it.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30770

gdb/nat/windows-nat.c
gdb/windows-nat.c
gdbserver/win32-low.cc
gdbsupport/errors.cc
gdbsupport/errors.h

index bf4c43878863277ef02188e71379433b3974480f..7951bc37d3cfabdbd66b51452f71268d42640ee6 100644 (file)
@@ -206,8 +206,7 @@ windows_process_info::get_exec_module_filename (char *exe_name_ret,
     if (len == 0)
       {
        unsigned err = (unsigned) GetLastError ();
-       error (_("Error getting executable filename (error %u): %s"),
-              err, strwinerror (err));
+       throw_winerror_with_name (_("Error getting executable filename"), err);
       }
     if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, exe_name_ret,
                          exe_name_max_len) < 0)
@@ -219,8 +218,7 @@ windows_process_info::get_exec_module_filename (char *exe_name_ret,
   if (len == 0)
     {
       unsigned err = (unsigned) GetLastError ();
-      error (_("Error getting executable filename (error %u): %s"),
-            err, strwinerror (err));
+      throw_winerror_with_name (_("Error getting executable filename"), err);
     }
 #endif
 
index b3440344c740c3d56c85a3fcf04fe9aaa2794215..39a4e7931c66fde12b2b93324101063e792b98ff 100644 (file)
@@ -1346,9 +1346,9 @@ windows_nat_target::windows_continue (DWORD continue_status, int id,
     });
 
   if (err.has_value ())
-    error (_("Failed to resume program execution"
-            " (ContinueDebugEvent failed, error %u: %s)"),
-          *err, strwinerror (*err));
+    throw_winerror_with_name (_("Failed to resume program execution"
+                               " - ContinueDebugEvent failed"),
+                             *err);
 
   return TRUE;
 }
@@ -1366,8 +1366,7 @@ windows_nat_target::fake_create_process ()
   else
     {
       unsigned err = (unsigned) GetLastError ();
-      error (_("OpenProcess call failed, GetLastError = %u: %s"),
-            err, strwinerror (err));
+      throw_winerror_with_name (_("OpenProcess call failed"), err);
       /*  We can not debug anything in that case.  */
     }
   add_thread (ptid_t (windows_process.current_event.dwProcessId, 0,
@@ -2047,8 +2046,11 @@ windows_nat_target::attach (const char *args, int from_tty)
     });
 
   if (err.has_value ())
-    error (_("Can't attach to process %u (error %u: %s)"),
-          (unsigned) pid, *err, strwinerror (*err));
+    {
+      std::string msg = string_printf (_("Can't attach to process %u"),
+                                      (unsigned) pid);
+      throw_winerror_with_name (msg.c_str (), *err);
+    }
 
   DebugSetProcessKillOnExit (FALSE);
 
@@ -2085,9 +2087,12 @@ windows_nat_target::detach (inferior *inf, int from_tty)
     });
 
   if (err.has_value ())
-    error (_("Can't detach process %u (error %u: %s)"),
-          (unsigned) windows_process.current_event.dwProcessId,
-          *err, strwinerror (*err));
+    {
+      std::string msg
+       = string_printf (_("Can't detach process %u"),
+                        (unsigned) windows_process.current_event.dwProcessId);
+      throw_winerror_with_name (msg.c_str (), *err);
+    }
 
   target_announce_detach (from_tty);
 
@@ -2790,8 +2795,10 @@ windows_nat_target::create_inferior (const char *exec_file,
 #endif /* !__CYGWIN__ */
 
   if (ret.has_value ())
-    error (_("Error creating process %s, (error %u: %s)"),
-          exec_file, *ret, strwinerror (*ret));
+    {
+      std::string msg = _("Error creating process ") + std::string (exec_file);
+      throw_winerror_with_name (msg.c_str (), *ret);
+    }
 
 #ifdef __x86_64__
   BOOL wow64;
index 3842c80daff8c9ca9ce3fc402935c9343a34d4c8..9c0a8856ca7e6473ac2eb1576aff5e4ad6456ff6 100644 (file)
@@ -324,8 +324,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
   if (!IsWow64Process (proch, &wow64))
     {
       DWORD err = GetLastError ();
-      error ("Check if WOW64 process failed (error %d): %s\n",
-            (int) err, strwinerror (err));
+      throw_winerror_with_name ("Check if WOW64 process failed", err);
     }
   windows_process.wow64_process = wow64;
 
@@ -579,8 +578,9 @@ win32_process_target::create_inferior (const char *program,
 
   if (!ret)
     {
-      error ("Error creating process \"%s %s\", (error %d): %s\n",
-            program, args, (int) err, strwinerror (err));
+      std::string msg = string_printf (_("Error creating process \"%s %s\""),
+                                      program, args);
+      throw_winerror_with_name (msg.c_str (), err);
     }
   else
     {
@@ -627,8 +627,7 @@ win32_process_target::attach (unsigned long pid)
     }
 
   err = GetLastError ();
-  error ("Attach to process failed (error %d): %s\n",
-        (int) err, strwinerror (err));
+  throw_winerror_with_name ("Attach to process failed", err);
 }
 
 /* See nat/windows-nat.h.  */
index b48ce10eef8085f481e84fee394d97cc442a7a2c..59f934c6916c5f850132b7565ca08009fef394bc 100644 (file)
@@ -144,4 +144,12 @@ strwinerror (ULONGEST error)
   return buf;
 }
 
+/* See errors.h.  */
+
+void
+throw_winerror_with_name (const char *string, ULONGEST err)
+{
+  error (_("%s (error %d): %s"), string, err, strwinerror (err));
+}
+
 #endif /* USE_WIN32API */
index 20f9152b6713f955ee600725009479e012a2de2f..a94debf24e6f2a1717d887d5b2906a46e572cc0c 100644 (file)
@@ -120,6 +120,13 @@ extern void flush_streams ();
 
 extern const char *strwinerror (ULONGEST error);
 
+/* Like perror_with_name, but for Windows errors.  Throw an exception
+   including STRING and the system text for the given error
+   number.  */
+
+extern void throw_winerror_with_name (const char *string, ULONGEST err)
+  ATTRIBUTE_NORETURN;
+
 #endif /* USE_WIN32API */
 
 #endif /* COMMON_ERRORS_H */