)]}'
{
  "commit": "fbfb29b304ef7d3270a918b5fc60c22b0909367e",
  "tree": "7a81e2c874fd0dcec142f24ec28f7894e6ba45ed",
  "parents": [
    "0d1d25671598eed4fdeab09d0ef987c12afce21c"
  ],
  "author": {
    "name": "Tom de Vries",
    "email": "tdevries@suse.de",
    "time": "Thu Mar 13 07:41:51 2025 +0100"
  },
  "committer": {
    "name": "Tom de Vries",
    "email": "tdevries@suse.de",
    "time": "Thu Mar 13 07:41:51 2025 +0100"
  },
  "message": "[gdb/tdep] Rewrite i386_canonicalize_syscall\n\nOn openSUSE Tumbleweed x86_64, with target board unix/-m32 and test-case\ngdb.reverse/recvmsg-reverse.exp, I run into:\n...\n(gdb) continue^M\nContinuing.^M\nProcess record and replay target doesn\u0027t support syscall number 360^M\nProcess record: failed to record execution log.^M\n^M\nProgram stopped.^M\n0xf7fc5575 in __kernel_vsyscall ()^M\n(gdb) FAIL: $exp: continue to breakpoint: marker2\n...\n\nThe syscall number 360 in i386 is for syscall socketpair, as we can see in\narch/x86/entry/syscalls/syscall_32.tbl:\n...\n\u003cnumber\u003e  \u003cabi\u003e  \u003cname\u003e      \u003centry point\u003e\n360       i386   socketpair  sys_socketpair\n...\n\nFunction i386_canonicalize_syscall assumes that any syscall below 500 maps to\nan identically valued enum in enum gdb_syscall:\n...\nstatic enum gdb_syscall\ni386_canonicalize_syscall (int syscall)\n{\n  enum { i386_syscall_max \u003d 499 };\n\n  if (syscall \u003c\u003d i386_syscall_max)\n    return (enum gdb_syscall) syscall;\n  else\n    return gdb_sys_no_syscall;\n}\n...\n\nHowever, that\u0027s not the case.  The value of gdb_sys_socketpair is not 360,\nbut 512:\n...\nenum gdb_syscall {\n  ...\n  gdb_sys_getrandom \u003d 355,\n  gdb_sys_statx \u003d 383,\n  ...\n  gdb_sys_socketpair \u003d 512,\n...\n\nConsequently, when record_linux_system_call is called with\nsyscall \u003d\u003d i386_canonicalize_syscall (360), we hit the default case here:\n....\n  switch (syscall)\n    {\n    ...\n    default:\n      gdb_printf (gdb_stderr,\n                  _(\"Process record and replay target doesn\u0027t \"\n                    \"support syscall number %d\\n\"), syscall);\n      return -1;\n      break;\n    }\n...\nrather than hitting the case for gdb_sys_socketpair.\n\nI initially wrote a trivial fix for this, changing the value of\ngdb_sys_socketpair to 360.  However, Andreas Schwab pointed out that there are\nother functions (ppc_canonicalize_syscall and s390_canonicalize_syscall) that\nmake assumptions about specific values of enum gdb_syscall, and fixing this\nfor i386 may break things for ppc or s390.\n\nSo instead, I decided to rewrite i386_canonicalize_syscall to match the\napproach taken in aarch64_canonicalize_syscall, which allows\ngdb_sys_socketpair to keep the same value.\n\nSo, fix this by:\n- adding a new table file gdb/i386-syscalls.def, using a SYSCALL entry for\n  each syscall, generated from arch/x86/entry/syscalls/syscall_32.tbl,\n- using gdb/i386-syscalls.def to define enum i386_syscall, and\n- using macros SYSCALL_MAP, SYSCALL_MAP_RENAME and UNSUPPORTED_SYSCALL_MAP to\n  define the mapping from enum i386_syscall to enum gdb_syscall in\n  i386_canonicalize_syscall.\n\nI\u0027ve created the mapping as follows:\n- I used arch/x86/entry/syscalls/syscall_32.tbl to generate an initial mapping\n  using SYSCALL_MAP for each syscall,\n- I attempted to compile this and used the compilation errors about\n  non-existing gdb_sys_ values to change those entries to\n  UNSUPPORTED_SYSCALL_MAP, which got me a compiling version,\n- I reviewed the UNSUPPORTED_SYSCALL_MAP entries, changing to\n  SYSCALL_MAP_RENAME where necessary,\n- I then reviewed syscalls below 500 that mapped to a gdb_syscall value below\n  500, but not the same, and fixed those using SYSCALL_MAP_RENAME, and\n- reviewed the mapping for gdb_syscall entries \u003e\u003d 500.\n\nOn the resulting mapping, I was able to do the following sanity check:\n...\n  for (int i \u003d 0; i \u003c 500; ++i)\n    {\n      int res \u003d i386_canonicalize_syscall (i);\n      if (res \u003d\u003d i)\n\tcontinue;\n      if (res \u003d\u003d -1)\n\tcontinue;\n      if (res \u003e\u003d 500)\n\tcontinue;\n      gdb_assert_not_reached (\"\");\n    }\n}\n...\nto make sure that any syscall below 500 either:\n- maps to the same number,\n- is unsupported, or\n- maps to a number \u003e\u003d 500.\n\nComing back to our original problem, the socket pair syscall is addressed by\nan entry:\n...\n      SYSCALL_MAP (socketpair);\n...\nwhich maps i386_sys_socketpair (360) to gdb_sys_socketpair (512).\n\nTested on x86_64-linux with target board unix/-m32.\n\nApproved-By: Guinevere Larsen \u003cguinevere@redhat.com\u003e\n\nPR tdep/32770\nBug: https://sourceware.org/bugzilla/show_bug.cgi?id\u003d32770\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "9dec83ac753d1d90ce2333ead1f074177f4e12ea",
      "old_mode": 33188,
      "old_path": "gdb/i386-linux-tdep.c",
      "new_id": "374a60307ac67dbd534ccad9a20e3b7af9300f3e",
      "new_mode": 33188,
      "new_path": "gdb/i386-linux-tdep.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "5ba384ab505bed31452664fcec9f299d06265e10",
      "new_mode": 33188,
      "new_path": "gdb/i386-syscalls.def"
    }
  ]
}
