ODR warnings for "struct coff_symbol"
[binutils-gdb.git] / gdb / linux-record.c
index bf2041996e119eef3cbf2df8da82e07279e863a1..1e8e3c955673f69fe621b0e3977a5cd3cbd87117 100644 (file)
@@ -1,6 +1,6 @@
 /* Process record and replay target code for GNU/Linux.
 
-   Copyright (C) 2008-2016 Free Software Foundation, Inc.
+   Copyright (C) 2008-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -24,6 +24,7 @@
 #include "record.h"
 #include "record-full.h"
 #include "linux-record.h"
+#include "gdbarch.h"
 
 /* These macros are the values of the first argument of system call
    "sys_ptrace".  The values of these macros were obtained from Linux
@@ -83,7 +84,7 @@
 #define RECORD_Q_XGETQUOTA     (('3' << 8) + 3)
 
 #define OUTPUT_REG(val, num)      phex_nz ((val), \
-    TYPE_LENGTH (gdbarch_register_type (get_regcache_arch (regcache), (num))))
+    TYPE_LENGTH (gdbarch_register_type (regcache->arch (), (num))))
 
 /* Record a memory area of length LEN pointed to by register
    REGNUM.  */
@@ -104,7 +105,7 @@ record_linux_sockaddr (struct regcache *regcache,
 {
   gdb_byte *a;
   int addrlen;
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   if (!addr)
@@ -119,11 +120,11 @@ record_linux_sockaddr (struct regcache *regcache,
   if (target_read_memory ((CORE_ADDR) len, a, tdep->size_int))
     {
       if (record_debug)
-       fprintf_unfiltered (gdb_stdlog,
-                           "Process record: error reading "
-                           "memory at addr = 0x%s len = %d.\n",
-                           phex_nz (len, tdep->size_pointer),
-                           tdep->size_int);
+       gdb_printf (gdb_stdlog,
+                   "Process record: error reading "
+                   "memory at addr = 0x%s len = %d.\n",
+                   phex_nz (len, tdep->size_pointer),
+                   tdep->size_int);
       return -1;
     }
   addrlen = (int) extract_unsigned_integer (a, tdep->size_int, byte_order);
@@ -141,7 +142,7 @@ record_linux_msghdr (struct regcache *regcache,
                     struct linux_record_tdep *tdep, ULONGEST addr)
 {
   gdb_byte *a;
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR tmpaddr;
   int tmpint;
@@ -156,12 +157,12 @@ record_linux_msghdr (struct regcache *regcache,
   if (target_read_memory ((CORE_ADDR) addr, a, tdep->size_msghdr))
     {
       if (record_debug)
-       fprintf_unfiltered (gdb_stdlog,
-                           "Process record: error reading "
-                           "memory at addr = 0x%s "
-                           "len = %d.\n",
-                           phex_nz (addr, tdep->size_pointer),
-                           tdep->size_msghdr);
+       gdb_printf (gdb_stdlog,
+                   "Process record: error reading "
+                   "memory at addr = 0x%s "
+                   "len = %d.\n",
+                   phex_nz (addr, tdep->size_pointer),
+                   tdep->size_msghdr);
       return -1;
     }
 
@@ -193,13 +194,13 @@ record_linux_msghdr (struct regcache *regcache,
          if (target_read_memory ((CORE_ADDR) addr, iov, tdep->size_iovec))
            {
              if (record_debug)
-               fprintf_unfiltered (gdb_stdlog,
-                                   "Process record: error "
-                                   "reading memory at "
-                                   "addr = 0x%s "
-                                   "len = %d.\n",
-                                   phex_nz (addr,tdep->size_pointer),
-                                   tdep->size_iovec);
+               gdb_printf (gdb_stdlog,
+                           "Process record: error "
+                           "reading memory at "
+                           "addr = 0x%s "
+                           "len = %d.\n",
+                           phex_nz (addr,tdep->size_pointer),
+                           tdep->size_iovec);
              return -1;
            }
          tmpaddr = (CORE_ADDR) extract_unsigned_integer (iov,
@@ -242,7 +243,7 @@ record_linux_system_call (enum gdb_syscall syscall,
                          struct regcache *regcache,
                          struct linux_record_tdep *tdep)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST tmpulongest;
   CORE_ADDR tmpaddr;
@@ -254,23 +255,18 @@ record_linux_system_call (enum gdb_syscall syscall,
       break;
 
     case gdb_sys_exit:
-      {
-       int q;
-
-       target_terminal_ours ();
-       q = yquery (_("The next instruction is syscall exit.  "
-                     "It will make the program exit.  "
-                     "Do you want to stop the program?"));
-       target_terminal_inferior ();
-       if (q)
-         return 1;
-      }
+      if (yquery (_("The next instruction is syscall exit.  "
+                   "It will make the program exit.  "
+                   "Do you want to stop the program?")))
+       return 1;
       break;
 
     case gdb_sys_fork:
       break;
 
     case gdb_sys_read:
+    case gdb_sys_readlink:
+    case gdb_sys_recv:
       regcache_raw_read_unsigned (regcache, tdep->arg3, &tmpulongest);
       if (record_mem_at_reg (regcache, tdep->arg2, (int) tmpulongest))
        return -1;
@@ -355,6 +351,7 @@ record_linux_system_call (enum gdb_syscall syscall,
       break;
 
     case gdb_sys_pipe:
+    case gdb_sys_pipe2:
       if (record_mem_at_reg (regcache, tdep->arg1, tdep->size_int * 2))
        return -1;
       break;
@@ -495,15 +492,17 @@ record_linux_system_call (enum gdb_syscall syscall,
        }
       else if (tmpulongest == tdep->ioctl_TIOCSERGSTRUCT)
        {
-         printf_unfiltered (_("Process record and replay target doesn't "
-                              "support ioctl request TIOCSERGSTRUCT\n"));
+         gdb_printf (gdb_stderr,
+                     _("Process record and replay target doesn't "
+                       "support ioctl request TIOCSERGSTRUCT\n"));
          return 1;
        }
       else
        {
-         printf_unfiltered (_("Process record and replay target doesn't "
-                              "support ioctl request 0x%s.\n"),
-                            OUTPUT_REG (tmpulongest, tdep->arg2));
+         gdb_printf (gdb_stderr,
+                     _("Process record and replay target doesn't "
+                       "support ioctl request 0x%s.\n"),
+                     OUTPUT_REG (tmpulongest, tdep->arg2));
          return 1;
        }
       break;
@@ -617,11 +616,11 @@ record_linux_system_call (enum gdb_syscall syscall,
            if (target_read_memory (tmpulongest, a, sz_sel_arg))
              {
                if (record_debug)
-                 fprintf_unfiltered (gdb_stdlog,
-                                     "Process record: error reading memory "
-                                     "at addr = 0x%s len = %lu.\n",
-                                     OUTPUT_REG (tmpulongest, tdep->arg1),
-                                     sz_sel_arg);
+                 gdb_printf (gdb_stdlog,
+                             "Process record: error reading memory "
+                             "at addr = 0x%s len = %lu.\n",
+                             OUTPUT_REG (tmpulongest, tdep->arg1),
+                             sz_sel_arg);
                return -1;
              }
            /* Skip n. */
@@ -652,28 +651,15 @@ record_linux_system_call (enum gdb_syscall syscall,
     case gdb_sys_symlink:
       break;
 
-    case gdb_sys_readlink:
-      regcache_raw_read_unsigned (regcache, tdep->arg3, &tmpulongest);
-      if (record_mem_at_reg (regcache, tdep->arg2, (int) tmpulongest))
-       return -1;
-      break;
-
     case gdb_sys_uselib:
     case gdb_sys_swapon:
       break;
 
     case gdb_sys_reboot:
-      {
-       int q;
-
-       target_terminal_ours ();
-       q = yquery (_("The next instruction is syscall reboot.  "
-                     "It will restart the computer.  "
-                     "Do you want to stop the program?"));
-       target_terminal_inferior ();
-       if (q)
-         return 1;
-      }
+      if (yquery (_("The next instruction is syscall reboot.  "
+                   "It will restart the computer.  "
+                   "Do you want to stop the program?")))
+       return 1;
       break;
 
     case gdb_old_readdir:
@@ -693,17 +679,12 @@ record_linux_system_call (enum gdb_syscall syscall,
        regcache_raw_read_unsigned (regcache, tdep->arg2, &len);
        if (record_full_memory_query)
          {
-           int q;
-
-           target_terminal_ours ();
-           q = yquery (_("\
+           if (yquery (_("\
 The next instruction is syscall munmap.\n\
 It will free the memory addr = 0x%s len = %u.\n\
 It will make record target cannot record some memory change.\n\
 Do you want to stop the program?"),
-                       OUTPUT_REG (tmpulongest, tdep->arg1), (int) len);
-           target_terminal_inferior ();
-           if (q)
+                       OUTPUT_REG (tmpulongest, tdep->arg1), (int) len))
              return 1;
          }
       }
@@ -761,12 +742,6 @@ Do you want to stop the program?"),
       }
       break;
 
-    case gdb_sys_recv:
-      regcache_raw_read_unsigned (regcache, tdep->arg3, &tmpulongest);
-      if (record_mem_at_reg (regcache, tdep->arg2, (int) tmpulongest))
-       return -1;
-      break;
-
     case gdb_sys_recvmsg:
       regcache_raw_read_unsigned (regcache, tdep->arg2, &tmpulongest);
       if (record_linux_msghdr (regcache, tdep, tmpulongest))
@@ -789,12 +764,12 @@ Do you want to stop the program?"),
                                  tdep->size_int))
            {
              if (record_debug)
-               fprintf_unfiltered (gdb_stdlog,
-                                   "Process record: error reading "
-                                   "memory at addr = 0x%s "
-                                   "len = %d.\n",
-                                   OUTPUT_REG (tmpulongest, tdep->arg5),
-                                   tdep->size_int);
+               gdb_printf (gdb_stdlog,
+                           "Process record: error reading "
+                           "memory at addr = 0x%s "
+                           "len = %d.\n",
+                           OUTPUT_REG (tmpulongest, tdep->arg5),
+                           tdep->size_int);
              return -1;
            }
          regcache_raw_read_unsigned (regcache, tdep->arg4, &optvalp);
@@ -833,11 +808,11 @@ Do you want to stop the program?"),
                                        tdep->size_ulong * 2))
                  {
                    if (record_debug)
-                     fprintf_unfiltered (gdb_stdlog,
-                                         "Process record: error reading "
-                                         "memory at addr = 0x%s len = %d.\n",
-                                         OUTPUT_REG (tmpulongest, tdep->arg2),
-                                         tdep->size_ulong * 2);
+                     gdb_printf (gdb_stdlog,
+                                 "Process record: error reading "
+                                 "memory at addr = 0x%s len = %d.\n",
+                                 OUTPUT_REG (tmpulongest, tdep->arg2),
+                                 tdep->size_ulong * 2);
                    return -1;
                  }
                tmpulongest = extract_unsigned_integer (a,
@@ -864,11 +839,11 @@ Do you want to stop the program?"),
                                        tdep->size_ulong))
                  {
                    if (record_debug)
-                     fprintf_unfiltered (gdb_stdlog,
-                                         "Process record: error reading "
-                                         "memory at addr = 0x%s len = %d.\n",
-                                         OUTPUT_REG (tmpulongest, tdep->arg2),
-                                         tdep->size_ulong);
+                     gdb_printf (gdb_stdlog,
+                                 "Process record: error reading "
+                                 "memory at addr = 0x%s len = %d.\n",
+                                 OUTPUT_REG (tmpulongest, tdep->arg2),
+                                 tdep->size_ulong);
                    return -1;
                  }
                tmpaddr
@@ -895,11 +870,11 @@ Do you want to stop the program?"),
                                      tdep->size_ulong * 2))
                {
                  if (record_debug)
-                   fprintf_unfiltered (gdb_stdlog,
-                                       "Process record: error reading "
-                                       "memory at addr = 0x%s len = %d.\n",
-                                       OUTPUT_REG (tmpulongest, tdep->arg2),
-                                       tdep->size_ulong * 2);
+                   gdb_printf (gdb_stdlog,
+                               "Process record: error reading "
+                               "memory at addr = 0x%s len = %d.\n",
+                               OUTPUT_REG (tmpulongest, tdep->arg2),
+                               tdep->size_ulong * 2);
                  return -1;
                }
              tmpulongest = extract_unsigned_integer (a, tdep->size_ulong,
@@ -909,6 +884,7 @@ Do you want to stop the program?"),
              if (record_linux_sockaddr (regcache, tdep, tmpulongest, len))
                return -1;
            }
+         break;
        case RECORD_SYS_RECV:
          regcache_raw_read_unsigned (regcache, tdep->arg2,
                                      &tmpulongest);
@@ -921,11 +897,11 @@ Do you want to stop the program?"),
                                      tdep->size_ulong))
                {
                  if (record_debug)
-                   fprintf_unfiltered (gdb_stdlog,
-                                       "Process record: error reading "
-                                       "memory at addr = 0x%s len = %d.\n",
-                                       OUTPUT_REG (tmpulongest, tdep->arg2),
-                                       tdep->size_ulong);
+                   gdb_printf (gdb_stdlog,
+                               "Process record: error reading "
+                               "memory at addr = 0x%s len = %d.\n",
+                               OUTPUT_REG (tmpulongest, tdep->arg2),
+                               tdep->size_ulong);
                  return -1;
                }
              tmpulongest = extract_unsigned_integer (a, tdep->size_ulong,
@@ -958,11 +934,11 @@ Do you want to stop the program?"),
                                        tdep->size_ulong * 2))
                  {
                    if (record_debug)
-                     fprintf_unfiltered (gdb_stdlog,
-                                         "Process record: error reading "
-                                         "memory at addr = 0x%s len = %d.\n",
-                                         OUTPUT_REG (tmpulongest, tdep->arg2),
-                                         tdep->size_ulong * 2);
+                     gdb_printf (gdb_stdlog,
+                                 "Process record: error reading "
+                                 "memory at addr = 0x%s len = %d.\n",
+                                 OUTPUT_REG (tmpulongest, tdep->arg2),
+                                 tdep->size_ulong * 2);
                    return -1;
                  }
                tmpulongest = extract_unsigned_integer (a + tdep->size_ulong,
@@ -974,13 +950,13 @@ Do you want to stop the program?"),
                                            tdep->size_int))
                      {
                        if (record_debug)
-                         fprintf_unfiltered (gdb_stdlog,
-                                             "Process record: error reading "
-                                             "memory at addr = 0x%s "
-                                             "len = %d.\n",
-                                             phex_nz (tmpulongest,
-                                                      tdep->size_ulong),
-                                             tdep->size_int);
+                         gdb_printf (gdb_stdlog,
+                                     "Process record: error reading "
+                                     "memory at addr = 0x%s "
+                                     "len = %d.\n",
+                                     phex_nz (tmpulongest,
+                                              tdep->size_ulong),
+                                     tdep->size_int);
                        return -1;
                      }
                    tmpaddr
