[v2,3/4] gdb: LoongArch: Add system call support for process record/replay

Message ID 20241122090624.2355-4-lihui@loongson.cn
State New
Headers
Series gdb: LoongArch: Add process record/replay and reverse debugging support |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Hui Li Nov. 22, 2024, 9:06 a.m. UTC
  The process record and replay function also need record Linux
system call instruction. This patch adds LoongArch system call
number definitions in gdb/arch/loongarch-syscall.h, and adds
loongarch_linux_syscall_record() in gdb/loongarch-linux-tdep.c
to record system call execute log. With this patch, the main
functions of process record/replay and reverse debugging are
implemented.

The LoongArch system call numbers definitions are obtained from Linux kernel.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/include/asm/unistd.h

Signed-off-by: Hui Li <lihui@loongson.cn>
Approved-By: Guinevere Larsen <guinevere@redhat.com> (record-full)
---
 gdb/arch/loongarch-syscall.h | 348 +++++++++++++++++++++
 gdb/loongarch-linux-tdep.c   | 567 +++++++++++++++++++++++++++++++++++
 gdb/loongarch-tdep.c         |  18 ++
 gdb/loongarch-tdep.h         |   4 +
 4 files changed, 937 insertions(+)
 create mode 100644 gdb/arch/loongarch-syscall.h
  

Patch

