aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/gdb-checked-static-cast.h
AgeCommit message (Collapse)AuthorFilesLines
2023-05-24gdbsupport: add support for references to checked_static_castSimon Marchi1-0/+16
Add a checked_static_cast overload that works with references. A bad dynamic cast with references throws std::bad_cast, it would be possible to implement the new overload based on that, but it seemed simpler to just piggy back off the existing function. I found some potential uses of this new overload in amd-dbgapi-target.c, update them to illustrate the use of the new overload. To build amd-dbgapi-target.c, on needs the amd-dbgapi library, which I don't expect many people to have. But I have it, and it builds fine here. I did test the new overload by making a purposely bad cast and it did catch it. Change-Id: Id6b6a7db09fe3b4aa43cddb60575ff5f46761e96 Reviewed-By: Lancelot SIX <lsix@lancelotsix.com> Reviewed-By: Andrew Burgess <aburgess@redhat.com>
2023-01-31gdbsupport: allow passing nullptr to checked_static_castSimon Marchi1-0/+3
Both static_cast and dynamic_cast handle nullptr (they return nullptr), so I think checked_static_cast should too. This will allow doing a null check after a checked_static_cast: cooked_index_vector *table = (gdb::checked_static_cast<cooked_index_vector *> (per_bfd->index_table.get ())); if (table != nullptr) return; Change-Id: If5c3134e63696f8e417c87b5f3901240c9f7ea97
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker1-1/+1
This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
2022-07-21gdbsupport: add checked_static_castAndrew Burgess1-0/+68
This commit was inspired by these mailing list posts: https://sourceware.org/pipermail/gdb-patches/2022-June/190323.html https://sourceware.org/pipermail/gdb-patches/2022-April/188098.html The idea is to add a new function gdb::checked_static_cast, which can, in some cases, be used as a drop-in replacement for static_cast. And so, if I previously wrote this: BaseClass *base = get_base_class_pointer (); DerivedClass *derived = static_cast<DerivedClass *> (base); I can now write: BaseClass *base = get_base_class_pointer (); DerivedClass *derived = gdb::checked_static_cast<DerivedClass *> (base); The requirement is that BaseClass and DerivedClass must be polymorphic. The benefit of making this change is that, when GDB is built in developer mode, a run-time check will be made to ensure that `base` really is of type DerivedClass before the cast is performed. If `base` is not of type DerivedClass then GDB will assert. In a non-developer build gdb::checked_static_cast is equivalent to a static_cast, and there should be no performance difference. This commit adds the support function, but does not make use of this function, a use will be added in the next commit. Co-Authored-By: Pedro Alves <pedro@palves.net> Co-Authored-By: Tom Tromey <tom@tromey.com>