@@ -1019,11 +995,11 @@ Do you want to stop the program?"),
                                        tdep->size_ulong))
                  {
                    if (record_debug)
-                     fprintf_unfiltered (gdb_stdlog,
-                                         "Process record: error reading "
-                                         "memory at addr = 0x%s len = %d.\n",
-                                         OUTPUT_REG (tmpulongest, tdep->arg2),
-                                         tdep->size_ulong);
+                     gdb_printf (gdb_stdlog,
+                                 "Process record: error reading "
+                                 "memory at addr = 0x%s len = %d.\n",
+                                 OUTPUT_REG (tmpulongest, tdep->arg2),
+                                 tdep->size_ulong);
                    return -1;
                  }
                tmpulongest = extract_unsigned_integer (a, tdep->size_ulong,
@@ -1034,9 +1010,10 @@ Do you want to stop the program?"),
          }
          break;
        default:
-         printf_unfiltered (_("Process record and replay target "
-                              "doesn't support socketcall call 0x%s\n"),
-                            OUTPUT_REG (tmpulongest, tdep->arg1));
+         gdb_printf (gdb_stderr,
+                     _("Process record and replay target "
+                       "doesn't support socketcall call 0x%s\n"),
+                     OUTPUT_REG (tmpulongest, tdep->arg1));
          return -1;
          break;
        }