diff --git a/gdb/arch/loongarch-syscall.h b/gdb/arch/loongarch-syscall.h
new file mode 100644
index 00000000000..d4b00e4848d
--- /dev/null
+++ b/gdb/arch/loongarch-syscall.h
@@ -0,0 +1,348 @@ 
+/* Target-dependent code for LoongArch
+
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* The syscall number definitions are obtained from Linux kernel header file.
+   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h
+   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/include/asm/unistd.h  */
+
+#ifndef ARCH_LOONGARCH_SYSCALL_H
+#define ARCH_LOONGARCH_SYSCALL_H
+
+enum loongarch_syscall
+{
+  loongarch_sys_io_setup = 0,
+  loongarch_sys_io_destroy = 1,
+  loongarch_sys_io_submit = 2,
+  loongarch_sys_io_cancel = 3,
+  loongarch_sys_io_getevents = 4,
+  loongarch_sys_setxattr = 5,
+  loongarch_sys_lsetxattr = 6,
+  loongarch_sys_fsetxattr = 7,
+  loongarch_sys_getxattr = 8,
+  loongarch_sys_lgetxattr = 9,
+  loongarch_sys_fgetxattr = 10,
+  loongarch_sys_listxattr = 11,
+  loongarch_sys_llistxattr = 12,
+  loongarch_sys_flistxattr = 13,
+  loongarch_sys_removexattr = 14,
+  loongarch_sys_lremovexattr = 15,
+  loongarch_sys_fremovexattr = 16,
+  loongarch_sys_getcwd = 17,
+  loongarch_sys_lookup_dcookie = 18,
+  loongarch_sys_eventfd2 = 19,
+  loongarch_sys_epoll_create1 = 20,
+  loongarch_sys_epoll_ctl = 21,
+  loongarch_sys_epoll_pwait = 22,
+  loongarch_sys_dup = 23,
+  loongarch_sys_dup3 = 24,
+  loongarch_sys_fcntl = 25,
+  loongarch_sys_inotify_init1 = 26,
+  loongarch_sys_inotify_add_watch = 27,
+  loongarch_sys_inotify_rm_watch = 28,
+  loongarch_sys_ioctl = 29,
+  loongarch_sys_ioprio_set = 30,
+  loongarch_sys_ioprio_get = 31,
+  loongarch_sys_flock = 32,
+  loongarch_sys_mknodat = 33,
+  loongarch_sys_mkdirat = 34,
+  loongarch_sys_unlinkat = 35,
+  loongarch_sys_symlinkat = 36,
+  loongarch_sys_linkat = 37,
+
+  loongarch_sys_umount2 = 39,
+  loongarch_sys_mount = 40,
+  loongarch_sys_pivot_root = 41,
+  loongarch_sys_nfsservctl = 42,
+  loongarch_sys_statfs = 43,
+  loongarch_sys_fstatfs = 44,
+  loongarch_sys_truncate = 45,
+  loongarch_sys_ftruncate = 46,
+  loongarch_sys_fallocate = 47,
+  loongarch_sys_faccessat = 48,
+  loongarch_sys_chdir = 49,
+  loongarch_sys_fchdir = 50,
+  loongarch_sys_chroot = 51,
+  loongarch_sys_fchmod = 52,
+  loongarch_sys_fchmodat = 53,
+  loongarch_sys_fchownat = 54,
+  loongarch_sys_fchown = 55,
+  loongarch_sys_openat = 56,
+  loongarch_sys_close = 57,
+  loongarch_sys_vhangup = 58,
+  loongarch_sys_pipe2 = 59,
+  loongarch_sys_quotactl = 60,
+  loongarch_sys_getdents64 = 61,
+  loongarch_sys_lseek = 62,
+  loongarch_sys_read = 63,
+  loongarch_sys_write = 64,
+  loongarch_sys_readv = 65,
+  loongarch_sys_writev = 66,
+  loongarch_sys_pread64 = 67,
+  loongarch_sys_pwrite64 = 68,
+  loongarch_sys_preadv = 69,
+  loongarch_sys_pwritev = 70,
+  loongarch_sys_sendfile = 71,
+  loongarch_sys_pselect6 = 72,
+  loongarch_sys_ppoll = 73,
+  loongarch_sys_signalfd4 = 74,
+  loongarch_sys_vmsplice = 75,
+  loongarch_sys_splice = 76,
+  loongarch_sys_tee = 77,
+  loongarch_sys_readlinkat = 78,
+  loongarch_sys_newfstatat = 79,
+  loongarch_sys_fstat = 80,
+  loongarch_sys_sync = 81,
+  loongarch_sys_fsync = 82,
+  loongarch_sys_fdatasync = 83,
+  loongarch_sys_sync_file_range = 84,
+  loongarch_sys_timerfd_create = 85,
+  loongarch_sys_timerfd_settime = 86,
+  loongarch_sys_timerfd_gettime = 87,
+  loongarch_sys_utimensat = 88,
+  loongarch_sys_acct = 89,
+  loongarch_sys_capget = 90,
+  loongarch_sys_capset = 91,
+  loongarch_sys_personality = 92,
+  loongarch_sys_exit = 93,
+  loongarch_sys_exit_group = 94,
+  loongarch_sys_waitid = 95,
+  loongarch_sys_set_tid_address = 96,
+  loongarch_sys_unshare = 97,
+  loongarch_sys_futex = 98,
+  loongarch_sys_set_robust_list = 99,
+  loongarch_sys_get_robust_list = 100,
+  loongarch_sys_nanosleep = 101,
+  loongarch_sys_getitimer = 102,
+  loongarch_sys_setitimer = 103,
+  loongarch_sys_kexec_load = 104,
+  loongarch_sys_init_module = 105,
+  loongarch_sys_delete_module = 106,
+  loongarch_sys_timer_create = 107,
+  loongarch_sys_timer_gettime = 108,
+  loongarch_sys_timer_getoverrun = 109,
+  loongarch_sys_timer_settime = 110,
+  loongarch_sys_timer_delete = 111,
+  loongarch_sys_clock_settime = 112,
+  loongarch_sys_clock_gettime = 113,
+  loongarch_sys_clock_getres = 114,
+  loongarch_sys_clock_nanosleep = 115,
+  loongarch_sys_syslog = 116,
+  loongarch_sys_ptrace = 117,
+  loongarch_sys_sched_setparam = 118,
+  loongarch_sys_sched_setscheduler = 119,
+  loongarch_sys_sched_getscheduler = 120,
+  loongarch_sys_sched_getparam = 121,
+  loongarch_sys_sched_setaffinity = 122,
+  loongarch_sys_sched_getaffinity = 123,
+  loongarch_sys_sched_yield = 124,
+  loongarch_sys_sched_get_priority_max = 125,
+  loongarch_sys_sched_get_priority_min = 126,
+  loongarch_sys_sched_rr_get_interval = 127,
+  loongarch_sys_restart_syscall = 128,
+  loongarch_sys_kill = 129,
+  loongarch_sys_tkill = 130,
+  loongarch_sys_tgkill = 131,
+  loongarch_sys_sigaltstack = 132,
+  loongarch_sys_rt_sigsuspend = 133,
+  loongarch_sys_rt_sigaction = 134,
+  loongarch_sys_rt_sigprocmask = 135,
+  loongarch_sys_rt_sigpending = 136,
+  loongarch_sys_rt_sigtimedwait = 137,
+  loongarch_sys_rt_sigqueueinfo = 138,
+  loongarch_sys_rt_sigreturn = 139,
+  loongarch_sys_setpriority = 140,
+  loongarch_sys_getpriority = 141,
+  loongarch_sys_reboot = 142,
+  loongarch_sys_setregid = 143,
+  loongarch_sys_setgid = 144,
+  loongarch_sys_setreuid = 145,
+  loongarch_sys_setuid = 146,
+  loongarch_sys_setresuid = 147,
+  loongarch_sys_getresuid = 148,
+  loongarch_sys_setresgid = 149,
+  loongarch_sys_getresgid = 150,
+  loongarch_sys_setfsuid = 151,
+  loongarch_sys_setfsgid = 152,
+  loongarch_sys_times = 153,
+  loongarch_sys_setpgid = 154,
+  loongarch_sys_getpgid = 155,
+  loongarch_sys_getsid = 156,
+  loongarch_sys_setsid = 157,
+  loongarch_sys_getgroups = 158,
+  loongarch_sys_setgroups = 159,
+  loongarch_sys_uname = 160,
+  loongarch_sys_sethostname = 161,
+  loongarch_sys_setdomainname = 162,
+
+  loongarch_sys_getrusage = 165,
+  loongarch_sys_umask = 166,
+  loongarch_sys_prctl = 167,
+  loongarch_sys_getcpu = 168,
+  loongarch_sys_gettimeofday = 169,
+  loongarch_sys_settimeofday = 170,
+  loongarch_sys_adjtimex = 171,
+  loongarch_sys_getpid = 172,
+  loongarch_sys_getppid = 173,
+  loongarch_sys_getuid = 174,
+  loongarch_sys_geteuid = 175,
+  loongarch_sys_getgid = 176,
+  loongarch_sys_getegid = 177,
+  loongarch_sys_gettid = 178,
+  loongarch_sys_sysinfo = 179,
+  loongarch_sys_mq_open = 180,
+  loongarch_sys_mq_unlink = 181,
+  loongarch_sys_mq_timedsend = 182,
+  loongarch_sys_mq_timedreceive = 183,
+  loongarch_sys_mq_notify = 184,
+  loongarch_sys_mq_getsetattr = 185,
+  loongarch_sys_msgget = 186,
+  loongarch_sys_msgctl = 187,
+  loongarch_sys_msgrcv = 188,
+  loongarch_sys_msgsnd = 189,
+  loongarch_sys_semget = 190,
+  loongarch_sys_semctl = 191,
+  loongarch_sys_semtimedop = 192,
+  loongarch_sys_semop = 193,
+  loongarch_sys_shmget = 194,
+  loongarch_sys_shmctl = 195,
+  loongarch_sys_shmat = 196,
+  loongarch_sys_shmdt = 197,
+  loongarch_sys_socket = 198,
+  loongarch_sys_socketpair = 199,
+  loongarch_sys_bind = 200,
+  loongarch_sys_listen = 201,
+  loongarch_sys_accept = 202,
+  loongarch_sys_connect = 203,
+  loongarch_sys_getsockname = 204,
+  loongarch_sys_getpeername = 205,
+  loongarch_sys_sendto = 206,
+  loongarch_sys_recvfrom = 207,
+  loongarch_sys_setsockopt = 208,
+  loongarch_sys_getsockopt = 209,
+  loongarch_sys_shutdown = 210,
+  loongarch_sys_sendmsg = 211,
+  loongarch_sys_recvmsg = 212,
+  loongarch_sys_readahead = 213,
+  loongarch_sys_brk = 214,
+  loongarch_sys_munmap = 215,
+  loongarch_sys_mremap = 216,
+  loongarch_sys_add_key = 217,
+  loongarch_sys_request_key = 218,
+  loongarch_sys_keyctl = 219,
+  loongarch_sys_clone = 220,
+  loongarch_sys_execve = 221,
+  loongarch_sys_mmap = 222,
+  loongarch_sys_fadvise64 = 223,
+  loongarch_sys_swapon = 224,
+  loongarch_sys_swapoff = 225,
+  loongarch_sys_mprotect = 226,
+  loongarch_sys_msync = 227,
+  loongarch_sys_mlock = 228,
+  loongarch_sys_munlock = 229,
+  loongarch_sys_mlockall = 230,
+  loongarch_sys_munlockall = 231,
+  loongarch_sys_mincore = 232,
+  loongarch_sys_madvise = 233,
+  loongarch_sys_remap_file_pages = 234,
+  loongarch_sys_mbind = 235,
+  loongarch_sys_get_mempolicy = 236,
+  loongarch_sys_set_mempolicy = 237,
+  loongarch_sys_migrate_pages = 238,
+  loongarch_sys_move_pages = 239,
+  loongarch_sys_rt_tgsigqueueinfo = 240,
+  loongarch_sys_perf_event_open = 241,
+  loongarch_sys_accept4 = 242,
+  loongarch_sys_recvmmsg = 243,
+  loongarch_sys_wait4 = 260,
+  loongarch_sys_prlimit64 = 261,
+  loongarch_sys_fanotify_init = 262,
+  loongarch_sys_fanotify_mark = 263,
+  loongarch_sys_name_to_handle_at = 264,
+  loongarch_sys_open_by_handle_at = 265,
+  loongarch_sys_clock_adjtime = 266,
+  loongarch_sys_syncfs = 267,
+  loongarch_sys_setns = 268,
+  loongarch_sys_sendmmsg = 269,
+  loongarch_sys_process_vm_readv = 270,
+  loongarch_sys_process_vm_writev = 271,
+  loongarch_sys_kcmp = 272,
+  loongarch_sys_finit_module = 273,
+  loongarch_sys_sched_setattr = 274,
+  loongarch_sys_sched_getattr = 275,
+  loongarch_sys_renameat2 = 276,
+  loongarch_sys_seccomp = 277,
+  loongarch_sys_getrandom = 278,
+  loongarch_sys_memfd_create = 279,
+  loongarch_sys_bpf = 280,
+  loongarch_sys_execveat = 281,
+  loongarch_sys_userfaultfd = 282,
+  loongarch_sys_membarrier = 283,
+  loongarch_sys_mlock2 = 284,
+  loongarch_sys_copy_file_range = 285,
+  loongarch_sys_preadv2 = 286,
+  loongarch_sys_pwritev2 = 287,
+  loongarch_sys_pkey_mprotect = 288,
+  loongarch_sys_pkey_alloc = 289,
+  loongarch_sys_pkey_free = 290,
+  loongarch_sys_statx = 291,
+  loongarch_sys_io_pgetevents = 292,
+  loongarch_sys_rseq = 293,
+  loongarch_sys_kexec_file_load = 294,
+
+  loongarch_sys_pidfd_send_signal = 424,
+  loongarch_sys_io_uring_setup = 425,
+  loongarch_sys_io_uring_enter = 426,
+  loongarch_sys_io_uring_register = 427,
+  loongarch_sys_open_tree = 428,
+  loongarch_sys_move_mount = 429,
+  loongarch_sys_fsopen = 430,
+  loongarch_sys_fsconfig = 431,
+  loongarch_sys_fsmount = 432,
+  loongarch_sys_fspick = 433,
+  loongarch_sys_pidfd_open = 434,
+  loongarch_sys_clone3 = 435,
+  loongarch_sys_close_range = 436,
+  loongarch_sys_openat2 = 437,
+  loongarch_sys_pidfd_getfd = 438,
+  loongarch_sys_faccessat2 = 439,
+  loongarch_sys_process_madvise = 440,
+  loongarch_sys_epoll_pwait2 = 441,
+  loongarch_sys_mount_setattr = 442,
+  loongarch_sys_quotactl_fd = 443,
+  loongarch_sys_landlock_create_ruleset = 444,
+  loongarch_sys_landlock_add_rule = 445,
+  loongarch_sys_landlock_restrict_self = 446,
+
+  loongarch_sys_process_mrelease = 448,
+  loongarch_sys_futex_waitv = 449,
+  loongarch_sys_set_mempolicy_home_node = 450,
+  loongarch_sys_cachestat = 451,
+  loongarch_sys_fchmodat2 = 452,
+  loongarch_sys_map_shadow_stack = 453,
+  loongarch_sys_futex_wake = 454,
+  loongarch_sys_futex_wait = 455,
+  loongarch_sys_futex_requeue = 456,
+  loongarch_sys_statmount = 457,
+  loongarch_sys_listmount = 458,
+  loongarch_sys_lsm_get_self_attr = 459,
+  loongarch_sys_lsm_set_self_attr = 460,
+  loongarch_sys_lsm_list_modules = 461,
+  loongarch_sys_mseal = 462,
+  loongarch_sys_syscalls = 463,
+};
+
+#endif /* ARCH_LOONGARCH_SYSCALL_H */
diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index 86e7ed8a0bc..b18cacca087 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -18,15 +18,21 @@ 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "arch/loongarch-syscall.h"
 #include "extract-store-integer.h"
