From: Simon Marchi Date: Wed, 17 Nov 2021 18:44:01 +0000 (-0500) Subject: gdbsupport: make gdb_assert_not_reached accept a format string X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=557b4d7650ffa3cd6dbfb8a56c830a1d45562d19;p=binutils-gdb.git 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 --- diff --git a/gdb/arch/arc.c b/gdb/arch/arc.c index 813f4ea45f5..f5d81b64881 100644 --- a/gdb/arch/arc.c +++ b/gdb/arch/arc.c @@ -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; diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 8e391a00ed0..67d4db33c9a 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -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 diff --git a/gdb/cli/cli-option.c b/gdb/cli/cli-option.c index 846b8198985..4f5cb036830 100644 --- a/gdb/cli/cli-option.c +++ b/gdb/cli/cli-option.c @@ -445,7 +445,7 @@ parse_option (gdb::array_view 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"); } } diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c index 65f186763f7..e365cefe0cc 100644 --- a/gdb/compile/compile-c-support.c +++ b/gdb/compile/compile-c-support.c @@ -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."); } } }; diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c index 08ebe0f4f3b..fa1cb7a70ba 100644 --- a/gdb/compile/compile-c-symbols.c +++ b/gdb/compile/compile-c-symbols.c @@ -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 diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ed101237587..4a963e4a236 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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."); } } diff --git a/gdb/findvar.c b/gdb/findvar.c index d2b77133982..f7e632809d0 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -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: { diff --git a/gdb/infrun.c b/gdb/infrun.c index 64e535a3477..89a98c20df4 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -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? */ diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 03abd7576fc..e408b19db63 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -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 diff --git a/gdb/remote.c b/gdb/remote.c index c3601972400..61bde5aaa94 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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"); } } diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 522eaa7440e..94dad41a9fd 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -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) diff --git a/gdb/thread-fsm.h b/gdb/thread-fsm.h index 3c11c1d1926..98710abd361 100644 --- a/gdb/thread-fsm.h +++ b/gdb/thread-fsm.h @@ -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"); } }; diff --git a/gdb/tid-parse.c b/gdb/tid-parse.c index 25c4669fdac..6f902dc8637 100644 --- a/gdb/tid-parse.c +++ b/gdb/tid-parse.c @@ -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 diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 0c5107c8d5c..15506fdbf4e 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -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)) diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 89f84a2b942..b06576936be 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -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. */ diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 982d157a932..fe0e18ba0c6 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -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]) diff --git a/gdb/varobj.c b/gdb/varobj.c index d0c857a6906..c448fc82d75 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -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 diff --git a/gdbsupport/filestuff.cc b/gdbsupport/filestuff.cc index 2975a0e6a99..7063dd6ed8c 100644 --- a/gdbsupport/filestuff.cc +++ b/gdbsupport/filestuff.cc @@ -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 */ diff --git a/gdbsupport/gdb_assert.h b/gdbsupport/gdb_assert.h index bc8ad7b5dc4..6628c1d90d5 100644 --- a/gdbsupport/gdb_assert.h +++ b/gdbsupport/gdb_assert.h @@ -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 */