From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 195183858D37 for ; Wed, 1 Feb 2023 19:45:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 195183858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675280752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IBl6KEbx5tmcTC/v2tLtU4zpcZkjYsDK5s+AiDBggOo=; b=FZ0+n+UeyyvMTqkbRnTS9BYLbEoRppqcuFQlCLSeudt9JsrWH/ElZD5EeJf5WI9GUMVF7H 1u1oNeW9CF/h5/nwxttvpSo4iXHlmF1pRo9QmD85YUhDdzCuNgoXB7feo1vNOLtK3T23Sk uqXGFP2BGd7E2cd6dnMlc7Bzw1KlNMg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-378-HB6H3wi5OY25VA4IYm3Qnw-1; Wed, 01 Feb 2023 14:45:49 -0500 X-MC-Unique: HB6H3wi5OY25VA4IYm3Qnw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6696B802314 for ; Wed, 1 Feb 2023 19:45:49 +0000 (UTC) Received: from [10.2.16.136] (unknown [10.2.16.136]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 239802026D68; Wed, 1 Feb 2023 19:45:49 +0000 (UTC) Message-ID: Date: Wed, 1 Feb 2023 11:45:47 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH] gdb/source: Fix open_source_file error handling To: Aaron Merey , gdb-patches@sourceware.org References: <20230128033748.2839360-1-amerey@redhat.com> From: Keith Seitz In-Reply-To: <20230128033748.2839360-1-amerey@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-19.2 required=5.0 tests=BAYES_00,DKIM_INVALID,DKIM_SIGNED,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: On 1/27/23 19:37, Aaron Merey via Gdb-patches wrote: > > Fix this by having open_source_file return a negative errno if it fails > to open a source file. Use this value to generate the error message > instead of errno. Also add new function throw_sys_errmsg for reporting > this value. Thanks for the patch. This LGTM [warning: I am not a maintainer], but I just have two observations (nits?). > diff --git a/gdb/source.c b/gdb/source.c > index be5af180c49..158b59fd613 100644 > --- a/gdb/source.c > +++ b/gdb/source.c > @@ -1200,10 +1204,21 @@ open_source_file (struct symtab *s) > > /* Query debuginfod for the source file. */ > if (build_id != nullptr && !srcpath.empty ()) > - fd = debuginfod_source_query (build_id->data, > - build_id->size, > - srcpath.c_str (), > - &fullname); > + { > + scoped_fd query_fd > + = debuginfod_source_query (build_id->data, > + build_id->size, > + srcpath.c_str (), > + &fullname); > + > + /* Don't return a negative errno from debuginfod_source_query. > + It handles the reporting of its own errors. */ I would prefer to see a comment on this behavior with debuginfod_source_query's description. [Repeating here is fine IMO.] > + if (query_fd.get () >= 0) > + { > + s->fullname = fullname.release (); > + return query_fd; > + } > + } > } > } > > diff --git a/gdb/utils.c b/gdb/utils.c > index 95adbe58e4a..0a5c6a70531 100644 > --- a/gdb/utils.c > +++ b/gdb/utils.c > @@ -670,6 +670,21 @@ print_sys_errmsg (const char *string, int errcode) > gdb_printf (gdb_stderr, "%s: %s.\n", string, err); > } > > +/* Same as perror_with_name except that ERRCODE specifies the error > + instead of errno. */ > + Should this comment be moved to the decl in utils.h? In such cases, we normally use "See utils.h." as a comment at the definition. > +void > +throw_sys_errmsg (const char *string, int errcode) > +{ > + const char *err = safe_strerror (errcode); > + std::string combined = std::string (string) + ": " + err; > + > + bfd_set_error (bfd_error_no_error); > + errno = 0; > + > + throw_error (GENERIC_ERROR, _("%s."), combined.c_str ()); > +} > + > /* Control C eventually causes this to be called, at a convenient time. */ > > void > diff --git a/gdb/utils.h b/gdb/utils.h > index 7865812998e..54a1bc4e476 100644 > --- a/gdb/utils.h > +++ b/gdb/utils.h > @@ -278,6 +278,8 @@ extern void fprintf_symbol (struct ui_file *, const char *, > extern void perror_warning_with_name (const char *string); > > extern void print_sys_errmsg (const char *, int); > + > +extern void throw_sys_errmsg (const char *, int) ATTRIBUTE_NORETURN; > > /* Warnings and error messages. */ FWIW, I've regression tested this on x86_64 both unix/-m64 and native-extended-gdbserver/-m64. There were no issues. Keith