From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy1-pub.mail.unifiedlayer.com (gproxy1-pub.mail.unifiedlayer.com [69.89.25.95]) by sourceware.org (Postfix) with ESMTPS id DDD163858CDA for ; Sun, 25 Sep 2022 21:11:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DDD163858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway3.mail.pro1.eigbox.com (Postfix) with ESMTP id DB0DA10046F23 for ; Sun, 25 Sep 2022 21:11:22 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id cYuHoUmVwvlAacYuIoXjyW; Sun, 25 Sep 2022 21:11:22 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=S+wcfKgP c=1 sm=1 tr=0 ts=6330c3fa a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=xOM3xZuef0cA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=vyHVLNph9YSjhu1Kd-IA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=pOirLmmBfOKX7Haw69v7W4BN46BiUkSwH/jGQmWaEeQ=; b=Nq0lGn9bjCvYvP+FzksFDh+IrH hFGrfJta3i8Evrb5Hb7OhDoITC4GKqcu1aFl2NHdTVpQJyApe6RtobrmGMSEm8eZADPRLyT78uzFO WATlL4TqGXDzDT/df3zC0bj+r; Received: from 71-211-160-49.hlrn.qwest.net ([71.211.160.49]:47276 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ocYuH-000IXM-Cp; Sun, 25 Sep 2022 15:11:21 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/2] Use checked_static_cast in more places Date: Sun, 25 Sep 2022 15:11:06 -0600 Message-Id: <20220925211107.709402-2-tom@tromey.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220925211107.709402-1-tom@tromey.com> References: <20220925211107.709402-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.160.49 X-Source-L: No X-Exim-ID: 1ocYuH-000IXM-Cp X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-160-49.hlrn.qwest.net (localhost.localdomain) [71.211.160.49]:47276 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3028.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Sep 2022 21:11:37 -0000 I looked through all the uses of static_cast<... *> in gdb and converted many of them to checked_static_cast. I couldn't test a few of these changes. --- gdb/aix-thread.c | 2 +- gdb/breakpoint.c | 9 +++++---- gdb/darwin-nat.h | 4 ++-- gdb/dwarf2/read.c | 14 +++++++------- gdb/linux-thread-db.c | 2 +- gdb/location.c | 10 +++++----- gdb/nto-tdep.h | 3 ++- gdb/process-stratum-target.h | 3 ++- gdb/remote.c | 4 ++-- 9 files changed, 27 insertions(+), 24 deletions(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 57e5756e144..e556c153576 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -90,7 +90,7 @@ struct aix_thread_info : public private_thread_info static aix_thread_info * get_aix_thread_info (thread_info *thread) { - return static_cast (thread->priv.get ()); + return gdb::checked_static_cast (thread->priv.get ()); } /* Information about a thread of which libpthdebug is aware. */ diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 002f4a935b1..cbe7b340782 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -999,7 +999,7 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp, b->cond_string.reset (); if (is_watchpoint (b)) - static_cast (b)->cond_exp.reset (); + gdb::checked_static_cast (b)->cond_exp.reset (); else { int loc_num = 1; @@ -1031,7 +1031,7 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp, expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); if (*arg != 0) error (_("Junk at end of expression")); - watchpoint *w = static_cast (b); + watchpoint *w = gdb::checked_static_cast (b); w->cond_exp = std::move (new_exp); w->cond_exp_valid_block = tracker.block (); } @@ -8299,7 +8299,7 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_, if (type == bp_static_tracepoint || type == bp_static_marker_tracepoint) { - auto *t = static_cast (this); + auto *t = gdb::checked_static_cast (this); struct static_tracepoint_marker marker; if (strace_marker_p (this)) @@ -13501,7 +13501,8 @@ insert_single_step_breakpoint (struct gdbarch *gdbarch, sal.explicit_pc = 1; auto *ss_bp - = static_cast (tp->control.single_step_breakpoints); + = (gdb::checked_static_cast + (tp->control.single_step_breakpoints)); ss_bp->add_location (sal); update_global_location_list (UGLL_INSERT); diff --git a/gdb/darwin-nat.h b/gdb/darwin-nat.h index e3dcd963706..f8a14981aee 100644 --- a/gdb/darwin-nat.h +++ b/gdb/darwin-nat.h @@ -154,7 +154,7 @@ struct darwin_exception_info static inline darwin_thread_info * get_darwin_thread_info (class thread_info *thread) { - return static_cast (thread->priv.get ()); + return gdb::checked_static_cast (thread->priv.get ()); } /* Describe an inferior. */ @@ -188,7 +188,7 @@ struct darwin_inferior : public private_inferior static inline darwin_inferior * get_darwin_inferior (inferior *inf) { - return static_cast (inf->priv.get ()); + return gdb::checked_static_cast (inf->priv.get ()); } /* Exception port. */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 35cce9396ae..d34ba69c373 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3102,7 +3102,7 @@ dwarf2_gdb_index::dump (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); - mapped_index *index = (static_cast + mapped_index *index = (gdb::checked_static_cast (per_objfile->per_bfd->index_table.get ())); gdb_printf (".gdb_index: version %d\n", index->version); gdb_printf ("\n"); @@ -18564,11 +18564,11 @@ dwarf2_per_cu_data * cooked_index_functions::find_per_cu (dwarf2_per_bfd *per_bfd, CORE_ADDR adjusted_pc) { + if (per_bfd->index_table == nullptr) + return nullptr; cooked_index_vector *table - = (static_cast + = (gdb::checked_static_cast (per_bfd->index_table.get ())); - if (table == nullptr) - return nullptr; return table->lookup (adjusted_pc); } @@ -18585,7 +18585,7 @@ cooked_index_functions::find_compunit_symtab_by_address CORE_ADDR baseaddr = objfile->data_section_offset (); cooked_index_vector *table - = (static_cast + = (gdb::checked_static_cast (per_objfile->per_bfd->index_table.get ())); dwarf2_per_cu_data *per_cu = table->lookup (address - baseaddr); if (per_cu == nullptr) @@ -18613,7 +18613,7 @@ cooked_index_functions::expand_matching_symbols = lang->get_symbol_name_matcher (lookup_name); cooked_index_vector *table - = (static_cast + = (gdb::checked_static_cast (per_objfile->per_bfd->index_table.get ())); for (const cooked_index_entry *entry : table->all_entries ()) { @@ -18645,7 +18645,7 @@ cooked_index_functions::expand_symtabs_matching return true; cooked_index_vector *table - = (static_cast + = (gdb::checked_static_cast (per_objfile->per_bfd->index_table.get ())); table->wait (); diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 11da82a1abc..839271c01c5 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -317,7 +317,7 @@ struct thread_db_thread_info : public private_thread_info static thread_db_thread_info * get_thread_db_thread_info (thread_info *thread) { - return static_cast (thread->priv.get ()); + return gdb::checked_static_cast (thread->priv.get ()); } static const char * diff --git a/gdb/location.c b/gdb/location.c index e4863fdefce..ba86b7c48f7 100644 --- a/gdb/location.c +++ b/gdb/location.c @@ -221,7 +221,7 @@ const linespec_location_spec * as_linespec_location_spec (const location_spec *locspec) { gdb_assert (locspec->type () == LINESPEC_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec); } /* See description in location.h. */ @@ -240,7 +240,7 @@ const address_location_spec * as_address_location_spec (const location_spec *locspec) { gdb_assert (locspec->type () == ADDRESS_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec); } /* See description in location.h. */ @@ -257,7 +257,7 @@ const probe_location_spec * as_probe_location_spec (const location_spec *locspec) { gdb_assert (locspec->type () == PROBE_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec); } /* See description in location.h. */ @@ -266,7 +266,7 @@ const explicit_location_spec * as_explicit_location_spec (const location_spec *locspec) { gdb_assert (locspec->type () == EXPLICIT_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec); } /* See description in location.h. */ @@ -275,7 +275,7 @@ explicit_location_spec * as_explicit_location_spec (location_spec *locspec) { gdb_assert (locspec->type () == EXPLICIT_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec); } /* Return a string representation of the explicit location spec in diff --git a/gdb/nto-tdep.h b/gdb/nto-tdep.h index f176b70df27..e97eee0708b 100644 --- a/gdb/nto-tdep.h +++ b/gdb/nto-tdep.h @@ -26,6 +26,7 @@ #include "osabi.h" #include "regset.h" #include "gdbthread.h" +#include "gdbsupport/gdb-checked-static-cast.h" /* Target operations defined for Neutrino targets (-nto-tdep.c). */ @@ -145,7 +146,7 @@ struct nto_thread_info : public private_thread_info static inline nto_thread_info * get_nto_thread_info (thread_info *thread) { - return static_cast (thread->priv.get ()); + return gdb::checked_static_cast (thread->priv.get ()); } /* Per-inferior data, common for both procfs and remote. */ diff --git a/gdb/process-stratum-target.h b/gdb/process-stratum-target.h index bb8e39f53a3..62f56166f5e 100644 --- a/gdb/process-stratum-target.h +++ b/gdb/process-stratum-target.h @@ -23,6 +23,7 @@ #include "target.h" #include #include "gdbsupport/intrusive_list.h" +#include "gdbsupport/gdb-checked-static-cast.h" #include "gdbthread.h" /* Abstract base class inherited by all process_stratum targets. */ @@ -160,7 +161,7 @@ static inline process_stratum_target * as_process_stratum_target (target_ops *target) { gdb_assert (target->stratum () == process_stratum); - return static_cast (target); + return gdb::checked_static_cast (target); } /* Return a collection of targets that have non-exited inferiors. */ diff --git a/gdb/remote.c b/gdb/remote.c index 2f6cb2d01ee..17c2d17c8fe 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2694,7 +2694,7 @@ get_remote_thread_info (thread_info *thread) if (thread->priv == NULL) thread->priv.reset (new remote_thread_info); - return static_cast (thread->priv.get ()); + return gdb::checked_static_cast (thread->priv.get ()); } /* Return PTID's private thread data, creating it if necessary. */ @@ -6611,7 +6611,7 @@ get_remote_inferior (inferior *inf) if (inf->priv == NULL) inf->priv.reset (new remote_inferior); - return static_cast (inf->priv.get ()); + return gdb::checked_static_cast (inf->priv.get ()); } /* Class used to track the construction of a vCont packet in the -- 2.34.3