From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id DBD483858C83; Sun, 16 Oct 2022 18:17:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBD483858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665944252; bh=AV9NSshlaoZ7Z60ak8DANQfRj7LrpbZHsvMYFU/hzX4=; h=From:To:Subject:Date:From; b=ZHXC5EVrOM6ByQiRjuO6qIOmnHsoRfQKvXRHemQxzsiC5y4k1VQ8Ea8q26foMVMhs 5qojhOU4D1Soc3KSnIl+sXBNHb2MHmjAyWIA5RrrPAZ/P6pzNFABZHOFA1YARtC4vG pasgsgKWiDSfsdMzFFM2pLUFx58NdTMbeMQLMlO4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use checked_static_cast in more places X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 45685a2fd86073e76a772c5b677f14f8465a5040 X-Git-Newrev: 98ed24fb35d89eb20179edf6c12f599c7a9e228e Message-Id: <20221016181732.DBD483858C83@sourceware.org> Date: Sun, 16 Oct 2022 18:17:32 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D98ed24fb35d8= 9eb20179edf6c12f599c7a9e228e commit 98ed24fb35d89eb20179edf6c12f599c7a9e228e Author: Tom Tromey Date: Sat Sep 24 13:34:09 2022 -0600 Use checked_static_cast in more places =20 I looked through all the uses of static_cast<... *> in gdb and converted many of them to checked_static_cast. =20 I couldn't test a few of these changes. Diff: --- 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 ()); } =20 /* Information about a thread of which libpthdebug is aware. */ diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index f6591d43871..91e13a03360 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -997,7 +997,7 @@ set_breakpoint_condition (struct breakpoint *b, const c= har *exp, b->cond_string.reset (); =20 if (is_watchpoint (b)) - static_cast (b)->cond_exp.reset (); + gdb::checked_static_cast (b)->cond_exp.reset (); else { int loc_num =3D 1; @@ -1029,7 +1029,7 @@ set_breakpoint_condition (struct breakpoint *b, const= char *exp, expression_up new_exp =3D parse_exp_1 (&arg, 0, 0, 0, &tracker); if (*arg !=3D 0) error (_("Junk at end of expression")); - watchpoint *w =3D static_cast (b); + watchpoint *w =3D gdb::checked_static_cast (b); w->cond_exp =3D std::move (new_exp); w->cond_exp_valid_block =3D tracker.block (); } @@ -8312,7 +8312,7 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdb= arch_, if (type =3D=3D bp_static_tracepoint || type =3D=3D bp_static_marker_tracepoint) { - auto *t =3D static_cast (this); + auto *t =3D gdb::checked_static_cast (this); struct static_tracepoint_marker marker; =20 if (strace_marker_p (this)) @@ -13502,7 +13502,8 @@ insert_single_step_breakpoint (struct gdbarch *gdba= rch, sal.explicit_pc =3D 1; =20 auto *ss_bp - =3D static_cast (tp->control.single_step_break= points); + =3D (gdb::checked_static_cast + (tp->control.single_step_breakpoints)); ss_bp->add_location (sal); =20 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 = ()); } =20 /* 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 ()); } =20 /* Exception port. */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 78f4cc1f60d..3f71ebd1d66 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 =3D get_dwarf2_per_objfile (objfile); =20 - mapped_index *index =3D (static_cast + mapped_index *index =3D (gdb::checked_static_cast (per_objfile->per_bfd->index_table.get ())); gdb_printf (".gdb_index: version %d\n", index->version); gdb_printf ("\n"); @@ -18576,11 +18576,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 =3D=3D nullptr) + return nullptr; cooked_index_vector *table - =3D (static_cast + =3D (gdb::checked_static_cast (per_bfd->index_table.get ())); - if (table =3D=3D nullptr) - return nullptr; return table->lookup (adjusted_pc); } =20 @@ -18597,7 +18597,7 @@ cooked_index_functions::find_compunit_symtab_by_add= ress =20 CORE_ADDR baseaddr =3D objfile->data_section_offset (); cooked_index_vector *table - =3D (static_cast + =3D (gdb::checked_static_cast (per_objfile->per_bfd->index_table.get ())); dwarf2_per_cu_data *per_cu =3D table->lookup (address - baseaddr); if (per_cu =3D=3D nullptr) @@ -18625,7 +18625,7 @@ cooked_index_functions::expand_matching_symbols =3D lang->get_symbol_name_matcher (lookup_name); =20 cooked_index_vector *table - =3D (static_cast + =3D (gdb::checked_static_cast (per_objfile->per_bfd->index_table.get ())); for (const cooked_index_entry *entry : table->all_entries ()) { @@ -18657,7 +18657,7 @@ cooked_index_functions::expand_symtabs_matching return true; =20 cooked_index_vector *table - =3D (static_cast + =3D (gdb::checked_static_cast (per_objfile->per_bfd->index_table.get ())); table->wait (); =20 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_in= fo 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.g= et ()); } =20 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 () =3D=3D LINESPEC_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec= ); } =20 /* 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 () =3D=3D ADDRESS_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec); } =20 /* 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 () =3D=3D PROBE_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec); } =20 /* 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 () =3D=3D EXPLICIT_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec= ); } =20 /* See description in location.h. */ @@ -275,7 +275,7 @@ explicit_location_spec * as_explicit_location_spec (location_spec *locspec) { gdb_assert (locspec->type () =3D=3D EXPLICIT_LOCATION_SPEC); - return static_cast (locspec); + return gdb::checked_static_cast (locspec); } =20 /* 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" =20 /* Target operations defined for Neutrino targets (-nto-tdep.c). = */ =20 @@ -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 ()); } =20 /* 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" =20 /* 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 () =3D=3D process_stratum); - return static_cast (target); + return gdb::checked_static_cast (target); } =20 /* 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 =3D=3D NULL) thread->priv.reset (new remote_thread_info); =20 - return static_cast (thread->priv.get ()); + return gdb::checked_static_cast (thread->priv.get = ()); } =20 /* Return PTID's private thread data, creating it if necessary. */ @@ -6611,7 +6611,7 @@ get_remote_inferior (inferior *inf) if (inf->priv =3D=3D NULL) inf->priv.reset (new remote_inferior); =20 - return static_cast (inf->priv.get ()); + return gdb::checked_static_cast (inf->priv.get ()); } =20 /* Class used to track the construction of a vCont packet in the