Add multibyte character warning option to the assembler.
[binutils-gdb.git] / gdb / printcmd.c
index 8daa87cf978f086e941ba89b5894818790b6b2c9..e408b19db63c08aa50aa7e864b0f4adece716d24 100644 (file)
@@ -508,7 +508,7 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type,
        opts.format = 0;
        if (type->is_unsigned ())
          type = builtin_type (gdbarch)->builtin_true_unsigned_char;
-       else
+       else
          type = builtin_type (gdbarch)->builtin_true_char;
 
        value_print (value_from_longest (type, *val_long), stream, &opts);
@@ -1266,19 +1266,26 @@ print_value (value *val, const value_print_options &opts)
 static bool
 should_validate_memtags (struct value *value)
 {
-  if (target_supports_memory_tagging ()
-      && gdbarch_tagged_address_p (target_gdbarch (), value))
-    {
-      gdb_assert (value != nullptr && value_type (value) != nullptr);
+  gdb_assert (value != nullptr && value_type (value) != nullptr);
 
-      enum type_code code = value_type (value)->code ();
+  if (!target_supports_memory_tagging ())
+    return false;
 
-      return (code == TYPE_CODE_PTR
-             || code == TYPE_CODE_REF
-             || code == TYPE_CODE_METHODPTR
-             || code == TYPE_CODE_MEMBERPTR);
-    }
-  return false;
+  enum type_code code = value_type (value)->code ();
+
+  /* Skip non-address values.  */
+  if (code != TYPE_CODE_PTR
+      && !TYPE_IS_REFERENCE (value_type (value)))
+    return false;
+
+  /* OK, we have an address value.  Check we have a complete value we
+     can extract.  */
+  if (value_optimized_out (value)
+      || !value_entirely_available (value))
+    return false;
+
+  /* We do.  Check whether it includes any tags.  */
+  return gdbarch_tagged_address_p (target_gdbarch (), value);
 }
 
 /* Helper for parsing arguments for print_command_1.  */
@@ -1321,26 +1328,42 @@ print_command_1 (const char *args, int voidprint)
                    value_type (val)->code () != TYPE_CODE_VOID))
     {
       /* If memory tagging validation is on, check if the tag is valid.  */
-      if (print_opts.memory_tag_violations && should_validate_memtags (val)
-         && !gdbarch_memtag_matches_p (target_gdbarch (), val))
+      if (print_opts.memory_tag_violations)
        {
-         /* Fetch the logical tag.  */
-         struct value *tag
-           = gdbarch_get_memtag (target_gdbarch (), val,
-                                 memtag_type::logical);
-         std::string ltag
-           = gdbarch_memtag_to_string (target_gdbarch (), tag);
-
-         /* Fetch the allocation tag.  */
-         tag = gdbarch_get_memtag (target_gdbarch (), val,
-                                   memtag_type::allocation);
-         std::string atag
-           = gdbarch_memtag_to_string (target_gdbarch (), tag);
-
-         printf_filtered (_("Logical tag (%s) does not match the "
-                            "allocation tag (%s).\n"),
-                          ltag.c_str (), atag.c_str ());
+         try
+           {
+             if (should_validate_memtags (val)
+                 && !gdbarch_memtag_matches_p (target_gdbarch (), val))
+               {
+                 /* Fetch the logical tag.  */
+                 struct value *tag
+                   = gdbarch_get_memtag (target_gdbarch (), val,
+                                         memtag_type::logical);
+                 std::string ltag
+                   = gdbarch_memtag_to_string (target_gdbarch (), tag);
+
+                 /* Fetch the allocation tag.  */
+                 tag = gdbarch_get_memtag (target_gdbarch (), val,
+                                           memtag_type::allocation);
+                 std::string atag
+                   = gdbarch_memtag_to_string (target_gdbarch (), tag);
+
+                 printf_filtered (_("Logical tag (%s) does not match the "
+                                    "allocation tag (%s).\n"),
+                                  ltag.c_str (), atag.c_str ());
+               }
+           }
+         catch (gdb_exception_error &ex)
+           {
+             if (ex.error == TARGET_CLOSE_ERROR)
+               throw;
+
+             fprintf_filtered (gdb_stderr,
+                               _("Could not validate memory tag: %s\n"),
+                               ex.message->c_str ());
+           }
        }
+
       print_value (val, print_opts);
     }
 }