@@ -1069,6 +1046,12 @@ Do you want to stop the program?"),
        return -1;
       break;
 
+    case gdb_sys_statx:
+      regcache_raw_read_unsigned (regcache, tdep->arg5, &tmpulongest);
+      if (record_full_arch_list_add_mem ((CORE_ADDR) tmpulongest, 256))
+       return -1;
+      break;
+
     case gdb_sys_uname:
       if (record_mem_at_reg (regcache, tdep->arg1,
                             tdep->size_old_utsname))
@@ -1174,9 +1157,10 @@ Do you want to stop the program?"),
          break;
        default:
          /* XXX RECORD_SEMCTL still not supported.  */
-         printf_unfiltered (_("Process record and replay target doesn't "
-                              "support ipc number %s\n"),
-                            pulongest (tmpulongest));
+         gdb_printf (gdb_stderr,
+                     _("Process record and replay target doesn't "
+                       "support ipc number %s\n"),
+                     pulongest (tmpulongest));
          break;
        }
       break;
@@ -1314,11 +1298,11 @@ Do you want to stop the program?"),
                                        tdep->size_iovec))
                  {
                    if (record_debug)
-                     fprintf_unfiltered (gdb_stdlog,
-                                         "Process record: error reading "
-                                         "memory at addr = 0x%s len = %d.\n",
-                                         OUTPUT_REG (vec, tdep->arg2),
-                                         tdep->size_iovec);
+                     gdb_printf (gdb_stdlog,
+                                 "Process record: error reading "
+                                 "memory at addr = 0x%s len = %d.\n",
+                                 OUTPUT_REG (vec, tdep->arg2),
+                                 tdep->size_iovec);
                    return -1;
                  }
                tmpaddr
