gdbsupport: make gdb_assert_not_reached accept a format string

Change gdb_assert_not_reached to accept a format string plus
corresponding arguments.  This allows giving more precise messages.

Because the format string passed by the caller is prepended with a "%s:"
to add the function name, the callers can no longer pass a translated
string (`_(...)`).  Make the gdb_assert_not_reached include the _(),
just like the gdb_assert_fail macro just above.

Change-Id: Id0cfda5a57979df6cdaacaba0d55dd91ae9efee7
This commit is contained in:
Simon Marchi 2021-11-17 13:44:01 -05:00
parent ab19827912
commit 557b4d7650
19 changed files with 39 additions and 39 deletions

View file

@ -54,7 +54,7 @@ arc_create_target_description (const struct arc_arch_features &features)
std::string msg = string_printf
("Cannot determine architecture: ISA=%d; bitness=%d",
features.isa, 8 * features.reg_size);
gdb_assert_not_reached (msg.c_str ());
gdb_assert_not_reached ("%s", msg.c_str ());
}
set_tdesc_architecture (tdesc.get (), arch_name.c_str ());
@ -75,7 +75,7 @@ arc_create_target_description (const struct arc_arch_features &features)
default:
std::string msg = string_printf
("Cannot choose target description XML: %d", features.isa);
gdb_assert_not_reached (msg.c_str ());
gdb_assert_not_reached ("%s", msg.c_str ());
}
return tdesc;

View file

@ -609,7 +609,7 @@ gen_var_ref (struct agent_expr *ax, struct axs_value *value, struct symbol *var)
break;
case LOC_COMPUTED:
gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
gdb_assert_not_reached ("LOC_COMPUTED variable missing a method");
case LOC_OPTIMIZED_OUT:
/* Flag this, but don't say anything; leave it up to callers to

View file

@ -445,7 +445,7 @@ parse_option (gdb::array_view<const option_def_group> options_group,
default:
/* Not yet. */
gdb_assert_not_reached (_("option type not supported"));
gdb_assert_not_reached ("option type not supported");
}
return {};
@ -824,7 +824,7 @@ add_setshow_cmds_for_options (command_class cmd_class,
set_list, show_list);
}
else
gdb_assert_not_reached (_("option type not handled"));
gdb_assert_not_reached ("option type not handled");
}
}

View file

@ -352,7 +352,7 @@ struct c_add_code_header
break;
default:
gdb_assert_not_reached (_("Unknown compiler scope reached."));
gdb_assert_not_reached ("Unknown compiler scope reached.");
}
}
};
@ -376,7 +376,7 @@ struct c_add_code_footer
break;
default:
gdb_assert_not_reached (_("Unknown compiler scope reached."));
gdb_assert_not_reached ("Unknown compiler scope reached.");
}
}
};
@ -477,7 +477,7 @@ struct cplus_add_code_header
break;
default:
gdb_assert_not_reached (_("Unknown compiler scope reached."));
gdb_assert_not_reached ("Unknown compiler scope reached.");
}
}
};

View file

@ -587,8 +587,8 @@ generate_c_for_for_one_variable (compile_instance *compiler,
error (_("Local symbol unhandled when generating C code."));
case LOC_COMPUTED:
gdb_assert_not_reached (_("LOC_COMPUTED variable "
"missing a method."));
gdb_assert_not_reached ("LOC_COMPUTED variable "
"missing a method.");
default:
/* Nothing to do for all other cases, as they don't represent

View file

@ -19979,7 +19979,7 @@ read_attribute_reprocess (const struct die_reader_specs *reader,
break;
}
default:
gdb_assert_not_reached (_("Unexpected DWARF form."));
gdb_assert_not_reached ("Unexpected DWARF form.");
}
}

View file

@ -364,7 +364,7 @@ symbol_read_needs (struct symbol *sym)
/* All cases listed explicitly so that gcc -Wall will detect it if
we failed to consider one. */
case LOC_COMPUTED:
gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
gdb_assert_not_reached ("LOC_COMPUTED variable missing a method");
case LOC_REGISTER:
case LOC_ARG:
@ -744,7 +744,7 @@ language_defn::read_var_value (struct symbol *var,
break;
case LOC_COMPUTED:
gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
gdb_assert_not_reached ("LOC_COMPUTED variable missing a method");
case LOC_UNRESOLVED:
{

View file

@ -2401,8 +2401,8 @@ resume_1 (enum gdb_signal sig)
step = gdbarch_displaced_step_hw_singlestep (gdbarch);
}
else
gdb_assert_not_reached (_("Invalid displaced_step_prepare_status "
"value."));
gdb_assert_not_reached ("Invalid displaced_step_prepare_status "
"value.");
}
/* Do we need to do it the hard way, w/temp breakpoints? */

View file

@ -1724,7 +1724,7 @@ info_address_command (const char *exp, int from_tty)
break;
case LOC_COMPUTED:
gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
gdb_assert_not_reached ("LOC_COMPUTED variable missing a method");
case LOC_REGISTER:
/* GDBARCH is the architecture associated with the objfile the symbol

View file

@ -2217,7 +2217,7 @@ packet_config_support (struct packet_config *config)
case AUTO_BOOLEAN_AUTO:
return config->support;
default:
gdb_assert_not_reached (_("bad switch"));
gdb_assert_not_reached ("bad switch");
}
}
@ -10316,7 +10316,7 @@ remote_target::extended_remote_run (const std::string &args)
error (_("Running \"%s\" on the remote target failed"),
remote_exec_file);
default:
gdb_assert_not_reached (_("bad switch"));
gdb_assert_not_reached ("bad switch");
}
}

View file

@ -864,7 +864,7 @@ riscv_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
case 4:
return ebreak;
default:
gdb_assert_not_reached (_("unhandled breakpoint kind"));
gdb_assert_not_reached ("unhandled breakpoint kind");
}
}
@ -2877,7 +2877,7 @@ riscv_print_arg_location (ui_file *stream, struct gdbarch *gdbarch,
break;
default:
gdb_assert_not_reached (_("unknown argument location type"));
gdb_assert_not_reached ("unknown argument location type");
}
}
@ -3039,7 +3039,7 @@ riscv_push_dummy_call (struct gdbarch *gdbarch,
break;
default:
gdb_assert_not_reached (_("unknown argument location type"));
gdb_assert_not_reached ("unknown argument location type");
}
if (second_arg_length > 0)

View file

@ -106,7 +106,7 @@ protected:
FSM finishes successfully. */
virtual enum async_reply_reason do_async_reply_reason ()
{
gdb_assert_not_reached (_("should not call async_reply_reason here"));
gdb_assert_not_reached ("should not call async_reply_reason here");
}
};

