From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mQa1BnHHlGmeNz8AWB0awg (envelope-from ) for ; Tue, 17 Feb 2026 14:54:25 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=q7UHW2tm; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1446A1E0BA; Tue, 17 Feb 2026 14:54:25 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 534811E08D for ; Tue, 17 Feb 2026 14:54:24 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id BC04B4BAE7C0 for ; Tue, 17 Feb 2026 19:54:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC04B4BAE7C0 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=q7UHW2tm Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id D8CA84B9DB5B for ; Tue, 17 Feb 2026 19:53:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8CA84B9DB5B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8CA84B9DB5B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771358018; cv=none; b=j4XJ6+Ti2hve6tBCHBhjIrNwMzPJx58/d5vCDKI77ZaijpYIyqN7jtCTkrcZR0Jm0/Yrtki+u+hDniaLCjZkJzkvwPBYq7jaZHMebotdkcl7b7k8wVa3O9ZNI3I11eEj/UFqIo5hEMlXdDSjMFwnNaDjWcbjiitbT2417aEYJcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771358018; c=relaxed/simple; bh=il/pv/tpZCzTDssz7mDN/SbPyZw1x9gGzYUZfJgoRWo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dQITjy1oGDUbz8goaUME9C3k6VPAL1seTwqwaJc/PEWShdNRDToXEuARQ6hCvpKPtTp8xZHaUbeNtUvJqsMLxfxtnZVadhHtgQvSaRpmlu2z+tep04um3xa4Wpt4Wjxmz+JUvSIkhyTBwrs5oOVsqPGoZmtF06xpVum8EvrFEvs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8CA84B9DB5B Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 61HJrWII173015 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Feb 2026 14:53:36 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 61HJrWII173015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1771358017; bh=c+HzEXJ8ZJayUVEMI3WmKtRkIcYYMVzF1/osv1XG6dI=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=q7UHW2tm7U0S/22NmoitBKWNlKTqTkgrsy9iqGAnOnTmkZIIvcXURKiX65ET7/b44 z2jciizGlD0jPSjA5ZfeDqSUUVQumQdBC8sAy4c1Wx1CfntPh+9eHTjQ0Qv5FucSOg a7G9awLzHJ36mz5hnz3k0hRaoAFB5YB8j+e7vK3ZQ3/xVBZ2ZdRW9vte4HWW/8euk9 F5TLzl3T7lqVVfHnojujk9mD41+87LLVHiA/mBAutR3XGfKlGPIsY7Olw7UA4BWqkQ Oov+/BOjQGMTE49ETdojY+jBGDfHxlnDJE9URBCBgttA3LjSK1Utl3vdFeq7wyVDQe KfGiWt5r8FxpQ== Received: by simark.ca (Postfix) id 9BED01E0BA; Tue, 17 Feb 2026 14:53:30 -0500 (EST) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2 2/9] gdb/ctf: add unique_ptr types Date: Tue, 17 Feb 2026 14:50:51 -0500 Message-ID: <20260217195329.3833518-3-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260217195329.3833518-1-simon.marchi@polymtl.ca> References: <20260203065435.3092465-1-simon.marchi@polymtl.ca> <20260217195329.3833518-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 17 Feb 2026 19:53:32 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi Add ctf_archive_up and ctf_dict_up to automatically manage the lifetime of a ctf_archive_t or ctf_dict_t and use them. Change-Id: I51b3548b1bb28941c7bad776a11a238eb25789e4 --- gdb/ctfread.c | 56 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 141f51f621b0..6c1bbebcf2c8 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -125,28 +125,40 @@ ctf_kind_str (uint32_t kind) using ctf_type_map = gdb::unordered_map; -struct ctf_dict_info +struct ctf_archive_closer { - explicit ctf_dict_info (ctf_dict_t *dict) : dict (dict) {} - ~ctf_dict_info (); + void operator() (ctf_archive_t *arc) const noexcept + { + ctf_close (arc); + } +}; - /* Map from IDs to types. */ - ctf_type_map type_map; +using ctf_archive_up = std::unique_ptr; - /* The dictionary. */ - ctf_dict_t *dict; +struct ctf_dict_closer +{ + void operator() (ctf_dict_t *dict) const noexcept + { + ctf_dict_close (dict); + } }; -/* Cleanup function for the ctf_dict_key data. */ -ctf_dict_info::~ctf_dict_info () +using ctf_dict_up = std::unique_ptr; + +struct ctf_dict_info { - if (dict == nullptr) - return; + explicit ctf_dict_info (ctf_archive_up archive, ctf_dict_up dict) + : archive (std::move (archive)), + dict (std::move (dict)) + {} - ctf_archive_t *arc = ctf_get_arc (dict); - ctf_dict_close (dict); - ctf_close (arc); -} + /* Map from IDs to types. */ + ctf_type_map type_map; + + /* The archive and dictionary. */ + ctf_archive_up archive; + ctf_dict_up dict; +}; static const registry::key ctf_dict_key; @@ -1542,26 +1554,28 @@ elfctf_build_psymtabs (struct objfile *of) CTF_SCOPED_DEBUG_START_END ("building psymtabs for %s", bfd_get_filename (abfd)); - ctf_archive_t *arc = ctf_bfdopen (abfd, &err); + ctf_archive_up arc (ctf_bfdopen (abfd, &err)); if (arc == nullptr) error (_("ctf_bfdopen failed on %s - %s"), bfd_get_filename (abfd), ctf_errmsg (err)); - ctf_dict_t *dict = ctf_dict_open (arc, NULL, &err); + ctf_dict_up dict (ctf_dict_open (arc.get (), NULL, &err)); if (dict == nullptr) error (_("ctf_dict_open failed on %s - %s"), bfd_get_filename (abfd), ctf_errmsg (err)); - ctf_dict_key.emplace (of, dict); - pcu.dict = dict; + ctf_dict_info &dict_info + = ctf_dict_key.emplace (of, std::move (arc), std::move (dict)); + + pcu.dict = dict_info.dict.get (); pcu.of = of; - pcu.arc = arc; + pcu.arc = dict_info.archive.get (); psymbol_functions *psf = new psymbol_functions (); of->qf.emplace_front (psf); pcu.psf = psf; - if (ctf_archive_iter (arc, build_ctf_archive_member, &pcu) < 0) + if (ctf_archive_iter (pcu.arc, build_ctf_archive_member, &pcu) < 0) error (_("ctf_archive_iter failed in input file %s: - %s"), bfd_get_filename (abfd), ctf_errmsg (err)); } -- 2.53.0