@@ -1734,11 +1718,11 @@ Do you want to stop the program?"),
                                  nr * tdep->size_pointer))
            {
              if (record_debug)
-               fprintf_unfiltered (gdb_stdlog,
-                                   "Process record: error reading memory "
-                                   "at addr = 0x%s len = %u.\n",
-                                   OUTPUT_REG (tmpulongest, tdep->arg2),
-                                   (int) (nr * tdep->size_pointer));
+               gdb_printf (gdb_stdlog,
+                           "Process record: error reading memory "
+                           "at addr = 0x%s len = %u.\n",
+                           OUTPUT_REG (tmpulongest, tdep->arg2),
+                           (int) (nr * tdep->size_pointer));
              return -1;
            }
          for (i = 0; i < nr; i++)
@@ -1764,17 +1748,10 @@ Do you want to stop the program?"),
       break;
 
     case gdb_sys_exit_group:
-      {
-       int q;
-
-       target_terminal_ours ();
-       q = yquery (_("The next instruction is syscall exit_group.  "
-                     "It will make the program exit.  "
-                     "Do you want to stop the program?"));
-       target_terminal_inferior ();
-       if (q)
-         return 1;
-      }
+      if (yquery (_("The next instruction is syscall exit_group.  "
+                   "It will make the program exit.  "
+                   "Do you want to stop the program?")))
+       return 1;
       break;
 
     case gdb_sys_lookup_dcookie:
@@ -2061,17 +2038,13 @@ Do you want to stop the program?"),
     case gdb_sys_dup3:
       break;
 
-    case gdb_sys_pipe2:
-      if (record_mem_at_reg (regcache, tdep->arg1, tdep->size_int * 2))
-       return -1;
-      break;
-
     case gdb_sys_inotify_init1:
       break;
 
     default:
-      printf_unfiltered (_("Process record and replay target doesn't "
-                          "support syscall number %d\n"), syscall);
+      gdb_printf (gdb_stderr,
+                 _("Process record and replay target doesn't "
+                   "support syscall number %d\n"), syscall);
       return -1;
       break;
     }