]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbsupport: make gdb_assert_not_reached accept a format string
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 17 Nov 2021 18:44:01 +0000 (13:44 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 18 Nov 2021 16:29:19 +0000 (11:29 -0500)
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

19 files changed:
gdb/arch/arc.c
gdb/ax-gdb.c
gdb/cli/cli-option.c
gdb/compile/compile-c-support.c
gdb/compile/compile-c-symbols.c
gdb/dwarf2/read.c
gdb/findvar.c
gdb/infrun.c
gdb/printcmd.c
gdb/remote.c
gdb/riscv-tdep.c
gdb/thread-fsm.h
gdb/tid-parse.c
gdb/tracepoint.c
gdb/tui/tui-layout.c
gdb/ui-out.c
gdb/varobj.c
gdbsupport/filestuff.cc
gdbsupport/gdb_assert.h

index 813f4ea45f56ef8bd06b6b401af7696f4746a619..f5d81b64881be0dee70306b6e5544f9c4af98bf0 100644 (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;
index 8e391a00ed08ef5c609037b91e3952f09e16fda7..67d4db33c9a4d0eab91d068d96110368b7d264e0 100644 (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
index 846b8198985f9df6f1e02d6ea3fa9297d136c7b6..4f5cb03683058805b58eff37f191e297a3679fc0 100644 (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");
     }
 }
 
index 65f186763f7d4975e462c30139a0f8edf20e2eb0..e365cefe0cc85ed136c65df5f83afeff5d3b23bd 100644 (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.");
     }
   }
 };
index 08ebe0f4f3be7e09a31bb0f03c7f635c5a61677a..fa1cb7a70bab7142d6b0ee127a84904e68296c04 100644 (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
index ed1012375871d634c6dd74bfde4e38226cee749c..4a963e4a236bae75a95883da1e72612c8894f4f1 100644 (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.");
     }
 }
 
index d2b77133982acd07505c5044c66f82d6e2a5f83d..f7e632809d07d881ed145c94d3ce732039fd18da 100644 (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:
       {
index 64e535a34773e605cb77b8493f74c6e0b232d27d..89a98c20df435afd63b52fbbbb0578c55cc6c083 100644 (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?  */
index 03abd7576fc9a08c751cb80943b95ba0e68a082a..e408b19db63c08aa50aa7e864b0f4adece716d24 100644 (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
index c360197240094773b0e802797ff73a349725b2e0..61bde5aaa94312c77140dae5d2bd91d99f2be541 100644 (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");
     }
 }
 
index 522eaa7440e1d7792e59d219507bebf254dad5c2..94dad41a9fdc222b9b11081802fca451b14a9886 100644 (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)
index 3c11c1d19260967831286f6b50d782e02950710d..98710abd36152d7a7498921b38acf5dfffba11ee 100644 (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");
   }
 };
 
index 25c4669fdac75a92e55e7763beb7502ef9837b92..6f902dc863732a91919d57e0cd3078ac524203f4 100644 (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
index 0c5107c8d5c6d840117534f98955ea341ddf6a18..15506fdbf4e88162effce92bdc00a8fa63c0ab62 100644 (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))
index 89f84a2b9425b08bae1f9afdd9caa63537bd6452..b06576936be009221c96dc1f8f56a85bd895c2f1 100644 (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. */
index 982d157a932814c41789417f062533a6a28c7870..fe0e18ba0c66c53e51afaa358feded51dff52bf4 100644 (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])
index d0c857a69060644b225f3072b96c90a44b6d1548..c448fc82d75b04a144c3757a63415b596cdb0370 100644 (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
index 2975a0e6a990a97014412423e3f9a941fee3b8b6..7063dd6ed8cb55f2869ac062a630d0d51f09f087 100644 (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 */
 
index bc8ad7b5dc4e20004e9048d82d8ae1270cf3fad8..6628c1d90d53bdd4a50a046194965edfb899105f 100644 (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 */