From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 5088D385840B for ; Tue, 12 Sep 2023 16:27:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5088D385840B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7927f24140eso197962239f.2 for ; Tue, 12 Sep 2023 09:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1694536071; x=1695140871; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oeqd9H/QT2Pnlu7ahEukWy+imwlNURPLepAGtY0ehA4=; b=D17jOrFnnJ6KzmoIgwmSEEfTTkgaHhk0DzdswpYrxQps1WetFrITTsYF1BLdw72olV PfgCnccWTvAypTECXcsIraI5QXvB9Aw50kO8ymwaL4JsLIS96f7gbR1sOpKYhgm7xLvW JidX/RewZN0k/naNK6BDyv4ZeBTZeZqp/+3/kL/xtWKl6hF9SqT0jz3gV9qW6u6Nrvz7 7+4SYY4Kq3yRA2QMm23Y03tzHo2UAjq7DJ/RPnoP7DI4Bwegagw8jKLJ3Aw+fT9QUaFr uZvU3RlEaLq/flvj5JHldvBOVi+F9D9pmndAbT9QS8UrrivU4HOoS/Q9oFlQDwqxExwt 2TcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694536071; x=1695140871; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oeqd9H/QT2Pnlu7ahEukWy+imwlNURPLepAGtY0ehA4=; b=V/aeCmieifeD+QG9DmZ1Df/BouDAP+qQqmoQZ5WQgNyPC5eVJskf4BIQHPnON6RryJ w5K0y6mkz2j4f7IyQ/sVjIAggzof+oEaa7L7FWYBjkG0FCV4UNLtkDUsJdSc/l6xBXZw kQuzexl3IQ2n0ZTnCAa7JDhwscWP0njq2S7OFKQoTXhhiMb2oHbpa8MLmI7fSiBNLHcd 0ozgwZpuBw+QRF79skyud58MVxH5XuYXmNiV+w7md+B7ISe0VI+l2dvqzh+iVq1M4l9Q pqbmiHJzq2omgCYii+imbwtVX5+ZLkXG+EK3UZJnAjn428Gs7zFKUvtNnBALFO+PWzlk s7fg== X-Gm-Message-State: AOJu0YyugV8TK17P8LLfnNhl7gAjKERwZxucXGOpLr/MhGtnXUoLy86g HaUq0Or+Uh6yKxl6r/1uL6jPZTxzN3MsMEaC4mXlYw== X-Google-Smtp-Source: AGHT+IGk9SflfqoatNnq5BldhCDrkQJNeNcVbGpNlXRAlvTBvorR5HaUtUSB0IB8IdB5LhDcpPMtWA== X-Received: by 2002:a5d:9c46:0:b0:792:8230:c17f with SMTP id 6-20020a5d9c46000000b007928230c17fmr344531iof.13.1694536071520; Tue, 12 Sep 2023 09:27:51 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id l1-20020a02cd81000000b0042b91ec7e31sm2872324jap.3.2023.09.12.09.27.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 09:27:51 -0700 (PDT) From: Tom Tromey Date: Tue, 12 Sep 2023 10:27:49 -0600 Subject: [PATCH 2/6] Introduce throw_winerror_with_name MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230912-serial-exceptions-v1-2-af5097485390@adacore.com> References: <20230912-serial-exceptions-v1-0-af5097485390@adacore.com> In-Reply-To: <20230912-serial-exceptions-v1-0-af5097485390@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 | 6 ++---- gdb/windows-nat.c | 31 +++++++++++++++++++------------ gdbserver/win32-low.cc | 11 +++++------ gdbsupport/errors.cc | 8 ++++++++ gdbsupport/errors.h | 7 +++++++ 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 8028494de20..c004b64269b 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -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 diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index d8b33452f46..b26dec12a56 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -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; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 3246957ec44..d94f4a60bc0 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -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. */ diff --git a/gdbsupport/errors.cc b/gdbsupport/errors.cc index b48ce10eef8..59f934c6916 100644 --- a/gdbsupport/errors.cc +++ b/gdbsupport/errors.cc @@ -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 */ diff --git a/gdbsupport/errors.h b/gdbsupport/errors.h index 20f9152b671..a94debf24e6 100644 --- a/gdbsupport/errors.h +++ b/gdbsupport/errors.h @@ -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 */ -- 2.40.1