+#include "gdbarch.h"
 #include "glibc-tdep.h"
 #include "inferior.h"
+#include "linux-record.h"
 #include "linux-tdep.h"
 #include "loongarch-tdep.h"
+#include "record-full.h"
+#include "regset.h"
 #include "solib-svr4.h"
 #include "target-descriptions.h"
 #include "trad-frame.h"
 #include "tramp-frame.h"
+#include "value.h"
 #include "xml-syscall.h"
 
 /* The syscall's XML filename for LoongArch.  */
@@ -566,6 +572,563 @@  loongarch_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread
   return ret;
 }
 
+static linux_record_tdep loongarch_linux_record_tdep;
+
+/* loongarch_canonicalize_syscall maps syscall ids from the native LoongArch
+   linux set of syscall ids into a canonical set of syscall ids used by
+   process record. */
+
+static enum gdb_syscall
+loongarch_canonicalize_syscall (enum loongarch_syscall syscall_number)
+{
+#define SYSCALL_MAP(SYSCALL) case loongarch_sys_##SYSCALL:              \
+  return gdb_sys_##SYSCALL
+
+#define UNSUPPORTED_SYSCALL_MAP(SYSCALL) case loongarch_sys_##SYSCALL:  \
+  return gdb_sys_no_syscall
+
+  switch(syscall_number)
+    {
+      SYSCALL_MAP (io_setup);
+      SYSCALL_MAP (io_destroy);
+      SYSCALL_MAP (io_submit);
+      SYSCALL_MAP (io_cancel);
+      SYSCALL_MAP (io_getevents);
+      SYSCALL_MAP (setxattr);
+      SYSCALL_MAP (lsetxattr);
+      SYSCALL_MAP (fsetxattr);
+      SYSCALL_MAP (getxattr);
+      SYSCALL_MAP (lgetxattr);
+      SYSCALL_MAP (fgetxattr);
+      SYSCALL_MAP (listxattr);
+      SYSCALL_MAP (llistxattr);
+      SYSCALL_MAP (flistxattr);
+      SYSCALL_MAP (removexattr);
+      SYSCALL_MAP (lremovexattr);
+      SYSCALL_MAP (fremovexattr);
+      SYSCALL_MAP (getcwd);
+      SYSCALL_MAP (lookup_dcookie);
+      SYSCALL_MAP (eventfd2);
+      SYSCALL_MAP (epoll_create1);
+      SYSCALL_MAP (epoll_ctl);
+      SYSCALL_MAP (epoll_pwait);
+      SYSCALL_MAP (dup);
+      SYSCALL_MAP (dup3);
+      SYSCALL_MAP (fcntl);
+      SYSCALL_MAP (inotify_init1);
+      SYSCALL_MAP (inotify_add_watch);
+      SYSCALL_MAP (inotify_rm_watch);
+      SYSCALL_MAP (ioctl);
+      SYSCALL_MAP (ioprio_set);
+      SYSCALL_MAP (ioprio_get);
+      SYSCALL_MAP (flock);
+      SYSCALL_MAP (mknodat);
+      SYSCALL_MAP (mkdirat);
+      SYSCALL_MAP (unlinkat);
+      SYSCALL_MAP (symlinkat);
+      SYSCALL_MAP (linkat);
+      UNSUPPORTED_SYSCALL_MAP (umount2);
+      SYSCALL_MAP (mount);
+      SYSCALL_MAP (pivot_root);
+      SYSCALL_MAP (nfsservctl);
+      SYSCALL_MAP (statfs);
+      SYSCALL_MAP (truncate);
+      SYSCALL_MAP (ftruncate);
+      SYSCALL_MAP (fallocate);
+      SYSCALL_MAP (faccessat);
+      SYSCALL_MAP (fchdir);
+      SYSCALL_MAP (chroot);
+      SYSCALL_MAP (fchmod);
+      SYSCALL_MAP (fchmodat);
+      SYSCALL_MAP (fchownat);
+      SYSCALL_MAP (fchown);
+      SYSCALL_MAP (openat);
+      SYSCALL_MAP (close);
+      SYSCALL_MAP (vhangup);
+      SYSCALL_MAP (pipe2);
+      SYSCALL_MAP (quotactl);
+      SYSCALL_MAP (getdents64);
+      SYSCALL_MAP (lseek);
+      SYSCALL_MAP (read);
+      SYSCALL_MAP (write);
+      SYSCALL_MAP (readv);
+      SYSCALL_MAP (writev);
+      SYSCALL_MAP (pread64);
+      SYSCALL_MAP (pwrite64);
+      UNSUPPORTED_SYSCALL_MAP (preadv);
+      UNSUPPORTED_SYSCALL_MAP (pwritev);
+      SYSCALL_MAP (sendfile);
+      SYSCALL_MAP (pselect6);
+      SYSCALL_MAP (ppoll);
+      UNSUPPORTED_SYSCALL_MAP (signalfd4);
+      SYSCALL_MAP (vmsplice);
+      SYSCALL_MAP (splice);
+      SYSCALL_MAP (tee);
+      SYSCALL_MAP (readlinkat);
+      SYSCALL_MAP (newfstatat);
+      SYSCALL_MAP (fstat);
+      SYSCALL_MAP (sync);
+      SYSCALL_MAP (fsync);
+      SYSCALL_MAP (fdatasync);
+      SYSCALL_MAP (sync_file_range);
+      UNSUPPORTED_SYSCALL_MAP (timerfd_create);
+      UNSUPPORTED_SYSCALL_MAP (timerfd_settime);
+      UNSUPPORTED_SYSCALL_MAP (timerfd_gettime);
+      UNSUPPORTED_SYSCALL_MAP (utimensat);
+      SYSCALL_MAP (acct);
+      SYSCALL_MAP (capget);
+      SYSCALL_MAP (capset);
+      SYSCALL_MAP (personality);
+      SYSCALL_MAP (exit);
+      SYSCALL_MAP (exit_group);
+      SYSCALL_MAP (waitid);
+      SYSCALL_MAP (set_tid_address);
+      SYSCALL_MAP (unshare);
+      SYSCALL_MAP (futex);
+      SYSCALL_MAP (set_robust_list);
+      SYSCALL_MAP (get_robust_list);
+      SYSCALL_MAP (nanosleep);
+      SYSCALL_MAP (getitimer);
+      SYSCALL_MAP (setitimer);
+      SYSCALL_MAP (kexec_load);
+      SYSCALL_MAP (init_module);
+      SYSCALL_MAP (delete_module);
+      SYSCALL_MAP (timer_create);
+      SYSCALL_MAP (timer_settime);
+      SYSCALL_MAP (timer_gettime);
+      SYSCALL_MAP (timer_getoverrun);
+      SYSCALL_MAP (timer_delete);
+      SYSCALL_MAP (clock_settime);
+      SYSCALL_MAP (clock_gettime);
+      SYSCALL_MAP (clock_getres);
+      SYSCALL_MAP (clock_nanosleep);
+      SYSCALL_MAP (syslog);
+      SYSCALL_MAP (ptrace);
+      SYSCALL_MAP (sched_setparam);
+      SYSCALL_MAP (sched_setscheduler);
+      SYSCALL_MAP (sched_getscheduler);
+      SYSCALL_MAP (sched_getparam);
+      SYSCALL_MAP (sched_setaffinity);
+      SYSCALL_MAP (sched_getaffinity);
+      SYSCALL_MAP (sched_yield);
+      SYSCALL_MAP (sched_get_priority_max);
+      SYSCALL_MAP (sched_get_priority_min);
+      SYSCALL_MAP (sched_rr_get_interval);
+      SYSCALL_MAP (kill);
+      SYSCALL_MAP (tkill);
+      SYSCALL_MAP (tgkill);
+      SYSCALL_MAP (sigaltstack);
+      SYSCALL_MAP (rt_sigsuspend);
+      SYSCALL_MAP (rt_sigaction);
+      SYSCALL_MAP (rt_sigprocmask);
+      SYSCALL_MAP (rt_sigpending);
+      SYSCALL_MAP (rt_sigtimedwait);
+      SYSCALL_MAP (rt_sigqueueinfo);
+      SYSCALL_MAP (rt_sigreturn);
+      SYSCALL_MAP (setpriority);
+      SYSCALL_MAP (getpriority);
+      SYSCALL_MAP (reboot);
+      SYSCALL_MAP (setregid);
+      SYSCALL_MAP (setgid);
+      SYSCALL_MAP (setreuid);
+      SYSCALL_MAP (setuid);
+      SYSCALL_MAP (setresuid);
+      SYSCALL_MAP (getresuid);
+      SYSCALL_MAP (setresgid);
+      SYSCALL_MAP (getresgid);
+      SYSCALL_MAP (setfsuid);
+      SYSCALL_MAP (setfsgid);
+      SYSCALL_MAP (times);
+      SYSCALL_MAP (setpgid);
+      SYSCALL_MAP (getpgid);
+      SYSCALL_MAP (getsid);
+      SYSCALL_MAP (setsid);
+      SYSCALL_MAP (getgroups);
+      SYSCALL_MAP (setgroups);
+      SYSCALL_MAP (uname);
+      SYSCALL_MAP (sethostname);
+      SYSCALL_MAP (setdomainname);
+      SYSCALL_MAP (getrusage);
+      SYSCALL_MAP (umask);
+      SYSCALL_MAP (prctl);
+      SYSCALL_MAP (getcpu);
+      SYSCALL_MAP (gettimeofday);
+      SYSCALL_MAP (settimeofday);
+      SYSCALL_MAP (adjtimex);
+      SYSCALL_MAP (getpid);
+      SYSCALL_MAP (getppid);
+      SYSCALL_MAP (getuid);
+      SYSCALL_MAP (geteuid);
+      SYSCALL_MAP (getgid);
+      SYSCALL_MAP (getegid);
+      SYSCALL_MAP (gettid);
+      SYSCALL_MAP (sysinfo);
+      SYSCALL_MAP (mq_open);
+      SYSCALL_MAP (mq_unlink);
+      SYSCALL_MAP (mq_timedsend);
+      SYSCALL_MAP (mq_timedreceive);
+      SYSCALL_MAP (mq_notify);
+      SYSCALL_MAP (mq_getsetattr);
+      SYSCALL_MAP (msgget);
+      SYSCALL_MAP (msgctl);
+      SYSCALL_MAP (msgrcv);
+      SYSCALL_MAP (msgsnd);
+      SYSCALL_MAP (semget);
+      SYSCALL_MAP (semctl);
+      SYSCALL_MAP (semtimedop);
+      SYSCALL_MAP (semop);
+      SYSCALL_MAP (shmget);
+      SYSCALL_MAP (shmctl);
+      SYSCALL_MAP (shmat);
+      SYSCALL_MAP (shmdt);
+      SYSCALL_MAP (socket);
+      SYSCALL_MAP (socketpair);
+      SYSCALL_MAP (bind);
+      SYSCALL_MAP (listen);
+      SYSCALL_MAP (accept);
+      SYSCALL_MAP (connect);
+      SYSCALL_MAP (getsockname);
+      SYSCALL_MAP (getpeername);
+      SYSCALL_MAP (sendto);
+      SYSCALL_MAP (recvfrom);
+      SYSCALL_MAP (setsockopt);
+      SYSCALL_MAP (getsockopt);
+      SYSCALL_MAP (shutdown);
+      SYSCALL_MAP (sendmsg);
+      SYSCALL_MAP (recvmsg);
+      SYSCALL_MAP (readahead);
+      SYSCALL_MAP (brk);
+      SYSCALL_MAP (munmap);
+      SYSCALL_MAP (mremap);
+      SYSCALL_MAP (add_key);
+      SYSCALL_MAP (request_key);
+      SYSCALL_MAP (keyctl);
+      SYSCALL_MAP (clone);
+      SYSCALL_MAP (execve);
+
+    case loongarch_sys_mmap:
+      return gdb_sys_mmap2;
+
+      SYSCALL_MAP (fadvise64);
+      SYSCALL_MAP (swapon);
+      SYSCALL_MAP (swapoff);
+      SYSCALL_MAP (mprotect);
+      SYSCALL_MAP (msync);
+      SYSCALL_MAP (mlock);
+      SYSCALL_MAP (munlock);
+      SYSCALL_MAP (mlockall);
+      SYSCALL_MAP (munlockall);
+      SYSCALL_MAP (mincore);
+      SYSCALL_MAP (madvise);
+      SYSCALL_MAP (remap_file_pages);
+      SYSCALL_MAP (mbind);
+      SYSCALL_MAP (get_mempolicy);
+      SYSCALL_MAP (set_mempolicy);
+      SYSCALL_MAP (migrate_pages);
+      SYSCALL_MAP (move_pages);
+      UNSUPPORTED_SYSCALL_MAP (rt_tgsigqueueinfo);
+      UNSUPPORTED_SYSCALL_MAP (perf_event_open);
+      UNSUPPORTED_SYSCALL_MAP (accept4);
+      UNSUPPORTED_SYSCALL_MAP (recvmmsg);
+      SYSCALL_MAP (wait4);
+      UNSUPPORTED_SYSCALL_MAP (prlimit64);
+      UNSUPPORTED_SYSCALL_MAP (fanotify_init);
+      UNSUPPORTED_SYSCALL_MAP (fanotify_mark);
+      UNSUPPORTED_SYSCALL_MAP (name_to_handle_at);
+      UNSUPPORTED_SYSCALL_MAP (open_by_handle_at);
+      UNSUPPORTED_SYSCALL_MAP (clock_adjtime);
+      UNSUPPORTED_SYSCALL_MAP (syncfs);
+      UNSUPPORTED_SYSCALL_MAP (setns);
+      UNSUPPORTED_SYSCALL_MAP (sendmmsg);
+      UNSUPPORTED_SYSCALL_MAP (process_vm_readv);
+      UNSUPPORTED_SYSCALL_MAP (process_vm_writev);
+      UNSUPPORTED_SYSCALL_MAP (kcmp);
+      UNSUPPORTED_SYSCALL_MAP (finit_module);
+      UNSUPPORTED_SYSCALL_MAP (sched_setattr);
+      UNSUPPORTED_SYSCALL_MAP (sched_getattr);
+      UNSUPPORTED_SYSCALL_MAP (renameat2);
+      UNSUPPORTED_SYSCALL_MAP (seccomp);
+      SYSCALL_MAP (getrandom);
+      UNSUPPORTED_SYSCALL_MAP (memfd_create);
+      UNSUPPORTED_SYSCALL_MAP (bpf);
+      UNSUPPORTED_SYSCALL_MAP (execveat);
+      UNSUPPORTED_SYSCALL_MAP (userfaultfd);
+      UNSUPPORTED_SYSCALL_MAP (membarrier);
+      UNSUPPORTED_SYSCALL_MAP (mlock2);
+      UNSUPPORTED_SYSCALL_MAP (copy_file_range);
+      UNSUPPORTED_SYSCALL_MAP (preadv2);
+      UNSUPPORTED_SYSCALL_MAP (pwritev2);
+      UNSUPPORTED_SYSCALL_MAP (pkey_mprotect);
+      UNSUPPORTED_SYSCALL_MAP (pkey_alloc);
+      UNSUPPORTED_SYSCALL_MAP (pkey_free);
+      SYSCALL_MAP (statx);
+      UNSUPPORTED_SYSCALL_MAP (io_pgetevents);
+      UNSUPPORTED_SYSCALL_MAP (rseq);
+      UNSUPPORTED_SYSCALL_MAP (kexec_file_load);
+      UNSUPPORTED_SYSCALL_MAP (pidfd_send_signal);
+      UNSUPPORTED_SYSCALL_MAP (io_uring_setup);
+      UNSUPPORTED_SYSCALL_MAP (io_uring_enter);
+      UNSUPPORTED_SYSCALL_MAP (io_uring_register);
+      UNSUPPORTED_SYSCALL_MAP (open_tree);
+      UNSUPPORTED_SYSCALL_MAP (move_mount);
+      UNSUPPORTED_SYSCALL_MAP (fsopen);
+      UNSUPPORTED_SYSCALL_MAP (fsconfig);
+      UNSUPPORTED_SYSCALL_MAP (fsmount);
+      UNSUPPORTED_SYSCALL_MAP (fspick);
+      UNSUPPORTED_SYSCALL_MAP (pidfd_open);
+      UNSUPPORTED_SYSCALL_MAP (clone3);
+      UNSUPPORTED_SYSCALL_MAP (close_range);
+      UNSUPPORTED_SYSCALL_MAP (openat2);
+      UNSUPPORTED_SYSCALL_MAP (pidfd_getfd);
+      UNSUPPORTED_SYSCALL_MAP (faccessat2);
+      UNSUPPORTED_SYSCALL_MAP (process_madvise);
+      UNSUPPORTED_SYSCALL_MAP (epoll_pwait2);
+      UNSUPPORTED_SYSCALL_MAP (mount_setattr);
+      UNSUPPORTED_SYSCALL_MAP (quotactl_fd);
+      UNSUPPORTED_SYSCALL_MAP (landlock_create_ruleset);
+      UNSUPPORTED_SYSCALL_MAP (landlock_add_rule);
+      UNSUPPORTED_SYSCALL_MAP (landlock_restrict_self);
+      UNSUPPORTED_SYSCALL_MAP (process_mrelease);
+      UNSUPPORTED_SYSCALL_MAP (futex_waitv);
+      UNSUPPORTED_SYSCALL_MAP (set_mempolicy_home_node);
+      UNSUPPORTED_SYSCALL_MAP (cachestat);
+      UNSUPPORTED_SYSCALL_MAP (fchmodat2);
+      UNSUPPORTED_SYSCALL_MAP (map_shadow_stack);
+      UNSUPPORTED_SYSCALL_MAP (futex_wake);
+      UNSUPPORTED_SYSCALL_MAP (futex_wait);
+      UNSUPPORTED_SYSCALL_MAP (futex_requeue);
+      UNSUPPORTED_SYSCALL_MAP (statmount);
+      UNSUPPORTED_SYSCALL_MAP (listmount);
+      UNSUPPORTED_SYSCALL_MAP (lsm_get_self_attr);
+      UNSUPPORTED_SYSCALL_MAP (lsm_set_self_attr);
+      UNSUPPORTED_SYSCALL_MAP (lsm_list_modules);
+      UNSUPPORTED_SYSCALL_MAP (mseal);
+      UNSUPPORTED_SYSCALL_MAP (syscalls);
+    default:
+      return gdb_sys_no_syscall;
+    }
+#undef SYSCALL_MAP
+#undef UNSUPPORTED_SYSCALL_MAP
+}
+
+static int
+loongarch_record_all_but_pc_registers (struct regcache *regcache)
+{
+
+  /* Record General purpose Registers. */
+  for (int i = 0; i < 32; ++i)
+    if (record_full_arch_list_add_reg (regcache, i))
+      return -1;
+
+  /* Record orig_a0 */
+  if (record_full_arch_list_add_reg (regcache, LOONGARCH_ORIG_A0_REGNUM))
+    return -1;
+
+  /* Record badvaddr */
+  if (record_full_arch_list_add_reg (regcache, LOONGARCH_BADV_REGNUM))
+    return -1;
+
+  return 0;
+}
+
+/* Handler for LoongArch architechture system call instruction recording.  */
+
+static int
+loongarch_linux_syscall_record (struct regcache *regcache,
+				unsigned long syscall_number)
+{
+  int ret = 0;
+  enum gdb_syscall syscall_gdb;
+
+  syscall_gdb =
+    loongarch_canonicalize_syscall ((enum loongarch_syscall) syscall_number);
+
+  if (syscall_gdb < 0)
+    {
+      gdb_printf (gdb_stderr,
+		  _("Process record and replay target doesn't "
+		  "support syscall number %s\n"), plongest (syscall_number));
+      return -1;
+    }
+
+  if (syscall_gdb == gdb_sys_sigreturn || syscall_gdb == gdb_sys_rt_sigreturn)
+    return loongarch_record_all_but_pc_registers (regcache);
+
+  ret = record_linux_system_call (syscall_gdb, regcache,
+				  &loongarch_linux_record_tdep);
+
+  if (ret != 0)
+    return ret;
+
+  /* Record the return value of the system call.  */
+  if (record_full_arch_list_add_reg (regcache, LOONGARCH_A0_REGNUM))
+    return -1;
+
+  return 0;
+}
+
+/* Initialize the loongarch_linux_record_tdep. These values are the size
+   of the type that will be used in a system call. They are obtained from
+   Linux Kernel source.  */
+
+static void
+init_loongarch_linux_record_tdep (struct gdbarch *gdbarch)
+{
+  loongarch_linux_record_tdep.size_pointer
+	= gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
+  loongarch_linux_record_tdep.size_tms = 32;
+  loongarch_linux_record_tdep.size_loff_t = 8;
+  loongarch_linux_record_tdep.size_flock = 32;
+  loongarch_linux_record_tdep.size_oldold_utsname = 45;
+  loongarch_linux_record_tdep.size_ustat = 32;
+  loongarch_linux_record_tdep.size_old_sigaction = 32;
+  loongarch_linux_record_tdep.size_old_sigset_t = 8;
+  loongarch_linux_record_tdep.size_rlimit = 16;
+  loongarch_linux_record_tdep.size_rusage = 144;
+  loongarch_linux_record_tdep.size_timeval = 16;
+  loongarch_linux_record_tdep.size_timezone = 8;
+  loongarch_linux_record_tdep.size_old_gid_t = 4;
+  loongarch_linux_record_tdep.size_old_uid_t = 4;
+  loongarch_linux_record_tdep.size_fd_set = 128;
+  loongarch_linux_record_tdep.size_old_dirent = 280;
+  loongarch_linux_record_tdep.size_statfs = 120;
+  loongarch_linux_record_tdep.size_statfs64 = 120;
+  loongarch_linux_record_tdep.size_sockaddr = 16;
+  loongarch_linux_record_tdep.size_int
+	    = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
+  loongarch_linux_record_tdep.size_long
+	    = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
+  loongarch_linux_record_tdep.size_ulong
+	    = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
+  loongarch_linux_record_tdep.size_msghdr = 56;
+  loongarch_linux_record_tdep.size_itimerval = 32;
+  loongarch_linux_record_tdep.size_stat = 144;
+  loongarch_linux_record_tdep.size_old_utsname = 325;
+  loongarch_linux_record_tdep.size_sysinfo = 112;
+  loongarch_linux_record_tdep.size_msqid_ds = 120;
+  loongarch_linux_record_tdep.size_shmid_ds = 112;
+  loongarch_linux_record_tdep.size_new_utsname = 390;
+  loongarch_linux_record_tdep.size_timex = 208;
+  loongarch_linux_record_tdep.size_mem_dqinfo = 72;
+  loongarch_linux_record_tdep.size_if_dqblk = 72;
+  loongarch_linux_record_tdep.size_fs_quota_stat = 80;
+  loongarch_linux_record_tdep.size_timespec = 16;
+  loongarch_linux_record_tdep.size_pollfd = 8;
+  loongarch_linux_record_tdep.size_NFS_FHSIZE = 32;
+  loongarch_linux_record_tdep.size_knfsd_fh = 132;
+  loongarch_linux_record_tdep.size_TASK_COMM_LEN = 16;
+  loongarch_linux_record_tdep.size_sigaction = 24;
+  loongarch_linux_record_tdep.size_sigset_t = 8;
+  loongarch_linux_record_tdep.size_siginfo_t = 128;
+  loongarch_linux_record_tdep.size_cap_user_data_t = 8;
+  loongarch_linux_record_tdep.size_stack_t = 24;
+  loongarch_linux_record_tdep.size_off_t = 8;
+  loongarch_linux_record_tdep.size_stat64 = 144;
+  loongarch_linux_record_tdep.size_gid_t = 4;
+  loongarch_linux_record_tdep.size_uid_t = 4;
+  loongarch_linux_record_tdep.size_PAGE_SIZE = 0x4000;
+  loongarch_linux_record_tdep.size_flock64 = 32;
+  loongarch_linux_record_tdep.size_user_desc = 16;
+  loongarch_linux_record_tdep.size_io_event = 32;
+  loongarch_linux_record_tdep.size_iocb = 64;
+  loongarch_linux_record_tdep.size_epoll_event = 12;
+  loongarch_linux_record_tdep.size_itimerspec = 32;
+  loongarch_linux_record_tdep.size_mq_attr = 64;
+  loongarch_linux_record_tdep.size_termios = 36;
+  loongarch_linux_record_tdep.size_termios2 = 44;
+  loongarch_linux_record_tdep.size_pid_t = 4;
+  loongarch_linux_record_tdep.size_winsize = 8;
+  loongarch_linux_record_tdep.size_serial_struct = 72;
+  loongarch_linux_record_tdep.size_serial_icounter_struct = 80;
+  loongarch_linux_record_tdep.size_hayes_esp_config = 12;
+  loongarch_linux_record_tdep.size_size_t = 8;
+  loongarch_linux_record_tdep.size_iovec = 16;
+  loongarch_linux_record_tdep.size_time_t = 8;
+
+  /* These values are the second argument of system call "sys_ioctl".
+     They are obtained from Linux Kernel source.  */
+  loongarch_linux_record_tdep.ioctl_TCGETS = 0x5401;
+  loongarch_linux_record_tdep.ioctl_TCSETS = 0x5402;
+  loongarch_linux_record_tdep.ioctl_TCSETSW = 0x5403;
+  loongarch_linux_record_tdep.ioctl_TCSETSF = 0x5404;
+  loongarch_linux_record_tdep.ioctl_TCGETA = 0x5405;
+  loongarch_linux_record_tdep.ioctl_TCSETA = 0x5406;
+  loongarch_linux_record_tdep.ioctl_TCSETAW = 0x5407;
+  loongarch_linux_record_tdep.ioctl_TCSETAF = 0x5408;
+  loongarch_linux_record_tdep.ioctl_TCSBRK = 0x5409;
+  loongarch_linux_record_tdep.ioctl_TCXONC = 0x540a;
+  loongarch_linux_record_tdep.ioctl_TCFLSH = 0x540b;
+  loongarch_linux_record_tdep.ioctl_TIOCEXCL = 0x540c;
+  loongarch_linux_record_tdep.ioctl_TIOCNXCL = 0x540d;
+  loongarch_linux_record_tdep.ioctl_TIOCSCTTY = 0x540e;
+  loongarch_linux_record_tdep.ioctl_TIOCGPGRP = 0x540f;
+  loongarch_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
+  loongarch_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
+  loongarch_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
+  loongarch_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
+  loongarch_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
+  loongarch_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
+  loongarch_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
+  loongarch_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
+  loongarch_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
+  loongarch_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
+  loongarch_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541a;
+  loongarch_linux_record_tdep.ioctl_FIONREAD = 0x541b;
+  loongarch_linux_record_tdep.ioctl_TIOCINQ = 0x541b;
+  loongarch_linux_record_tdep.ioctl_TIOCLINUX = 0x541c;
+  loongarch_linux_record_tdep.ioctl_TIOCCONS = 0x541d;
+  loongarch_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541e;
+  loongarch_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541f;
+  loongarch_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
+  loongarch_linux_record_tdep.ioctl_FIONBIO = 0x5421;
+  loongarch_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
+  loongarch_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
+  loongarch_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
+  loongarch_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
+  loongarch_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
+  loongarch_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
+  loongarch_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
+  loongarch_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
+  loongarch_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
+  loongarch_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
+  loongarch_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
+  loongarch_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
+  loongarch_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
+  loongarch_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
+  loongarch_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
+  loongarch_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
+  loongarch_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
+  loongarch_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
+  loongarch_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
+  loongarch_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
+  loongarch_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
+  loongarch_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
+  loongarch_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
+  loongarch_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
+  loongarch_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545a;
+  loongarch_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545b;
+  loongarch_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545c;
+  loongarch_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545d;
+  loongarch_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545e;
+  loongarch_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545f;
+  loongarch_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
+
+  /* These values are the second argument of system call "sys_fcntl"
+     and "sys_fcntl64".  They are obtained from Linux Kernel source. */
+  loongarch_linux_record_tdep.fcntl_F_GETLK = 5;
+  loongarch_linux_record_tdep.fcntl_F_GETLK64 = 12;
+  loongarch_linux_record_tdep.fcntl_F_SETLK64 = 13;
+  loongarch_linux_record_tdep.fcntl_F_SETLKW64 = 14;
+
+  loongarch_linux_record_tdep.arg1 = LOONGARCH_A0_REGNUM + 0;
+  loongarch_linux_record_tdep.arg2 = LOONGARCH_A0_REGNUM + 1;
+  loongarch_linux_record_tdep.arg3 = LOONGARCH_A0_REGNUM + 2;
+  loongarch_linux_record_tdep.arg4 = LOONGARCH_A0_REGNUM + 3;
+  loongarch_linux_record_tdep.arg5 = LOONGARCH_A0_REGNUM + 4;
+  loongarch_linux_record_tdep.arg6 = LOONGARCH_A0_REGNUM + 5;
+  loongarch_linux_record_tdep.arg7 = LOONGARCH_A0_REGNUM + 6;
+}
+
 /* Initialize LoongArch Linux ABI info.  */
 
 static void
