Use checked_static_cast in more places
I went through all the uses of dynamic_cast<> in gdb, looking for ones that could be replaced with checked_static_cast. This patch is the result. Regression tested on x86-64 Fedora 34.
This commit is contained in:
parent
29a6701e53
commit
5f48d886a9
7 changed files with 14 additions and 22 deletions
|
@ -342,9 +342,7 @@ static ada_choices_component *
|
||||||
choice_component ()
|
choice_component ()
|
||||||
{
|
{
|
||||||
ada_component *last = components.back ().get ();
|
ada_component *last = components.back ().get ();
|
||||||
ada_choices_component *result = dynamic_cast<ada_choices_component *> (last);
|
return gdb::checked_static_cast<ada_choices_component *> (last);
|
||||||
gdb_assert (result != nullptr);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pop the most recent component from the global stack, and return
|
/* Pop the most recent component from the global stack, and return
|
||||||
|
|
|
@ -1920,8 +1920,7 @@ assign_operation::do_generate_ax (struct expression *exp,
|
||||||
error (_("May only assign to trace state variables"));
|
error (_("May only assign to trace state variables"));
|
||||||
|
|
||||||
internalvar_operation *ivarop
|
internalvar_operation *ivarop
|
||||||
= dynamic_cast<internalvar_operation *> (subop);
|
= gdb::checked_static_cast<internalvar_operation *> (subop);
|
||||||
gdb_assert (ivarop != nullptr);
|
|
||||||
|
|
||||||
const char *name = internalvar_name (ivarop->get_internalvar ());
|
const char *name = internalvar_name (ivarop->get_internalvar ());
|
||||||
struct trace_state_variable *tsv;
|
struct trace_state_variable *tsv;
|
||||||
|
@ -1950,8 +1949,7 @@ assign_modify_operation::do_generate_ax (struct expression *exp,
|
||||||
error (_("May only assign to trace state variables"));
|
error (_("May only assign to trace state variables"));
|
||||||
|
|
||||||
internalvar_operation *ivarop
|
internalvar_operation *ivarop
|
||||||
= dynamic_cast<internalvar_operation *> (subop);
|
= gdb::checked_static_cast<internalvar_operation *> (subop);
|
||||||
gdb_assert (ivarop != nullptr);
|
|
||||||
|
|
||||||
const char *name = internalvar_name (ivarop->get_internalvar ());
|
const char *name = internalvar_name (ivarop->get_internalvar ());
|
||||||
struct trace_state_variable *tsv;
|
struct trace_state_variable *tsv;
|
||||||
|
|
|
@ -246,8 +246,7 @@ gdb_printing_disassembler::stream_from_gdb_disassemble_info (void *dis_info)
|
||||||
{
|
{
|
||||||
gdb_disassemble_info *di = (gdb_disassemble_info *) dis_info;
|
gdb_disassemble_info *di = (gdb_disassemble_info *) dis_info;
|
||||||
gdb_printing_disassembler *dis
|
gdb_printing_disassembler *dis
|
||||||
= dynamic_cast<gdb_printing_disassembler *> (di);
|
= gdb::checked_static_cast<gdb_printing_disassembler *> (di);
|
||||||
gdb_assert (dis != nullptr);
|
|
||||||
ui_file *stream = dis->stream ();
|
ui_file *stream = dis->stream ();
|
||||||
gdb_assert (stream != nullptr);
|
gdb_assert (stream != nullptr);
|
||||||
return stream;
|
return stream;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "gdbsupport/gdb_assert.h"
|
#include "gdbsupport/gdb_assert.h"
|
||||||
|
#include "gdbsupport/gdb-checked-static-cast.h"
|
||||||
#include "location.h"
|
#include "location.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
|
@ -848,8 +849,7 @@ string_to_location_spec (const char **stringp,
|
||||||
linespec parsing below and discard the explicit location
|
linespec parsing below and discard the explicit location
|
||||||
spec. */
|
spec. */
|
||||||
explicit_location_spec *xloc
|
explicit_location_spec *xloc
|
||||||
= dynamic_cast<explicit_location_spec *> (locspec.get ());
|
= gdb::checked_static_cast<explicit_location_spec *> (locspec.get ());
|
||||||
gdb_assert (xloc != nullptr);
|
|
||||||
match_type = xloc->func_name_match_type;
|
match_type = xloc->func_name_match_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "interps.h"
|
#include "interps.h"
|
||||||
#include "ui-out.h"
|
#include "ui-out.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "gdbsupport/gdb-checked-static-cast.h"
|
||||||
|
|
||||||
/* Mark beginning of a table. */
|
/* Mark beginning of a table. */
|
||||||
|
|
||||||
|
@ -327,11 +328,7 @@ mi_out_new (const char *mi_version)
|
||||||
static mi_ui_out *
|
static mi_ui_out *
|
||||||
as_mi_ui_out (ui_out *uiout)
|
as_mi_ui_out (ui_out *uiout)
|
||||||
{
|
{
|
||||||
mi_ui_out *mi_uiout = dynamic_cast<mi_ui_out *> (uiout);
|
return gdb::checked_static_cast<mi_ui_out *> (uiout);
|
||||||
|
|
||||||
gdb_assert (mi_uiout != NULL);
|
|
||||||
|
|
||||||
return mi_uiout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -687,7 +687,7 @@ validate_actionline (const char *line, struct breakpoint *b)
|
||||||
{
|
{
|
||||||
symbol *sym;
|
symbol *sym;
|
||||||
expr::var_value_operation *vvop
|
expr::var_value_operation *vvop
|
||||||
= (dynamic_cast<expr::var_value_operation *>
|
= (gdb::checked_static_cast<expr::var_value_operation *>
|
||||||
(exp->op.get ()));
|
(exp->op.get ()));
|
||||||
sym = vvop->get_symbol ();
|
sym = vvop->get_symbol ();
|
||||||
|
|
||||||
|
@ -1357,7 +1357,7 @@ encode_actions_1 (struct command_line *action,
|
||||||
case OP_REGISTER:
|
case OP_REGISTER:
|
||||||
{
|
{
|
||||||
expr::register_operation *regop
|
expr::register_operation *regop
|
||||||
= (dynamic_cast<expr::register_operation *>
|
= (gdb::checked_static_cast<expr::register_operation *>
|
||||||
(exp->op.get ()));
|
(exp->op.get ()));
|
||||||
const char *name = regop->get_name ();
|
const char *name = regop->get_name ();
|
||||||
|
|
||||||
|
@ -1380,7 +1380,7 @@ encode_actions_1 (struct command_line *action,
|
||||||
tempval = evaluate_expression (exp.get ());
|
tempval = evaluate_expression (exp.get ());
|
||||||
addr = value_address (tempval);
|
addr = value_address (tempval);
|
||||||
expr::unop_memval_operation *memop
|
expr::unop_memval_operation *memop
|
||||||
= (dynamic_cast<expr::unop_memval_operation *>
|
= (gdb::checked_static_cast<expr::unop_memval_operation *>
|
||||||
(exp->op.get ()));
|
(exp->op.get ()));
|
||||||
struct type *type = memop->get_type ();
|
struct type *type = memop->get_type ();
|
||||||
/* Initialize the TYPE_LENGTH if it is a typedef. */
|
/* Initialize the TYPE_LENGTH if it is a typedef. */
|
||||||
|
@ -1397,7 +1397,7 @@ encode_actions_1 (struct command_line *action,
|
||||||
case OP_VAR_VALUE:
|
case OP_VAR_VALUE:
|
||||||
{
|
{
|
||||||
expr::var_value_operation *vvo
|
expr::var_value_operation *vvo
|
||||||
= (dynamic_cast<expr::var_value_operation *>
|
= (gdb::checked_static_cast<expr::var_value_operation *>
|
||||||
(exp->op.get ()));
|
(exp->op.get ()));
|
||||||
struct symbol *sym = vvo->get_symbol ();
|
struct symbol *sym = vvo->get_symbol ();
|
||||||
const char *name = sym->natural_name ();
|
const char *name = sym->natural_name ();
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "gdb_curses.h"
|
#include "gdb_curses.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "pager.h"
|
#include "pager.h"
|
||||||
|
#include "gdbsupport/gdb-checked-static-cast.h"
|
||||||
|
|
||||||
/* This redefines CTRL if it is not already defined, so it must come
|
/* This redefines CTRL if it is not already defined, so it must come
|
||||||
after terminal state releated include files like <term.h> and
|
after terminal state releated include files like <term.h> and
|
||||||
|
@ -832,8 +833,7 @@ tui_setup_io (int mode)
|
||||||
tui_old_stdout = gdb_stdout;
|
tui_old_stdout = gdb_stdout;
|
||||||
tui_old_stderr = gdb_stderr;
|
tui_old_stderr = gdb_stderr;
|
||||||
tui_old_stdlog = gdb_stdlog;
|
tui_old_stdlog = gdb_stdlog;
|
||||||
tui_old_uiout = dynamic_cast<cli_ui_out *> (current_uiout);
|
tui_old_uiout = gdb::checked_static_cast<cli_ui_out *> (current_uiout);
|
||||||
gdb_assert (tui_old_uiout != nullptr);
|
|
||||||
|
|
||||||
/* Reconfigure gdb output. */
|
/* Reconfigure gdb output. */
|
||||||
gdb_stdout = tui_stdout;
|
gdb_stdout = tui_stdout;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue