Files
binutils-gdb/gdb/i386-syscalls.def
Tom de Vries fbfb29b304 [gdb/tdep] Rewrite i386_canonicalize_syscall
On openSUSE Tumbleweed x86_64, with target board unix/-m32 and test-case
gdb.reverse/recvmsg-reverse.exp, I run into:
...
(gdb) continue^M
Continuing.^M
Process record and replay target doesn't support syscall number 360^M
Process record: failed to record execution log.^M
^M
Program stopped.^M
0xf7fc5575 in __kernel_vsyscall ()^M
(gdb) FAIL: $exp: continue to breakpoint: marker2
...

The syscall number 360 in i386 is for syscall socketpair, as we can see in
arch/x86/entry/syscalls/syscall_32.tbl:
...
<number>  <abi>  <name>      <entry point>
360       i386   socketpair  sys_socketpair
...

Function i386_canonicalize_syscall assumes that any syscall below 500 maps to
an identically valued enum in enum gdb_syscall:
...
static enum gdb_syscall
i386_canonicalize_syscall (int syscall)
{
  enum { i386_syscall_max = 499 };

  if (syscall <= i386_syscall_max)
    return (enum gdb_syscall) syscall;
  else
    return gdb_sys_no_syscall;
}
...

However, that's not the case.  The value of gdb_sys_socketpair is not 360,
but 512:
...
enum gdb_syscall {
  ...
  gdb_sys_getrandom = 355,
  gdb_sys_statx = 383,
  ...
  gdb_sys_socketpair = 512,
...

Consequently, when record_linux_system_call is called with
syscall == i386_canonicalize_syscall (360), we hit the default case here:
....
  switch (syscall)
    {
    ...
    default:
      gdb_printf (gdb_stderr,
                  _("Process record and replay target doesn't "
                    "support syscall number %d\n"), syscall);
      return -1;
      break;
    }
...
rather than hitting the case for gdb_sys_socketpair.

I initially wrote a trivial fix for this, changing the value of
gdb_sys_socketpair to 360.  However, Andreas Schwab pointed out that there are
other functions (ppc_canonicalize_syscall and s390_canonicalize_syscall) that
make assumptions about specific values of enum gdb_syscall, and fixing this
for i386 may break things for ppc or s390.

So instead, I decided to rewrite i386_canonicalize_syscall to match the
approach taken in aarch64_canonicalize_syscall, which allows
gdb_sys_socketpair to keep the same value.

So, fix this by:
- adding a new table file gdb/i386-syscalls.def, using a SYSCALL entry for
  each syscall, generated from arch/x86/entry/syscalls/syscall_32.tbl,
- using gdb/i386-syscalls.def to define enum i386_syscall, and
- using macros SYSCALL_MAP, SYSCALL_MAP_RENAME and UNSUPPORTED_SYSCALL_MAP to
  define the mapping from enum i386_syscall to enum gdb_syscall in
  i386_canonicalize_syscall.

I've created the mapping as follows:
- I used arch/x86/entry/syscalls/syscall_32.tbl to generate an initial mapping
  using SYSCALL_MAP for each syscall,
- I attempted to compile this and used the compilation errors about
  non-existing gdb_sys_ values to change those entries to
  UNSUPPORTED_SYSCALL_MAP, which got me a compiling version,
- I reviewed the UNSUPPORTED_SYSCALL_MAP entries, changing to
  SYSCALL_MAP_RENAME where necessary,
- I then reviewed syscalls below 500 that mapped to a gdb_syscall value below
  500, but not the same, and fixed those using SYSCALL_MAP_RENAME, and
- reviewed the mapping for gdb_syscall entries >= 500.

On the resulting mapping, I was able to do the following sanity check:
...
  for (int i = 0; i < 500; ++i)
    {
      int res = i386_canonicalize_syscall (i);
      if (res == i)
	continue;
      if (res == -1)
	continue;
      if (res >= 500)
	continue;
      gdb_assert_not_reached ("");
    }
}
...
to make sure that any syscall below 500 either:
- maps to the same number,
- is unsupported, or
- maps to a number >= 500.

Coming back to our original problem, the socket pair syscall is addressed by
an entry:
...
      SYSCALL_MAP (socketpair);
...
which maps i386_sys_socketpair (360) to gdb_sys_socketpair (512).

Tested on x86_64-linux with target board unix/-m32.

Approved-By: Guinevere Larsen <guinevere@redhat.com>

PR tdep/32770
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32770
2025-03-13 07:41:51 +01:00

480 lines
12 KiB
Modula-2

/* Copyright (C) 2025 Free Software Foundation, Inc.
This file is part of GDB.
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/>.
Generated using linux v6.13 and command:
$ egrep -v "^#.*" ./arch/x86/entry/syscalls/syscall_32.tbl \
| awk '{printf "SYSCALL (%s, %s)\n", $1, $3}'
*/
SYSCALL (0, restart_syscall)
SYSCALL (1, exit)
SYSCALL (2, fork)
SYSCALL (3, read)
SYSCALL (4, write)
SYSCALL (5, open)
SYSCALL (6, close)
SYSCALL (7, waitpid)
SYSCALL (8, creat)
SYSCALL (9, link)
SYSCALL (10, unlink)
SYSCALL (11, execve)
SYSCALL (12, chdir)
SYSCALL (13, time)
SYSCALL (14, mknod)
SYSCALL (15, chmod)
SYSCALL (16, lchown)
SYSCALL (17, break)
SYSCALL (18, oldstat)
SYSCALL (19, lseek)
SYSCALL (20, getpid)
SYSCALL (21, mount)
SYSCALL (22, umount)
SYSCALL (23, setuid)
SYSCALL (24, getuid)
SYSCALL (25, stime)
SYSCALL (26, ptrace)
SYSCALL (27, alarm)
SYSCALL (28, oldfstat)
SYSCALL (29, pause)
SYSCALL (30, utime)
SYSCALL (31, stty)
SYSCALL (32, gtty)
SYSCALL (33, access)
SYSCALL (34, nice)
SYSCALL (35, ftime)
SYSCALL (36, sync)
SYSCALL (37, kill)
SYSCALL (38, rename)
SYSCALL (39, mkdir)
SYSCALL (40, rmdir)
SYSCALL (41, dup)
SYSCALL (42, pipe)
SYSCALL (43, times)
SYSCALL (44, prof)
SYSCALL (45, brk)
SYSCALL (46, setgid)
SYSCALL (47, getgid)
SYSCALL (48, signal)
SYSCALL (49, geteuid)
SYSCALL (50, getegid)
SYSCALL (51, acct)
SYSCALL (52, umount2)
SYSCALL (53, lock)
SYSCALL (54, ioctl)
SYSCALL (55, fcntl)
SYSCALL (56, mpx)
SYSCALL (57, setpgid)
SYSCALL (58, ulimit)
SYSCALL (59, oldolduname)
SYSCALL (60, umask)
SYSCALL (61, chroot)
SYSCALL (62, ustat)
SYSCALL (63, dup2)
SYSCALL (64, getppid)
SYSCALL (65, getpgrp)
SYSCALL (66, setsid)
SYSCALL (67, sigaction)
SYSCALL (68, sgetmask)
SYSCALL (69, ssetmask)
SYSCALL (70, setreuid)
SYSCALL (71, setregid)
SYSCALL (72, sigsuspend)
SYSCALL (73, sigpending)
SYSCALL (74, sethostname)
SYSCALL (75, setrlimit)
SYSCALL (76, getrlimit)
SYSCALL (77, getrusage)
SYSCALL (78, gettimeofday)
SYSCALL (79, settimeofday)
SYSCALL (80, getgroups)
SYSCALL (81, setgroups)
SYSCALL (82, select)
SYSCALL (83, symlink)
SYSCALL (84, oldlstat)
SYSCALL (85, readlink)
SYSCALL (86, uselib)
SYSCALL (87, swapon)
SYSCALL (88, reboot)
SYSCALL (89, readdir)
SYSCALL (90, mmap)
SYSCALL (91, munmap)
SYSCALL (92, truncate)
SYSCALL (93, ftruncate)
SYSCALL (94, fchmod)
SYSCALL (95, fchown)
SYSCALL (96, getpriority)
SYSCALL (97, setpriority)
SYSCALL (98, profil)
SYSCALL (99, statfs)
SYSCALL (100, fstatfs)
SYSCALL (101, ioperm)
SYSCALL (102, socketcall)
SYSCALL (103, syslog)
SYSCALL (104, setitimer)
SYSCALL (105, getitimer)
SYSCALL (106, stat)
SYSCALL (107, lstat)
SYSCALL (108, fstat)
SYSCALL (109, olduname)
SYSCALL (110, iopl)
SYSCALL (111, vhangup)
SYSCALL (112, idle)
SYSCALL (113, vm86old)
SYSCALL (114, wait4)
SYSCALL (115, swapoff)
SYSCALL (116, sysinfo)
SYSCALL (117, ipc)
SYSCALL (118, fsync)
SYSCALL (119, sigreturn)
SYSCALL (120, clone)
SYSCALL (121, setdomainname)
SYSCALL (122, uname)
SYSCALL (123, modify_ldt)
SYSCALL (124, adjtimex)
SYSCALL (125, mprotect)
SYSCALL (126, sigprocmask)
SYSCALL (127, create_module)
SYSCALL (128, init_module)
SYSCALL (129, delete_module)
SYSCALL (130, get_kernel_syms)
SYSCALL (131, quotactl)
SYSCALL (132, getpgid)
SYSCALL (133, fchdir)
SYSCALL (134, bdflush)
SYSCALL (135, sysfs)
SYSCALL (136, personality)
SYSCALL (137, afs_syscall)
SYSCALL (138, setfsuid)
SYSCALL (139, setfsgid)
SYSCALL (140, _llseek)
SYSCALL (141, getdents)
SYSCALL (142, _newselect)
SYSCALL (143, flock)
SYSCALL (144, msync)
SYSCALL (145, readv)
SYSCALL (146, writev)
SYSCALL (147, getsid)
SYSCALL (148, fdatasync)
SYSCALL (149, _sysctl)
SYSCALL (150, mlock)
SYSCALL (151, munlock)
SYSCALL (152, mlockall)
SYSCALL (153, munlockall)
SYSCALL (154, sched_setparam)
SYSCALL (155, sched_getparam)
SYSCALL (156, sched_setscheduler)
SYSCALL (157, sched_getscheduler)
SYSCALL (158, sched_yield)
SYSCALL (159, sched_get_priority_max)
SYSCALL (160, sched_get_priority_min)
SYSCALL (161, sched_rr_get_interval)
SYSCALL (162, nanosleep)
SYSCALL (163, mremap)
SYSCALL (164, setresuid)
SYSCALL (165, getresuid)
SYSCALL (166, vm86)
SYSCALL (167, query_module)
SYSCALL (168, poll)
SYSCALL (169, nfsservctl)
SYSCALL (170, setresgid)
SYSCALL (171, getresgid)
SYSCALL (172, prctl)
SYSCALL (173, rt_sigreturn)
SYSCALL (174, rt_sigaction)
SYSCALL (175, rt_sigprocmask)
SYSCALL (176, rt_sigpending)
SYSCALL (177, rt_sigtimedwait)
SYSCALL (178, rt_sigqueueinfo)
SYSCALL (179, rt_sigsuspend)
SYSCALL (180, pread64)
SYSCALL (181, pwrite64)
SYSCALL (182, chown)
SYSCALL (183, getcwd)
SYSCALL (184, capget)
SYSCALL (185, capset)
SYSCALL (186, sigaltstack)
SYSCALL (187, sendfile)
SYSCALL (188, getpmsg)
SYSCALL (189, putpmsg)
SYSCALL (190, vfork)
SYSCALL (191, ugetrlimit)
SYSCALL (192, mmap2)
SYSCALL (193, truncate64)
SYSCALL (194, ftruncate64)
SYSCALL (195, stat64)
SYSCALL (196, lstat64)
SYSCALL (197, fstat64)
SYSCALL (198, lchown32)
SYSCALL (199, getuid32)
SYSCALL (200, getgid32)
SYSCALL (201, geteuid32)
SYSCALL (202, getegid32)
SYSCALL (203, setreuid32)
SYSCALL (204, setregid32)
SYSCALL (205, getgroups32)
SYSCALL (206, setgroups32)
SYSCALL (207, fchown32)
SYSCALL (208, setresuid32)
SYSCALL (209, getresuid32)
SYSCALL (210, setresgid32)
SYSCALL (211, getresgid32)
SYSCALL (212, chown32)
SYSCALL (213, setuid32)
SYSCALL (214, setgid32)
SYSCALL (215, setfsuid32)
SYSCALL (216, setfsgid32)
SYSCALL (217, pivot_root)
SYSCALL (218, mincore)
SYSCALL (219, madvise)
SYSCALL (220, getdents64)
SYSCALL (221, fcntl64)
SYSCALL (224, gettid)
SYSCALL (225, readahead)
SYSCALL (226, setxattr)
SYSCALL (227, lsetxattr)
SYSCALL (228, fsetxattr)
SYSCALL (229, getxattr)
SYSCALL (230, lgetxattr)
SYSCALL (231, fgetxattr)
SYSCALL (232, listxattr)
SYSCALL (233, llistxattr)
SYSCALL (234, flistxattr)
SYSCALL (235, removexattr)
SYSCALL (236, lremovexattr)
SYSCALL (237, fremovexattr)
SYSCALL (238, tkill)
SYSCALL (239, sendfile64)
SYSCALL (240, futex)
SYSCALL (241, sched_setaffinity)
SYSCALL (242, sched_getaffinity)
SYSCALL (243, set_thread_area)
SYSCALL (244, get_thread_area)
SYSCALL (245, io_setup)
SYSCALL (246, io_destroy)
SYSCALL (247, io_getevents)
SYSCALL (248, io_submit)
SYSCALL (249, io_cancel)
SYSCALL (250, fadvise64)
SYSCALL (252, exit_group)
SYSCALL (253, lookup_dcookie)
SYSCALL (254, epoll_create)
SYSCALL (255, epoll_ctl)
SYSCALL (256, epoll_wait)
SYSCALL (257, remap_file_pages)
SYSCALL (258, set_tid_address)
SYSCALL (259, timer_create)
SYSCALL (260, timer_settime)
SYSCALL (261, timer_gettime)
SYSCALL (262, timer_getoverrun)
SYSCALL (263, timer_delete)
SYSCALL (264, clock_settime)
SYSCALL (265, clock_gettime)
SYSCALL (266, clock_getres)
SYSCALL (267, clock_nanosleep)
SYSCALL (268, statfs64)
SYSCALL (269, fstatfs64)
SYSCALL (270, tgkill)
SYSCALL (271, utimes)
SYSCALL (272, fadvise64_64)
SYSCALL (273, vserver)
SYSCALL (274, mbind)
SYSCALL (275, get_mempolicy)
SYSCALL (276, set_mempolicy)
SYSCALL (277, mq_open)
SYSCALL (278, mq_unlink)
SYSCALL (279, mq_timedsend)
SYSCALL (280, mq_timedreceive)
SYSCALL (281, mq_notify)
SYSCALL (282, mq_getsetattr)
SYSCALL (283, kexec_load)
SYSCALL (284, waitid)
SYSCALL (286, add_key)
SYSCALL (287, request_key)
SYSCALL (288, keyctl)
SYSCALL (289, ioprio_set)
SYSCALL (290, ioprio_get)
SYSCALL (291, inotify_init)
SYSCALL (292, inotify_add_watch)
SYSCALL (293, inotify_rm_watch)
SYSCALL (294, migrate_pages)
SYSCALL (295, openat)
SYSCALL (296, mkdirat)
SYSCALL (297, mknodat)
SYSCALL (298, fchownat)
SYSCALL (299, futimesat)
SYSCALL (300, fstatat64)
SYSCALL (301, unlinkat)
SYSCALL (302, renameat)
SYSCALL (303, linkat)
SYSCALL (304, symlinkat)
SYSCALL (305, readlinkat)
SYSCALL (306, fchmodat)
SYSCALL (307, faccessat)
SYSCALL (308, pselect6)
SYSCALL (309, ppoll)
SYSCALL (310, unshare)
SYSCALL (311, set_robust_list)
SYSCALL (312, get_robust_list)
SYSCALL (313, splice)
SYSCALL (314, sync_file_range)
SYSCALL (315, tee)
SYSCALL (316, vmsplice)
SYSCALL (317, move_pages)
SYSCALL (318, getcpu)
SYSCALL (319, epoll_pwait)
SYSCALL (320, utimensat)
SYSCALL (321, signalfd)
SYSCALL (322, timerfd_create)
SYSCALL (323, eventfd)
SYSCALL (324, fallocate)
SYSCALL (325, timerfd_settime)
SYSCALL (326, timerfd_gettime)
SYSCALL (327, signalfd4)
SYSCALL (328, eventfd2)
SYSCALL (329, epoll_create1)
SYSCALL (330, dup3)
SYSCALL (331, pipe2)
SYSCALL (332, inotify_init1)
SYSCALL (333, preadv)
SYSCALL (334, pwritev)
SYSCALL (335, rt_tgsigqueueinfo)
SYSCALL (336, perf_event_open)
SYSCALL (337, recvmmsg)
SYSCALL (338, fanotify_init)
SYSCALL (339, fanotify_mark)
SYSCALL (340, prlimit64)
SYSCALL (341, name_to_handle_at)
SYSCALL (342, open_by_handle_at)
SYSCALL (343, clock_adjtime)
SYSCALL (344, syncfs)
SYSCALL (345, sendmmsg)
SYSCALL (346, setns)
SYSCALL (347, process_vm_readv)
SYSCALL (348, process_vm_writev)
SYSCALL (349, kcmp)
SYSCALL (350, finit_module)
SYSCALL (351, sched_setattr)
SYSCALL (352, sched_getattr)
SYSCALL (353, renameat2)
SYSCALL (354, seccomp)
SYSCALL (355, getrandom)
SYSCALL (356, memfd_create)
SYSCALL (357, bpf)
SYSCALL (358, execveat)
SYSCALL (359, socket)
SYSCALL (360, socketpair)
SYSCALL (361, bind)
SYSCALL (362, connect)
SYSCALL (363, listen)
SYSCALL (364, accept4)
SYSCALL (365, getsockopt)
SYSCALL (366, setsockopt)
SYSCALL (367, getsockname)
SYSCALL (368, getpeername)
SYSCALL (369, sendto)
SYSCALL (370, sendmsg)
SYSCALL (371, recvfrom)
SYSCALL (372, recvmsg)
SYSCALL (373, shutdown)
SYSCALL (374, userfaultfd)
SYSCALL (375, membarrier)
SYSCALL (376, mlock2)
SYSCALL (377, copy_file_range)
SYSCALL (378, preadv2)
SYSCALL (379, pwritev2)
SYSCALL (380, pkey_mprotect)
SYSCALL (381, pkey_alloc)
SYSCALL (382, pkey_free)
SYSCALL (383, statx)
SYSCALL (384, arch_prctl)
SYSCALL (385, io_pgetevents)
SYSCALL (386, rseq)
SYSCALL (393, semget)
SYSCALL (394, semctl)
SYSCALL (395, shmget)
SYSCALL (396, shmctl)
SYSCALL (397, shmat)
SYSCALL (398, shmdt)
SYSCALL (399, msgget)
SYSCALL (400, msgsnd)
SYSCALL (401, msgrcv)
SYSCALL (402, msgctl)
SYSCALL (403, clock_gettime64)
SYSCALL (404, clock_settime64)
SYSCALL (405, clock_adjtime64)
SYSCALL (406, clock_getres_time64)
SYSCALL (407, clock_nanosleep_time64)
SYSCALL (408, timer_gettime64)
SYSCALL (409, timer_settime64)
SYSCALL (410, timerfd_gettime64)
SYSCALL (411, timerfd_settime64)
SYSCALL (412, utimensat_time64)
SYSCALL (413, pselect6_time64)
SYSCALL (414, ppoll_time64)
SYSCALL (416, io_pgetevents_time64)
SYSCALL (417, recvmmsg_time64)
SYSCALL (418, mq_timedsend_time64)
SYSCALL (419, mq_timedreceive_time64)
SYSCALL (420, semtimedop_time64)
SYSCALL (421, rt_sigtimedwait_time64)
SYSCALL (422, futex_time64)
SYSCALL (423, sched_rr_get_interval_time64)
SYSCALL (424, pidfd_send_signal)
SYSCALL (425, io_uring_setup)
SYSCALL (426, io_uring_enter)
SYSCALL (427, io_uring_register)
SYSCALL (428, open_tree)
SYSCALL (429, move_mount)
SYSCALL (430, fsopen)
SYSCALL (431, fsconfig)
SYSCALL (432, fsmount)
SYSCALL (433, fspick)
SYSCALL (434, pidfd_open)
SYSCALL (435, clone3)
SYSCALL (436, close_range)
SYSCALL (437, openat2)
SYSCALL (438, pidfd_getfd)
SYSCALL (439, faccessat2)
SYSCALL (440, process_madvise)
SYSCALL (441, epoll_pwait2)
SYSCALL (442, mount_setattr)
SYSCALL (443, quotactl_fd)
SYSCALL (444, landlock_create_ruleset)
SYSCALL (445, landlock_add_rule)
SYSCALL (446, landlock_restrict_self)
SYSCALL (447, memfd_secret)
SYSCALL (448, process_mrelease)
SYSCALL (449, futex_waitv)
SYSCALL (450, set_mempolicy_home_node)
SYSCALL (451, cachestat)
SYSCALL (452, fchmodat2)
SYSCALL (453, map_shadow_stack)
SYSCALL (454, futex_wake)
SYSCALL (455, futex_wait)
SYSCALL (456, futex_requeue)
SYSCALL (457, statmount)
SYSCALL (458, listmount)
SYSCALL (459, lsm_get_self_attr)
SYSCALL (460, lsm_set_self_attr)
SYSCALL (461, lsm_list_modules)
SYSCALL (462, mseal)
SYSCALL (463, setxattrat)
SYSCALL (464, getxattrat)
SYSCALL (465, listxattrat)
SYSCALL (466, removexattrat)