@@ -605,6 +1168,10 @@  loongarch_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   /* Reversible debugging, process record.  */
   set_gdbarch_process_record (gdbarch, loongarch_process_record);
+
+  /* Syscall record.  */
+  tdep->loongarch_syscall_record = loongarch_linux_syscall_record;
+  init_loongarch_linux_record_tdep (gdbarch);
 }
 
 /* Initialize LoongArch Linux target support.  */
diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index c1b3a1f239c..e91a69b73b9 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -2312,6 +2312,22 @@  loongarch_record_special_insn (loongarch_record_s *loongarch_record)
   return LOONGARCH_RECORD_SUCCESS;
 }
 
+/* Record handler for syscall instructions.  */
+
+static int
+loongarch_record_syscall_insn (loongarch_record_s *loongarch_record)
+{
+  uint64_t syscall_number;
+  struct loongarch_gdbarch_tdep *tdep
+	    = gdbarch_tdep<loongarch_gdbarch_tdep> (loongarch_record->gdbarch);
+
+  regcache_raw_read_unsigned (loongarch_record->regcache, LOONGARCH_A7_REGNUM,
+			      &syscall_number);
+
+  return tdep->loongarch_syscall_record (loongarch_record->regcache,
+					 syscall_number);
+}
+
 /* Decode insns type and invoke its record handler.  */
 
 static int