View file

@ -151,7 +151,7 @@ tid_range_parser::finished () const
return m_range_parser.finished ();
}
gdb_assert_not_reached (_("unhandled state"));
gdb_assert_not_reached ("unhandled state");
}
/* See tid-parse.h. */
@ -168,7 +168,7 @@ tid_range_parser::cur_tok () const
return m_range_parser.cur_tok ();
}
gdb_assert_not_reached (_("unhandled state"));
gdb_assert_not_reached ("unhandled state");
}
void

View file

@ -2641,7 +2641,7 @@ info_scope_command (const char *args_in, int from_tty)
printf_filtered ("optimized out.\n");
continue;
case LOC_COMPUTED:
gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
gdb_assert_not_reached ("LOC_COMPUTED variable missing a method");
}
}
if (SYMBOL_TYPE (sym))

View file

@ -163,7 +163,7 @@ find_layout (tui_layout_split *layout)
if (layout == layouts[i].get ())
return i;
}
gdb_assert_not_reached (_("layout not found!?"));
gdb_assert_not_reached ("layout not found!?");
}
/* Function to set the layout. */

View file

@ -638,10 +638,10 @@ ui_out::vmessage (const ui_file_style &in_style, const char *format,
}
break;
case wide_string_arg:
gdb_assert_not_reached (_("wide_string_arg not supported in vmessage"));
gdb_assert_not_reached ("wide_string_arg not supported in vmessage");
break;
case wide_char_arg:
gdb_assert_not_reached (_("wide_char_arg not supported in vmessage"));
gdb_assert_not_reached ("wide_char_arg not supported in vmessage");
break;
case long_long_arg:
call_do_message (style, current_substring, va_arg (args, long long));
@ -704,16 +704,16 @@ ui_out::vmessage (const ui_file_style &in_style, const char *format,
call_do_message (style, current_substring, va_arg (args, double));
break;
case long_double_arg:
gdb_assert_not_reached (_("long_double_arg not supported in vmessage"));
gdb_assert_not_reached ("long_double_arg not supported in vmessage");
break;
case dec32float_arg:
gdb_assert_not_reached (_("dec32float_arg not supported in vmessage"));
gdb_assert_not_reached ("dec32float_arg not supported in vmessage");
break;
case dec64float_arg:
gdb_assert_not_reached (_("dec64float_arg not supported in vmessage"));
gdb_assert_not_reached ("dec64float_arg not supported in vmessage");
break;
case dec128float_arg:
gdb_assert_not_reached (_("dec128float_arg not supported in vmessage"));
gdb_assert_not_reached ("dec128float_arg not supported in vmessage");
break;
case ptr_arg:
switch (current_substring[2])

View file

@ -661,8 +661,7 @@ varobj_get_iterator (struct varobj *var)
return py_varobj_get_iterator (var, var->dynamic->pretty_printer);
#endif
gdb_assert_not_reached (_("\
requested an iterator from a non-dynamic varobj"));
gdb_assert_not_reached ("requested an iterator from a non-dynamic varobj");
}
static bool

View file

@ -215,7 +215,7 @@ unmark_fd_no_cloexec (int fd)
if (it != open_fds.end ())
open_fds.erase (it);
else
gdb_assert_not_reached (_("fd not found in open_fds"));
gdb_assert_not_reached ("fd not found in open_fds");
}
/* Helper function for close_most_fds that closes the file descriptor
@ -378,7 +378,7 @@ gdb_socketpair_cloexec (int domain, int style, int protocol,
return result;
#else
gdb_assert_not_reached (_("socketpair not available on this host"));
gdb_assert_not_reached ("socketpair not available on this host");
#endif
}
@ -419,7 +419,7 @@ gdb_pipe_cloexec (int filedes[2])
mark_cloexec (filedes[1]);
}
#else /* HAVE_PIPE */
gdb_assert_not_reached (_("pipe not available on this host"));
gdb_assert_not_reached ("pipe not available on this host");
#endif /* HAVE_PIPE */
#endif /* HAVE_PIPE2 */

View file

@ -44,7 +44,8 @@
/* The canonical form of gdb_assert (0).
MESSAGE is a string to include in the error message. */
#define gdb_assert_not_reached(message) \
internal_error (__FILE__, __LINE__, "%s: %s", __func__, _(message))
#define gdb_assert_not_reached(message, ...) \
internal_error (__FILE__, __LINE__, _("%s: " message), __func__, \
##__VA_ARGS__)
#endif /* COMMON_GDB_ASSERT_H */