Add symbol::matches method
[binutils-gdb.git] / gdb / fbsd-tdep.c
index f2f961b5486ac790b5778f20fe42bd31be4e6a2d..dc5020d92d20bd77c610c23796b934aba13dde02 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for FreeBSD, architecture-independent.
 
-   Copyright (C) 2002-2022 Free Software Foundation, Inc.
+   Copyright (C) 2002-2023 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -484,24 +484,21 @@ const struct kinfo_proc_layout kinfo_proc_layout_64 =
     .ru_majflt = 0x48,
   };
 
-static struct gdbarch_data *fbsd_gdbarch_data_handle;
-
 struct fbsd_gdbarch_data
   {
-    struct type *siginfo_type;
+    struct type *siginfo_type = nullptr;
   };
 
-static void *
-init_fbsd_gdbarch_data (struct gdbarch *gdbarch)
-{
-  return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct fbsd_gdbarch_data);
-}
+static const registry<gdbarch>::key<fbsd_gdbarch_data>
+     fbsd_gdbarch_data_handle;
 
 static struct fbsd_gdbarch_data *
 get_fbsd_gdbarch_data (struct gdbarch *gdbarch)
 {
-  return ((struct fbsd_gdbarch_data *)
-         gdbarch_data (gdbarch, fbsd_gdbarch_data_handle));
+  struct fbsd_gdbarch_data *result = fbsd_gdbarch_data_handle.get (gdbarch);
+  if (result == nullptr)
+    result = fbsd_gdbarch_data_handle.emplace (gdbarch);
+  return result;
 }
 
 struct fbsd_pspace_data
@@ -666,7 +663,7 @@ fbsd_make_note_desc (enum target_object object, uint32_t structsize)
 
   gdb::byte_vector desc (sizeof (structsize) + buf->size ());
   memcpy (desc.data (), &structsize, sizeof (structsize));
-  memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
+  std::copy (buf->begin (), buf->end (), desc.data () + sizeof (structsize));
   return desc;
 }
 
@@ -1574,6 +1571,8 @@ fbsd_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file,
       TAG (PS_STRINGS, _("Pointer to ps_strings"), AUXV_FORMAT_HEX);
       TAG (FXRNG, _("Pointer to root RNG seed version"), AUXV_FORMAT_HEX);
       TAG (KPRELOAD, _("Base address of vDSO"), AUXV_FORMAT_HEX);
+      TAG (USRSTACKBASE, _("Top of user stack"), AUXV_FORMAT_HEX);
+      TAG (USRSTACKLIM, _("Grow limit of user stack"), AUXV_FORMAT_HEX);
     }
 
   fprint_auxv_entry (file, name, description, format, type, val);
@@ -1595,11 +1594,12 @@ fbsd_get_siginfo_type (struct gdbarch *gdbarch)
   if (fbsd_gdbarch_data->siginfo_type != NULL)
     return fbsd_gdbarch_data->siginfo_type;
 
-  int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+  type_allocator alloc (gdbarch);
+  int_type = init_integer_type (alloc, gdbarch_int_bit (gdbarch),
                                0, "int");
-  int32_type = arch_integer_type (gdbarch, 32, 0, "int32_t");
-  uint32_type = arch_integer_type (gdbarch, 32, 1, "uint32_t");
-  long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
+  int32_type = init_integer_type (alloc, 32, 0, "int32_t");
+  uint32_type = init_integer_type (alloc, 32, 1, "uint32_t");
+  long_type = init_integer_type (alloc, gdbarch_long_bit (gdbarch),
                                 0, "long");
   void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
 
@@ -1610,16 +1610,17 @@ fbsd_get_siginfo_type (struct gdbarch *gdbarch)
   append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
 
   /* __pid_t */
-  pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-                       TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
-  TYPE_TARGET_TYPE (pid_type) = int32_type;
+  pid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
+                            int32_type->length () * TARGET_CHAR_BIT,
+                            "__pid_t");
+  pid_type->set_target_type (int32_type);
   pid_type->set_target_is_stub (true);
 
   /* __uid_t */
-  uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-                       TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
-                       "__uid_t");
-  TYPE_TARGET_TYPE (uid_type) = uint32_type;
+  uid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
+                            uint32_type->length () * TARGET_CHAR_BIT,
+                            "__uid_t");
+  uid_type->set_target_type (uint32_type);
   pid_type->set_target_is_stub (true);
 
   /* _reason */
@@ -1926,7 +1927,7 @@ fbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
      However, system call catching requires this function to be
      set.  */
 
-  internal_error (__FILE__, __LINE__, _("fbsd_get_sycall_number called"));
+  internal_error (_("fbsd_get_sycall_number called"));
 }
 
 /* Read an integer symbol value from the current target.  */
@@ -2033,7 +2034,7 @@ fbsd_get_thread_local_address (struct gdbarch *gdbarch, CORE_ADDR dtv_addr,
   CORE_ADDR addr = gdbarch_pointer_to_address (gdbarch,
                                               builtin->builtin_data_ptr, buf);
 
-  addr += (tls_index + 1) * TYPE_LENGTH (builtin->builtin_data_ptr);
+  addr += (tls_index + 1) * builtin->builtin_data_ptr->length ();
   if (target_read_memory (addr, buf, sizeof buf) != 0)
     throw_error (TLS_GENERIC_ERROR,
                 _("Cannot find thread-local variables on this target"));
@@ -2309,9 +2310,7 @@ fbsd_vmmap_length (struct gdbarch *gdbarch, unsigned char *entries, size_t len,
 static bool
 fbsd_vdso_range (struct gdbarch *gdbarch, struct mem_range *range)
 {
-  struct target_ops *ops = current_inferior ()->top_target ();
-
-  if (target_auxv_search (ops, AT_FREEBSD_KPRELOAD, &range->start) <= 0)
+  if (target_auxv_search (AT_FREEBSD_KPRELOAD, &range->start) <= 0)
     return false;
 
   if (!target_has_execution ())
@@ -2338,7 +2337,8 @@ fbsd_vdso_range (struct gdbarch *gdbarch, struct mem_range *range)
     {
       /* Fetch the list of address space entries from the running target. */
       gdb::optional<gdb::byte_vector> buf =
-       target_read_alloc (ops, TARGET_OBJECT_FREEBSD_VMMAP, nullptr);
+       target_read_alloc (current_inferior ()->top_target (),
+                          TARGET_OBJECT_FREEBSD_VMMAP, nullptr);
       if (!buf || buf->empty ())
        return false;
 
@@ -2392,11 +2392,3 @@ fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_xml_syscall_file_name (gdbarch, "syscalls/freebsd.xml");
   set_gdbarch_get_syscall_number (gdbarch, fbsd_get_syscall_number);
 }
-
-void _initialize_fbsd_tdep ();
-void
-_initialize_fbsd_tdep ()
-{
-  fbsd_gdbarch_data_handle =
-    gdbarch_data_register_post_init (init_fbsd_gdbarch_data);
-}