@@ -1525,8 +1548,7 @@ info_symbol_command (const char *arg, int from_tty)
 
        sect_addr = overlay_mapped_address (addr, osect);
 
-       if (obj_section_addr (osect) <= sect_addr
-           && sect_addr < obj_section_endaddr (osect)
+       if (osect->addr () <= sect_addr && sect_addr < osect->endaddr ()
            && (msymbol
                = lookup_minimal_symbol_by_pc_section (sect_addr,
                                                       osect).minsym))
@@ -1661,8 +1683,7 @@ info_address_command (const char *exp, int from_tty)
     }
 
   printf_filtered ("Symbol \"");
-  fprintf_symbol_filtered (gdb_stdout, sym->print_name (),
-                          current_language->la_language, DMGL_ANSI);
+  fputs_filtered (sym->print_name (), gdb_stdout);
   printf_filtered ("\" is ");
   val = SYMBOL_VALUE (sym);
   if (SYMBOL_OBJFILE_OWNED (sym))
@@ -1703,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
@@ -2426,7 +2447,7 @@ printf_c_string (struct ui_file *stream, const char *format,
         null terminated) to be printed without problems.  */
       gdb_byte *tem_str = (gdb_byte *) alloca (len + 1);
 
-      memcpy (tem_str, value_contents (value), len);
+      memcpy (tem_str, value_contents (value).data (), len);
       tem_str [len] = 0;
       str = tem_str;
     }
@@ -2490,7 +2511,7 @@ printf_wide_c_string (struct ui_file *stream, const char *format,
   if (VALUE_LVAL (value) == lval_internalvar
       && c_is_string_type_p (value_type (value)))
     {
-      str = value_contents (value);
+      str = value_contents (value).data ();
       len = TYPE_LENGTH (value_type (value));
     }
   else
@@ -2599,14 +2620,15 @@ printf_floating (struct ui_file *stream, const char *format,
     {
       param_type = float_type_from_length (param_type);
       if (param_type != value_type (value))
-       value = value_from_contents (param_type, value_contents (value));
+       value = value_from_contents (param_type,
+                                    value_contents (value).data ());
     }
 
   value = value_cast (fmt_type, value);
 
   /* Convert the value to a string and print it.  */
   std::string str
-    = target_float_to_string (value_contents (value), fmt_type, format);
+    = target_float_to_string (value_contents (value).data (), fmt_type, format);
   fputs_filtered (str.c_str (), stream);
 }
 
@@ -2767,7 +2789,7 @@ ui_printf (const char *arg, struct ui_file *stream)
                  || valtype->code () != TYPE_CODE_INT)
                error (_("expected wchar_t argument for %%lc"));
 
-             bytes = value_contents (val_args[i]);
+             bytes = value_contents (val_args[i]).data ();
 
              auto_obstack output;
 
@@ -3304,7 +3326,8 @@ current working language.  The result is printed and saved in the value\n\
 history, if it is not void."));
   set_cmd_completer_handle_brkchars (c, print_command_completer);
 
-  add_cmd ("variable", class_vars, set_command, _("\
+  cmd_list_element *set_variable_cmd
+    = add_cmd ("variable", class_vars, set_command, _("\
 Evaluate expression EXP and assign result to variable VAR.\n\
 Usage: set variable VAR = EXP\n\
 This uses assignment syntax appropriate for the current language\n\
@@ -3313,8 +3336,8 @@ VAR may be a debugger \"convenience\" variable (names starting\n\
 with $), a register (a few standard names starting with $), or an actual\n\
 variable in the program being debugged.  EXP is any valid expression.\n\
 This may usually be abbreviated to simply \"set\"."),
-          &setlist);
-  add_alias_cmd ("var", "variable", class_vars, 0, &setlist);
+              &setlist);
+  add_alias_cmd ("var", set_variable_cmd, class_vars, 0, &setlist);
 
   const auto print_opts = make_value_print_options_def_group (nullptr);