mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 23:23:09 +00:00
gdb: ensure the cast in gdbarch_tdep is valid
This commit makes use of gdb::checked_static_cast when casting the generic gdbarch_tdep pointer to a specific sub-class type. This means that, when compiled in developer mode, GDB will validate that the cast is correct. In order to use gdb::checked_static_cast the types involved must have RTTI, which is why the gdbarch_tdep base class now has a virtual destructor. Assuming there are no bugs in GDB where we cast a gdbarch_tdep pointer to the wrong type, then there should be no changes after this commit. If any bugs do exist, then GDB will now assert (in a developer build).
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include "infrun.h"
|
#include "infrun.h"
|
||||||
#include "osabi.h"
|
#include "osabi.h"
|
||||||
#include "displaced-stepping.h"
|
#include "displaced-stepping.h"
|
||||||
|
#include "gdbsupport/gdb-checked-static-cast.h"
|
||||||
|
|
||||||
struct floatformat;
|
struct floatformat;
|
||||||
struct ui_file;
|
struct ui_file;
|
||||||
@@ -58,7 +59,14 @@ struct inferior;
|
|||||||
|
|
||||||
#include "regcache.h"
|
#include "regcache.h"
|
||||||
|
|
||||||
struct gdbarch_tdep {};
|
/* The base class for every architecture's tdep sub-class. The virtual
|
||||||
|
destructor ensures the class has RTTI information, which allows
|
||||||
|
gdb::checked_static_cast to be used, the gdbarch_tdep the function. */
|
||||||
|
|
||||||
|
struct gdbarch_tdep
|
||||||
|
{
|
||||||
|
virtual ~gdbarch_tdep() = default;
|
||||||
|
};
|
||||||
|
|
||||||
/* The architecture associated with the inferior through the
|
/* The architecture associated with the inferior through the
|
||||||
connection to the target.
|
connection to the target.
|
||||||
@@ -157,7 +165,7 @@ static inline TDepType *
|
|||||||
gdbarch_tdep (struct gdbarch *gdbarch)
|
gdbarch_tdep (struct gdbarch *gdbarch)
|
||||||
{
|
{
|
||||||
struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
|
struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
|
||||||
return static_cast<TDepType *> (tdep);
|
return gdb::checked_static_cast<TDepType *> (tdep);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mechanism for co-ordinating the selection of a specific
|
/* Mechanism for co-ordinating the selection of a specific
|
||||||
|
|||||||
Reference in New Issue
Block a user