@@ -2335,6 +2351,8 @@  loongarch_record_decode_insn_handler (loongarch_record_s *loongarch_record)
     return loongarch_record_bound_check_load_insn (loongarch_record);
   else if (is_bound_check_store_insn (loongarch_record->insn))
     return loongarch_record_bound_check_store_insn (loongarch_record);
+  else if (is_syscall_insn (loongarch_record->insn))
+    return loongarch_record_syscall_insn (loongarch_record);
 
   return LOONGARCH_RECORD_UNSUPPORTED;
 }
diff --git a/gdb/loongarch-tdep.h b/gdb/loongarch-tdep.h
index a148363c795..62f7edc1c45 100644
--- a/gdb/loongarch-tdep.h
+++ b/gdb/loongarch-tdep.h
@@ -40,6 +40,10 @@  struct loongarch_gdbarch_tdep : gdbarch_tdep_base
   /* Features about the abi that impact how the gdbarch is configured.  */
   struct loongarch_gdbarch_features abi_features;
 
+  /* syscall record.  */
+  int (*loongarch_syscall_record) (struct regcache *regcache,
+				   unsigned long syscall_number) = nullptr;
+
   /* Return the expected next PC if FRAME is stopped at a syscall instruction.  */
   CORE_ADDR (*syscall_next_pc) (const frame_info_ptr &frame) = nullptr;
 };