From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id TRslL/7TB2hFDgAAWB0awg (envelope-from ) for ; Tue, 22 Apr 2025 13:38:06 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OFbxub/G; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AC97E1E0C3; Tue, 22 Apr 2025 13:38:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 863FE1E05C for ; Tue, 22 Apr 2025 13:38:02 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B68673858428 for ; Tue, 22 Apr 2025 17:38:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B68673858428 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OFbxub/G Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 554CE3858C2D for ; Tue, 22 Apr 2025 17:37:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 554CE3858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 554CE3858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::535 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745343429; cv=none; b=F86mSgl3eRcLQYzSw9DmDnT/3fbfS4NFUpqrZUTIjY15nWUQYtYMyoKQbotBEbG1tUR+8i20e2puNdNM5bIBOupiNbXI2a/az9yC4R59OcmNsg2robj23nLHlsngAafF7WfVTO2fk3YRQB475qIS98X9CRG8nGnox1WFZqrcC9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745343429; c=relaxed/simple; bh=27I5rHUeqDDTFQGRT2REqJVD7/jJTk4Y7zAjulKms1Q=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=Od++EgL0QsqsS4qJrd+z6GwFTP9H5v0zrQuyr8uiXoFm4pfEtIjUoqBi0sLx8/6215rWlkGiyIRXkVjvWo+LIS2/5lqKjzX4g6ROClIg/XmbwUreXlIRzs3bNdzUZzkEUcSsztOi2WxyaKavsGE+aNoZ3olsal2KWBu7gDUPi5k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 554CE3858C2D Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5eb92df4fcbso9446809a12.0 for ; Tue, 22 Apr 2025 10:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745343427; x=1745948227; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cArO8o5Y/1+G+97faTsI8Q8++3ev+Nvd0piB3sdAb6Q=; b=OFbxub/GDzZGsgtH8y/NVd6C0Zfq/T5ouIPpapHEgX6xCkKHXhvPkck5i9WUrdvuaP Y87XytYDaB/mrVzOYFwCSO3IsWk3bYD1kApPMn7H0XYCrwDZmeso0l3oCXiuPS8EBrmr He1iuJgfs/BpSO+OnKgq0FB4P6aGFL3mqFM2hfaoJsy9rP6wXA84NzytCLYQ7p3dt/1i bYL6KfPj2ZA8t0ch3NaK2se0+Nq/dh7tWze6x1Jyjo2I2AAxWPgB809CqLWnn1G/jdPf Hflhlm98yxkC06rf1vdP79dfM4Wuh0s5nFccgfBDZPupMD69qIAvCpFgLRnAgDf+k1qA WwhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745343427; x=1745948227; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cArO8o5Y/1+G+97faTsI8Q8++3ev+Nvd0piB3sdAb6Q=; b=YlRmXHUNdYXRvXEgF8a3N6Y1cqknRtnTgghTIOA+wafkUsS+ovbJQCMLejnof1xBeI /JN0E0TzJIQAP9IJCbCXQn8wFC2/k0xQxDsmyFwS+PgDMGgWd34h2bFvsw2xsUZQdP1u kD2GkUt5DHbHWhKy8hqkP+re2xfj+Ro0tuF7VTtdrqVaWI+X50oQ5kXdx5De3QuWpc1B pXKFDVGmg7nzRgaGIvbMeThMywhugl1qWOGerQcuSGyahldpkZJO+n3q7qM+xftyZMRK PJhY+dRechlFTBqaSV+Jf+e2VdtBlffYaGI0O2yFD/HB3nko2vh9DvrnqJ4WYQ+gDRVd OklA== X-Gm-Message-State: AOJu0YzhPz1ep03ZNKS+hJJSYg7WMdhuSqgkMOdixh2DGVJLs/bStR+U /QbnKVKZN6wLBpLDy77QSkLHjgpNW1zq0MERotbL3vh8snzOisWBV8YkNZ8mQlpRnXzAhuDK8Zn +mEp/FDDZsDyyzKCLSdAFhIrhAVIYkbTADZFc/Q== X-Gm-Gg: ASbGncvKYT8zlS0TnYYYR2ld4cq0exFlBlYJyOBwbUQy41pBTYhD7okQcwy3b5fR9Al UwfMUM4/3MKUb4XAD/Pu6ULFjJkjf9+gBfzxAn3A4C4y9IWmcKvcbyFoQX+Yxu5rjuIBX9SSj6w 0gqbELhAqogXSvwT5GY4KQ5Q== X-Google-Smtp-Source: AGHT+IFqErLgv4EDYMz2WHO+afnL040qfvTGjKrlM9zQqM7qtoaB8vLJvi1MtBEg89edtA7KrJBqUWwIoSkSXv0y5pE= X-Received: by 2002:a05:6402:1e8e:b0:5f2:f29c:b98c with SMTP id 4fb4d7f45d1cf-5f62862706dmr13961025a12.32.1745343426103; Tue, 22 Apr 2025 10:37:06 -0700 (PDT) MIME-Version: 1.0 References: <875xjce5r8.fsf@redhat.com> <20250410115519.617361-1-timurgol007@gmail.com> <87fribdwc9.fsf@redhat.com> In-Reply-To: From: Timur Golubovich Date: Tue, 22 Apr 2025 20:36:54 +0300 X-Gm-Features: ATxdqUHU93RyJGSuZ7kVnu-MVfNmJlALGO6ZgDyF_j8I1VZ6LOU6QeuINCyiLKM Message-ID: Subject: Re: [PATCH v8] This commit adds record full support for rv64gc instruction set To: Andrew Burgess Cc: gdb-patches@sourceware.org, Guinevere Larsen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi! Sorry to bother, but It seems like no one else has any questions about this patch. Maybe then it's possible to merge it? > > Hi! > Thank you Andrew for watching this. > I think that now we can merge this patch? > > =D0=BF=D0=BD, 14 =D0=B0=D0=BF=D1=80. 2025=E2=80=AF=D0=B3. =D0=B2 10:41, A= ndrew Burgess : > > > > > Timur writes: > > > > > It includes changes to the following files: > > > - gdb/riscv-linux-tdep.c, gdb/riscv-linux-tdep.h: adds facilities to = record > > > syscalls. > > > - gdb/riscv-tdep.c, gdb/riscv-tdep.h: adds facilities to record execu= tion of > > > rv64gc instructions. > > > - gdb/configure.tgt: adds new files for compilation. > > > - gdb/testsuite/lib/gdb.exp: enables testing of full record mode for = RISC-V > > > targets. > > > - gdb/syscalls/riscv-canonicalize-syscall-gen.py: a script to generat= e > > > function that canonicalizes RISC-V syscall. This script can simplify = support > > > for syscalls on rv32 and rv64 system (currently support only for rv64= ). To > > > use this script you need to pass a path to a file with syscalls descr= iption > > > from riscv-glibc (example is in the help message). The script produce= s a > > > mapping from syscall names to gdb_syscall enum. > > > - gdb/riscv-canonicalize-syscall.c: the file generated by the previou= s script. > > > - gdb/doc/gdb.texinfo: notification that record mode is enabled in RI= SC-V. > > > - gdb/NEWS: notification of new functionality. > > > > > > Approved-By: Guinevere Larsen > > > > > > Hi Andrew! Thank you for review. > > > > > >> I guess riscv-glibc is a fork of glibc that is running ahead of the > > >> upstream glibc project? > > >> > > >> Is there any reason that this cannot work with the official glibc > > >> project? That would be preferable I think unless there's a compelli= ng > > >> reason, which ideally we'd document. > > >> > > >> I tried running the script using current HEAD of glibc, the only > > >> significant change is: > > >> > > >> diff --git i/gdb/riscv-canonicalize-syscall-gen.c w/gdb/riscv-cano= nicalize-syscall-gen.c > > >> index 3749fc32f33..03579984f4a 100644 > > >> --- i/gdb/riscv-canonicalize-syscall-gen.c > > >> +++ w/gdb/riscv-canonicalize-syscall-gen.c > > >> @@ -270,7 +270,7 @@ riscv64_canonicalize_syscall (int syscall) > > >> case 239: return gdb_sys_move_pages; > > >> /* case 240: return gdb_sys_rt_tgsigqueueinfo; */ > > >> /* case 241: return gdb_sys_perf_event_open; */ > > >> - /* case 242: return gdb_sys_accept4; */ > > >> + case 242: return gdb_sys_accept4; > > >> /* case 243: return gdb_sys_recvmmsg; */ > > >> /* case 258: return gdb_sys_riscv_hwprobe; */ > > >> /* case 259: return gdb_sys_riscv_flush_icache; */ > > >> > > >> There was also a bunch of new syscalls that are added, but commented > > >> out. I haven't tried to figure out if the change above is a bad thi= ng > > >> or not though, maybe you could advise. > > > > > > Yes, I agree with you, I just used riscv-glibc as I had aldready down= loaded it > > > and unfortunately the version was pretty old (I started working on th= is patch > > > almost half a year ago). > > > > > >> This entry needs to move to the correct section of the NEWS file. I= f > > >> you look for the lines starting '***' you'll see that the first head= er > > >> is '*** Changes since GDB 16', this is the section where you should > > >> place your entry, probably just before the '* New commands' line. > > >> These include guards need to be renamed to GDB_RISCV_LINUX_TDEP_H. = You > > >> can do this automatically if you like with: > > >> > > >> ./gdb/check-include-guards.py --update gdb/*.h > > >> + > > >> +#include "linux-record.h" > > >> + > > >> +/* riscv64_canonicalize_syscall maps from the native riscv Linux se= t > > >> + of syscall ids into a canonical set of syscall ids used by > > >> + process record. */ > > >> + > > >> +extern enum gdb_syscall riscv64_canonicalize_syscall (int syscall); > > >> + > > >> +#endif /* RISCV_LINUX_TDEP_H */ > > > > > > Addressed > > > > > >>@@ -3718,7 +3718,8 @@ proc supports_reverse {} { > > >>> || [istarget "i\[34567\]86-*-linux*"] > > >>> || [istarget "aarch64*-*-linux*"] > > >>> || [istarget "powerpc*-*-linux*"] > > >>> - || [istarget "s390*-*-linux*"] } { > > >>> + || [istarget "s390*-*-linux*"] > > >>> + || [istarget "riscv*-*-*"] } { > > >> > > >> I notice that every other entry in this list restricts the match to > > >> Linux based targets. Is RISC-V really different here? Or should RI= SC-V > > >> be similarly restricted? > > > > > > Addressed, this was just my misprint. > > > > > > Hope that now everything is okay, wait for your feedback. > > > > I scanned the fixes, they look good. I haven't looked at the rest of > > the patch in detail, assuming it hasn't changed from the previous > > version: > > > > Approved-By: Andrew Burgess > > > > Thanks, > > Andrew > > > > > > > > > > > > --- > > > gdb/NEWS | 2 + > > > gdb/configure.tgt | 5 +- > > > gdb/doc/gdb.texinfo | 2 +- > > > gdb/riscv-canonicalize-syscall-gen.c | 358 +++++++++ > > > gdb/riscv-linux-tdep.c | 256 +++++++ > > > gdb/riscv-linux-tdep.h | 29 + > > > gdb/riscv-tdep.c | 686 ++++++++++++++++= +- > > > gdb/riscv-tdep.h | 16 +- > > > .../riscv-canonicalize-syscall-gen.py | 163 +++++ > > > gdb/testsuite/lib/gdb.exp | 3 +- > > > 10 files changed, 1510 insertions(+), 10 deletions(-) > > > create mode 100644 gdb/riscv-canonicalize-syscall-gen.c > > > create mode 100644 gdb/riscv-linux-tdep.h > > > create mode 100755 gdb/syscalls/riscv-canonicalize-syscall-gen.py > > > > > > diff --git a/gdb/NEWS b/gdb/NEWS > > > index 99ec392d4c4..1a05a9f9251 100644 > > > --- a/gdb/NEWS > > > +++ b/gdb/NEWS > > > @@ -40,6 +40,8 @@ > > > namespace into which the library was loaded, if more than one name= space > > > is active. > > > > > > +* Add record full support for rv64gc architectures > > > + > > > * New commands > > > > > > maintenance check psymtabs > > > diff --git a/gdb/configure.tgt b/gdb/configure.tgt > > > index 18a15c032c3..44da2257be8 100644 > > > --- a/gdb/configure.tgt > > > +++ b/gdb/configure.tgt > > > @@ -534,8 +534,9 @@ riscv*-*-freebsd*) > > > > > > riscv*-*-linux*) > > > # Target: Linux/RISC-V > > > - gdb_target_obs=3D"riscv-linux-tdep.o glibc-tdep.o \ > > > - linux-tdep.o solib-svr4.o symfile-mem.o linux-r= ecord.o" > > > + gdb_target_obs=3D"riscv-linux-tdep.o riscv-canonicalize-syscall= -gen.o \ > > > + glibc-tdep.o linux-tdep.o solib-svr4.o symfile-= mem.o \ > > > + linux-record.o" > > > ;; > > > > > > riscv*-*-*) > > > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > > > index b251c8e1228..73f3b14cf74 100644 > > > --- a/gdb/doc/gdb.texinfo > > > +++ b/gdb/doc/gdb.texinfo > > > @@ -7807,7 +7807,7 @@ previous instruction; otherwise, it will work i= n record mode, if the > > > platform supports reverse execution, or stop if not. > > > > > > Currently, process record and replay is supported on ARM, Aarch64, > > > -LoongArch, Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) ru= nning > > > +Moxie, PowerPC, PowerPC64, S/390, RISC-V and x86 (i386/amd64) runnin= g > > > GNU/Linux. Process record and replay can be used both when native > > > debugging, and when remote debugging via @code{gdbserver}. > > > > > > diff --git a/gdb/riscv-canonicalize-syscall-gen.c b/gdb/riscv-canonic= alize-syscall-gen.c > > > new file mode 100644 > > > index 00000000000..03579984f4a > > > --- /dev/null > > > +++ b/gdb/riscv-canonicalize-syscall-gen.c > > > @@ -0,0 +1,358 @@ > > > +/* DO NOT EDIT: Autogenerated by riscv-canonicalize-syscall-gen.py > > > + > > > + Copyright (C) 2024-2025 Free Software Foundation, Inc. > > > + > > > + This file is part of GDB. > > > + > > > + This program is free software; you can redistribute it and/or mod= ify > > > + 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 . */ > > > + > > > +#include "defs.h" > > > +#include "riscv-linux-tdep.h" > > > + > > > +/* riscv64_canonicalize_syscall maps from the native riscv 64 Linux = set > > > + of syscall ids into a canonical set of syscall ids used by > > > + process record. */ > > > + > > > +enum gdb_syscall > > > +riscv64_canonicalize_syscall (int syscall) > > > +{ > > > + switch (syscall) > > > + { > > > + case 0: return gdb_sys_io_setup; > > > + case 1: return gdb_sys_io_destroy; > > > + case 2: return gdb_sys_io_submit; > > > + case 3: return gdb_sys_io_cancel; > > > + case 4: return gdb_sys_io_getevents; > > > + case 5: return gdb_sys_setxattr; > > > + case 6: return gdb_sys_lsetxattr; > > > + case 7: return gdb_sys_fsetxattr; > > > + case 8: return gdb_sys_getxattr; > > > + case 9: return gdb_sys_lgetxattr; > > > + case 10: return gdb_sys_fgetxattr; > > > + case 11: return gdb_sys_listxattr; > > > + case 12: return gdb_sys_llistxattr; > > > + case 13: return gdb_sys_flistxattr; > > > + case 14: return gdb_sys_removexattr; > > > + case 15: return gdb_sys_lremovexattr; > > > + case 16: return gdb_sys_fremovexattr; > > > + case 17: return gdb_sys_getcwd; > > > + case 18: return gdb_sys_lookup_dcookie; > > > + case 19: return gdb_sys_eventfd2; > > > + case 20: return gdb_sys_epoll_create1; > > > + case 21: return gdb_sys_epoll_ctl; > > > + case 22: return gdb_sys_epoll_pwait; > > > + case 23: return gdb_sys_dup; > > > + case 24: return gdb_sys_dup3; > > > + case 25: return gdb_sys_fcntl; > > > + case 26: return gdb_sys_inotify_init1; > > > + case 27: return gdb_sys_inotify_add_watch; > > > + case 28: return gdb_sys_inotify_rm_watch; > > > + case 29: return gdb_sys_ioctl; > > > + case 30: return gdb_sys_ioprio_set; > > > + case 31: return gdb_sys_ioprio_get; > > > + case 32: return gdb_sys_flock; > > > + case 33: return gdb_sys_mknodat; > > > + case 34: return gdb_sys_mkdirat; > > > + case 35: return gdb_sys_unlinkat; > > > + case 36: return gdb_sys_symlinkat; > > > + case 37: return gdb_sys_linkat; > > > + /* case 39: return gdb_sys_umount2; */ > > > + case 40: return gdb_sys_mount; > > > + case 41: return gdb_sys_pivot_root; > > > + case 42: return gdb_sys_nfsservctl; > > > + case 43: return gdb_sys_statfs; > > > + case 44: return gdb_sys_fstatfs; > > > + case 45: return gdb_sys_truncate; > > > + case 46: return gdb_sys_ftruncate; > > > + case 47: return gdb_sys_fallocate; > > > + case 48: return gdb_sys_faccessat; > > > + case 49: return gdb_sys_chdir; > > > + case 50: return gdb_sys_fchdir; > > > + case 51: return gdb_sys_chroot; > > > + case 52: return gdb_sys_fchmod; > > > + case 53: return gdb_sys_fchmodat; > > > + case 54: return gdb_sys_fchownat; > > > + case 55: return gdb_sys_fchown; > > > + case 56: return gdb_sys_openat; > > > + case 57: return gdb_sys_close; > > > + case 58: return gdb_sys_vhangup; > > > + case 59: return gdb_sys_pipe2; > > > + case 60: return gdb_sys_quotactl; > > > + case 61: return gdb_sys_getdents64; > > > + case 62: return gdb_sys_lseek; > > > + case 63: return gdb_sys_read; > > > + case 64: return gdb_sys_write; > > > + case 65: return gdb_sys_readv; > > > + case 66: return gdb_sys_writev; > > > + case 67: return gdb_sys_pread64; > > > + case 68: return gdb_sys_pwrite64; > > > + /* case 69: return gdb_sys_preadv; */ > > > + /* case 70: return gdb_sys_pwritev; */ > > > + case 71: return gdb_sys_sendfile; > > > + case 72: return gdb_sys_pselect6; > > > + case 73: return gdb_sys_ppoll; > > > + /* case 74: return gdb_sys_signalfd4; */ > > > + case 75: return gdb_sys_vmsplice; > > > + case 76: return gdb_sys_splice; > > > + case 77: return gdb_sys_tee; > > > + case 78: return gdb_sys_readlinkat; > > > + case 79: return gdb_sys_newfstatat; > > > + case 80: return gdb_sys_fstat; > > > + case 81: return gdb_sys_sync; > > > + case 82: return gdb_sys_fsync; > > > + case 83: return gdb_sys_fdatasync; > > > + case 84: return gdb_sys_sync_file_range; > > > + /* case 85: return gdb_sys_timerfd_create; */ > > > + /* case 86: return gdb_sys_timerfd_settime; */ > > > + /* case 87: return gdb_sys_timerfd_gettime; */ > > > + /* case 88: return gdb_sys_utimensat; */ > > > + case 89: return gdb_sys_acct; > > > + case 90: return gdb_sys_capget; > > > + case 91: return gdb_sys_capset; > > > + case 92: return gdb_sys_personality; > > > + case 93: return gdb_sys_exit; > > > + case 94: return gdb_sys_exit_group; > > > + case 95: return gdb_sys_waitid; > > > + case 96: return gdb_sys_set_tid_address; > > > + case 97: return gdb_sys_unshare; > > > + case 98: return gdb_sys_futex; > > > + case 99: return gdb_sys_set_robust_list; > > > + case 100: return gdb_sys_get_robust_list; > > > + case 101: return gdb_sys_nanosleep; > > > + case 102: return gdb_sys_getitimer; > > > + case 103: return gdb_sys_setitimer; > > > + case 104: return gdb_sys_kexec_load; > > > + case 105: return gdb_sys_init_module; > > > + case 106: return gdb_sys_delete_module; > > > + case 107: return gdb_sys_timer_create; > > > + case 108: return gdb_sys_timer_gettime; > > > + case 109: return gdb_sys_timer_getoverrun; > > > + case 110: return gdb_sys_timer_settime; > > > + case 111: return gdb_sys_timer_delete; > > > + case 112: return gdb_sys_clock_settime; > > > + case 113: return gdb_sys_clock_gettime; > > > + case 114: return gdb_sys_clock_getres; > > > + case 115: return gdb_sys_clock_nanosleep; > > > + case 116: return gdb_sys_syslog; > > > + case 117: return gdb_sys_ptrace; > > > + case 118: return gdb_sys_sched_setparam; > > > + case 119: return gdb_sys_sched_setscheduler; > > > + case 120: return gdb_sys_sched_getscheduler; > > > + case 121: return gdb_sys_sched_getparam; > > > + case 122: return gdb_sys_sched_setaffinity; > > > + case 123: return gdb_sys_sched_getaffinity; > > > + case 124: return gdb_sys_sched_yield; > > > + case 125: return gdb_sys_sched_get_priority_max; > > > + case 126: return gdb_sys_sched_get_priority_min; > > > + case 127: return gdb_sys_sched_rr_get_interval; > > > + case 128: return gdb_sys_restart_syscall; > > > + case 129: return gdb_sys_kill; > > > + case 130: return gdb_sys_tkill; > > > + case 131: return gdb_sys_tgkill; > > > + case 132: return gdb_sys_sigaltstack; > > > + case 133: return gdb_sys_rt_sigsuspend; > > > + case 134: return gdb_sys_rt_sigaction; > > > + case 135: return gdb_sys_rt_sigprocmask; > > > + case 136: return gdb_sys_rt_sigpending; > > > + case 137: return gdb_sys_rt_sigtimedwait; > > > + case 138: return gdb_sys_rt_sigqueueinfo; > > > + case 139: return gdb_sys_rt_sigreturn; > > > + case 140: return gdb_sys_setpriority; > > > + case 141: return gdb_sys_getpriority; > > > + case 142: return gdb_sys_reboot; > > > + case 143: return gdb_sys_setregid; > > > + case 144: return gdb_sys_setgid; > > > + case 145: return gdb_sys_setreuid; > > > + case 146: return gdb_sys_setuid; > > > + case 147: return gdb_sys_setresuid; > > > + case 148: return gdb_sys_getresuid; > > > + case 149: return gdb_sys_setresgid; > > > + case 150: return gdb_sys_getresgid; > > > + case 151: return gdb_sys_setfsuid; > > > + case 152: return gdb_sys_setfsgid; > > > + case 153: return gdb_sys_times; > > > + case 154: return gdb_sys_setpgid; > > > + case 155: return gdb_sys_getpgid; > > > + case 156: return gdb_sys_getsid; > > > + case 157: return gdb_sys_setsid; > > > + case 158: return gdb_sys_getgroups; > > > + case 159: return gdb_sys_setgroups; > > > + case 160: return gdb_sys_uname; > > > + case 161: return gdb_sys_sethostname; > > > + case 162: return gdb_sys_setdomainname; > > > + case 163: return gdb_sys_getrlimit; > > > + case 164: return gdb_sys_setrlimit; > > > + case 165: return gdb_sys_getrusage; > > > + case 166: return gdb_sys_umask; > > > + case 167: return gdb_sys_prctl; > > > + case 168: return gdb_sys_getcpu; > > > + case 169: return gdb_sys_gettimeofday; > > > + case 170: return gdb_sys_settimeofday; > > > + case 171: return gdb_sys_adjtimex; > > > + case 172: return gdb_sys_getpid; > > > + case 173: return gdb_sys_getppid; > > > + case 174: return gdb_sys_getuid; > > > + case 175: return gdb_sys_geteuid; > > > + case 176: return gdb_sys_getgid; > > > + case 177: return gdb_sys_getegid; > > > + case 178: return gdb_sys_gettid; > > > + case 179: return gdb_sys_sysinfo; > > > + case 180: return gdb_sys_mq_open; > > > + case 181: return gdb_sys_mq_unlink; > > > + case 182: return gdb_sys_mq_timedsend; > > > + case 183: return gdb_sys_mq_timedreceive; > > > + case 184: return gdb_sys_mq_notify; > > > + case 185: return gdb_sys_mq_getsetattr; > > > + case 186: return gdb_sys_msgget; > > > + case 187: return gdb_sys_msgctl; > > > + case 188: return gdb_sys_msgrcv; > > > + case 189: return gdb_sys_msgsnd; > > > + case 190: return gdb_sys_semget; > > > + case 191: return gdb_sys_semctl; > > > + case 192: return gdb_sys_semtimedop; > > > + case 193: return gdb_sys_semop; > > > + case 194: return gdb_sys_shmget; > > > + case 195: return gdb_sys_shmctl; > > > + case 196: return gdb_sys_shmat; > > > + case 197: return gdb_sys_shmdt; > > > + case 198: return gdb_sys_socket; > > > + case 199: return gdb_sys_socketpair; > > > + case 200: return gdb_sys_bind; > > > + case 201: return gdb_sys_listen; > > > + case 202: return gdb_sys_accept; > > > + case 203: return gdb_sys_connect; > > > + case 204: return gdb_sys_getsockname; > > > + case 205: return gdb_sys_getpeername; > > > + case 206: return gdb_sys_sendto; > > > + case 207: return gdb_sys_recvfrom; > > > + case 208: return gdb_sys_setsockopt; > > > + case 209: return gdb_sys_getsockopt; > > > + case 210: return gdb_sys_shutdown; > > > + case 211: return gdb_sys_sendmsg; > > > + case 212: return gdb_sys_recvmsg; > > > + case 213: return gdb_sys_readahead; > > > + case 214: return gdb_sys_brk; > > > + case 215: return gdb_sys_munmap; > > > + case 216: return gdb_sys_mremap; > > > + case 217: return gdb_sys_add_key; > > > + case 218: return gdb_sys_request_key; > > > + case 219: return gdb_sys_keyctl; > > > + case 220: return gdb_sys_clone; > > > + case 221: return gdb_sys_execve; > > > + case 222: return gdb_old_mmap; > > > + case 223: return gdb_sys_fadvise64; > > > + case 224: return gdb_sys_swapon; > > > + case 225: return gdb_sys_swapoff; > > > + case 226: return gdb_sys_mprotect; > > > + case 227: return gdb_sys_msync; > > > + case 228: return gdb_sys_mlock; > > > + case 229: return gdb_sys_munlock; > > > + case 230: return gdb_sys_mlockall; > > > + case 231: return gdb_sys_munlockall; > > > + case 232: return gdb_sys_mincore; > > > + case 233: return gdb_sys_madvise; > > > + case 234: return gdb_sys_remap_file_pages; > > > + case 235: return gdb_sys_mbind; > > > + case 236: return gdb_sys_get_mempolicy; > > > + case 237: return gdb_sys_set_mempolicy; > > > + case 238: return gdb_sys_migrate_pages; > > > + case 239: return gdb_sys_move_pages; > > > + /* case 240: return gdb_sys_rt_tgsigqueueinfo; */ > > > + /* case 241: return gdb_sys_perf_event_open; */ > > > + case 242: return gdb_sys_accept4; > > > + /* case 243: return gdb_sys_recvmmsg; */ > > > + /* case 258: return gdb_sys_riscv_hwprobe; */ > > > + /* case 259: return gdb_sys_riscv_flush_icache; */ > > > + case 260: return gdb_sys_wait4; > > > + /* case 261: return gdb_sys_prlimit64; */ > > > + /* case 262: return gdb_sys_fanotify_init; */ > > > + /* case 263: return gdb_sys_fanotify_mark; */ > > > + /* case 264: return gdb_sys_name_to_handle_at; */ > > > + /* case 265: return gdb_sys_open_by_handle_at; */ > > > + /* case 266: return gdb_sys_clock_adjtime; */ > > > + /* case 267: return gdb_sys_syncfs; */ > > > + /* case 268: return gdb_sys_setns; */ > > > + /* case 269: return gdb_sys_sendmmsg; */ > > > + /* case 270: return gdb_sys_process_vm_readv; */ > > > + /* case 271: return gdb_sys_process_vm_writev; */ > > > + /* case 272: return gdb_sys_kcmp; */ > > > + /* case 273: return gdb_sys_finit_module; */ > > > + /* case 274: return gdb_sys_sched_setattr; */ > > > + /* case 275: return gdb_sys_sched_getattr; */ > > > + /* case 276: return gdb_sys_renameat2; */ > > > + /* case 277: return gdb_sys_seccomp; */ > > > + case 278: return gdb_sys_getrandom; > > > + /* case 279: return gdb_sys_memfd_create; */ > > > + /* case 280: return gdb_sys_bpf; */ > > > + /* case 281: return gdb_sys_execveat; */ > > > + /* case 282: return gdb_sys_userfaultfd; */ > > > + /* case 283: return gdb_sys_membarrier; */ > > > + /* case 284: return gdb_sys_mlock2; */ > > > + /* case 285: return gdb_sys_copy_file_range; */ > > > + /* case 286: return gdb_sys_preadv2; */ > > > + /* case 287: return gdb_sys_pwritev2; */ > > > + /* case 288: return gdb_sys_pkey_mprotect; */ > > > + /* case 289: return gdb_sys_pkey_alloc; */ > > > + /* case 290: return gdb_sys_pkey_free; */ > > > + case 291: return gdb_sys_statx; > > > + /* case 292: return gdb_sys_io_pgetevents; */ > > > + /* case 293: return gdb_sys_rseq; */ > > > + /* case 294: return gdb_sys_kexec_file_load; */ > > > + /* case 424: return gdb_sys_pidfd_send_signal; */ > > > + /* case 425: return gdb_sys_io_uring_setup; */ > > > + /* case 426: return gdb_sys_io_uring_enter; */ > > > + /* case 427: return gdb_sys_io_uring_register; */ > > > + /* case 428: return gdb_sys_open_tree; */ > > > + /* case 429: return gdb_sys_move_mount; */ > > > + /* case 430: return gdb_sys_fsopen; */ > > > + /* case 431: return gdb_sys_fsconfig; */ > > > + /* case 432: return gdb_sys_fsmount; */ > > > + /* case 433: return gdb_sys_fspick; */ > > > + /* case 434: return gdb_sys_pidfd_open; */ > > > + /* case 435: return gdb_sys_clone3; */ > > > + /* case 436: return gdb_sys_close_range; */ > > > + /* case 437: return gdb_sys_openat2; */ > > > + /* case 438: return gdb_sys_pidfd_getfd; */ > > > + /* case 439: return gdb_sys_faccessat2; */ > > > + /* case 440: return gdb_sys_process_madvise; */ > > > + /* case 441: return gdb_sys_epoll_pwait2; */ > > > + /* case 442: return gdb_sys_mount_setattr; */ > > > + /* case 443: return gdb_sys_quotactl_fd; */ > > > + /* case 444: return gdb_sys_landlock_create_ruleset; */ > > > + /* case 445: return gdb_sys_landlock_add_rule; */ > > > + /* case 446: return gdb_sys_landlock_restrict_self; */ > > > + /* case 447: return gdb_sys_memfd_secret; */ > > > + /* case 448: return gdb_sys_process_mrelease; */ > > > + /* case 449: return gdb_sys_futex_waitv; */ > > > + /* case 450: return gdb_sys_set_mempolicy_home_node; */ > > > + /* case 451: return gdb_sys_cachestat; */ > > > + /* case 452: return gdb_sys_fchmodat2; */ > > > + /* case 453: return gdb_sys_map_shadow_stack; */ > > > + /* case 454: return gdb_sys_futex_wake; */ > > > + /* case 455: return gdb_sys_futex_wait; */ > > > + /* case 456: return gdb_sys_futex_requeue; */ > > > + /* case 457: return gdb_sys_statmount; */ > > > + /* case 458: return gdb_sys_listmount; */ > > > + /* case 459: return gdb_sys_lsm_get_self_attr; */ > > > + /* case 460: return gdb_sys_lsm_set_self_attr; */ > > > + /* case 461: return gdb_sys_lsm_list_modules; */ > > > + /* case 462: return gdb_sys_mseal; */ > > > + /* case 463: return gdb_sys_setxattrat; */ > > > + /* case 464: return gdb_sys_getxattrat; */ > > > + /* case 465: return gdb_sys_listxattrat; */ > > > + /* case 466: return gdb_sys_removexattrat; */ > > > + default: > > > + return gdb_sys_no_syscall; > > > + } > > > +} > > > diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c > > > index 4c0c65c1457..f21039a613c 100644 > > > --- a/gdb/riscv-linux-tdep.c > > > +++ b/gdb/riscv-linux-tdep.c > > > @@ -25,6 +25,11 @@ > > > #include "tramp-frame.h" > > > #include "trad-frame.h" > > > #include "gdbarch.h" > > > +#include "record-full.h" > > > +#include "linux-record.h" > > > +#include "riscv-linux-tdep.h" > > > + > > > +extern unsigned int record_debug; > > > > > > /* The following value is derived from __NR_rt_sigreturn in > > > from the Linux source tree. = */ > > > @@ -173,6 +178,254 @@ riscv_linux_syscall_next_pc (const frame_info_p= tr &frame) > > > return pc + 4 /* Length of the ECALL insn. */; > > > } > > > > > > +/* RISC-V process record-replay constructs: syscall, signal etc. */ > > > + > > > +static linux_record_tdep riscv_linux_record_tdep; > > > + > > > +using regnum_type =3D int; > > > + > > > +/* Record registers from first to last for process-record. */ > > > + > > > +static bool > > > +save_registers (struct regcache *regcache, regnum_type first, regnum= _type last) > > > +{ > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + for (regnum_type i =3D first; i !=3D last; ++i) > > > + if (record_full_arch_list_add_reg (regcache, i)) > > > + return false; > > > + return true; > > > +}; > > > + > > > +/* Record all registers but PC register for process-record. */ > > > + > > > +static bool > > > +riscv_all_but_pc_registers_record (struct regcache *regcache) > > > +{ > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + struct gdbarch *gdbarch =3D regcache->arch (); > > > + riscv_gdbarch_tdep *tdep =3D gdbarch_tdep (gdb= arch); > > > + const struct riscv_gdbarch_features &features =3D tdep->isa_featur= es; > > > + > > > + if (!save_registers (regcache, RISCV_ZERO_REGNUM + 1, RISCV_PC_REG= NUM)) > > > + return false; > > > + > > > + if (features.flen > > > + && !save_registers (regcache, RISCV_FIRST_FP_REGNUM, > > > + RISCV_LAST_FP_REGNUM + 1)) > > > + return false; > > > + > > > + return true; > > > +} > > > + > > > +/* Handler for riscv system call instruction recording. */ > > > + > > > +static int > > > +riscv_linux_syscall_record (struct regcache *regcache, > > > + unsigned long svc_number) > > > +{ > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + enum gdb_syscall syscall_gdb =3D riscv64_canonicalize_syscall (svc= _number); > > > + > > > + if (record_debug > 1) > > > + gdb_printf (gdb_stdlog, "Made syscall %s.\n", plongest (svc_numb= er)); > > > + > > > + if (syscall_gdb =3D=3D gdb_sys_no_syscall) > > > + { > > > + warning (_("Process record and replay target doesn't " > > > + "support syscall number %s\n"), plongest (svc_number))= ; > > > + return -1; > > > + } > > > + > > > + if (syscall_gdb =3D=3D gdb_sys_sigreturn || syscall_gdb =3D=3D gdb= _sys_rt_sigreturn) > > > + { > > > + if (!riscv_all_but_pc_registers_record (regcache)) > > > + return -1; > > > + return 0; > > > + } > > > + > > > + int ret =3D record_linux_system_call (syscall_gdb, regcache, > > > + &riscv_linux_record_tdep); > > > + if (ret !=3D 0) > > > + return ret; > > > + > > > + /* Record the return value of the system call. */ > > > + if (record_full_arch_list_add_reg (regcache, RISCV_A0_REGNUM)) > > > + return -1; > > > + > > > + return 0; > > > +} > > > + > > > +/* Initialize the riscv64_linux_record_tdep. */ > > > + > > > +static void > > > +riscv64_linux_record_tdep_init (struct gdbarch *gdbarch, > > > + struct linux_record_tdep & > > > + riscv_linux_record_tdep) > > > +{ > > > + gdb_assert (gdbarch !=3D nullptr); > > > + > > > + /* These values are the size of the type that > > > + will be used in a system call. */ > > > + riscv_linux_record_tdep.size_pointer > > > + =3D gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT; > > > + riscv_linux_record_tdep.size__old_kernel_stat =3D 48; > > > + riscv_linux_record_tdep.size_tms =3D 32; > > > + riscv_linux_record_tdep.size_loff_t =3D 8; > > > + riscv_linux_record_tdep.size_flock =3D 32; > > > + riscv_linux_record_tdep.size_oldold_utsname =3D 45; > > > + riscv_linux_record_tdep.size_ustat =3D 32; > > > + riscv_linux_record_tdep.size_old_sigaction =3D 32; > > > + riscv_linux_record_tdep.size_old_sigset_t =3D 8; > > > + riscv_linux_record_tdep.size_rlimit =3D 16; > > > + riscv_linux_record_tdep.size_rusage =3D 144; > > > + riscv_linux_record_tdep.size_timeval =3D 8; > > > + riscv_linux_record_tdep.size_timezone =3D 8; > > > + riscv_linux_record_tdep.size_old_gid_t =3D 2; > > > + riscv_linux_record_tdep.size_old_uid_t =3D 2; > > > + riscv_linux_record_tdep.size_fd_set =3D 128; > > > + riscv_linux_record_tdep.size_old_dirent =3D 268; > > > + riscv_linux_record_tdep.size_statfs =3D 120; > > > + riscv_linux_record_tdep.size_statfs64 =3D 120; > > > + riscv_linux_record_tdep.size_sockaddr =3D 16; > > > + riscv_linux_record_tdep.size_int > > > + =3D gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT; > > > + riscv_linux_record_tdep.size_long > > > + =3D gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT; > > > + riscv_linux_record_tdep.size_ulong > > > + =3D gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT; > > > + riscv_linux_record_tdep.size_msghdr =3D 104; > > > + riscv_linux_record_tdep.size_itimerval =3D 16; > > > + riscv_linux_record_tdep.size_stat =3D 128; > > > + riscv_linux_record_tdep.size_old_utsname =3D 325; > > > + riscv_linux_record_tdep.size_sysinfo =3D 112; > > > + riscv_linux_record_tdep.size_msqid_ds =3D 104; > > > + riscv_linux_record_tdep.size_shmid_ds =3D 88; > > > + riscv_linux_record_tdep.size_new_utsname =3D 390; > > > + riscv_linux_record_tdep.size_timex =3D 188; > > > + riscv_linux_record_tdep.size_mem_dqinfo =3D 72; > > > + riscv_linux_record_tdep.size_if_dqblk =3D 68; > > > + riscv_linux_record_tdep.size_fs_quota_stat =3D 64; > > > + riscv_linux_record_tdep.size_timespec =3D 16; > > > + riscv_linux_record_tdep.size_pollfd =3D 8; > > > + riscv_linux_record_tdep.size_NFS_FHSIZE =3D 32; > > > + riscv_linux_record_tdep.size_knfsd_fh =3D 36; > > > + riscv_linux_record_tdep.size_TASK_COMM_LEN =3D 4; > > > + riscv_linux_record_tdep.size_sigaction =3D 24; > > > + riscv_linux_record_tdep.size_sigset_t =3D 8; > > > + riscv_linux_record_tdep.size_siginfo_t =3D 128; > > > + riscv_linux_record_tdep.size_cap_user_data_t =3D 8; > > > + riscv_linux_record_tdep.size_stack_t =3D 24; > > > + riscv_linux_record_tdep.size_off_t =3D riscv_linux_record_tdep.siz= e_long; > > > + riscv_linux_record_tdep.size_stat64 =3D 136; > > > + riscv_linux_record_tdep.size_gid_t =3D 4; > > > + riscv_linux_record_tdep.size_uid_t =3D 4; > > > + riscv_linux_record_tdep.size_PAGE_SIZE =3D 4096; > > > + riscv_linux_record_tdep.size_flock64 =3D 32; > > > + riscv_linux_record_tdep.size_user_desc =3D 37; > > > + riscv_linux_record_tdep.size_io_event =3D 32; > > > + riscv_linux_record_tdep.size_iocb =3D 64; > > > + riscv_linux_record_tdep.size_epoll_event =3D 16; > > > + riscv_linux_record_tdep.size_itimerspec > > > + =3D riscv_linux_record_tdep.size_timespec * 2; > > > + riscv_linux_record_tdep.size_mq_attr =3D 64; > > > + riscv_linux_record_tdep.size_termios =3D 36; > > > + riscv_linux_record_tdep.size_termios2 =3D 44; > > > + riscv_linux_record_tdep.size_pid_t =3D 4; > > > + riscv_linux_record_tdep.size_winsize =3D 8; > > > + riscv_linux_record_tdep.size_serial_struct =3D 72; > > > + riscv_linux_record_tdep.size_serial_icounter_struct =3D 80; > > > + riscv_linux_record_tdep.size_hayes_esp_config =3D 12; > > > + riscv_linux_record_tdep.size_size_t =3D 8; > > > + riscv_linux_record_tdep.size_iovec =3D 16; > > > + riscv_linux_record_tdep.size_time_t =3D 8; > > > + > > > + /* These values are the second argument of system call "sys_ioctl"= . > > > + They are obtained from Linux Kernel source. */ > > > + riscv_linux_record_tdep.ioctl_TCGETS =3D 0x5401; > > > + riscv_linux_record_tdep.ioctl_TCSETS =3D 0x5402; > > > + riscv_linux_record_tdep.ioctl_TCSETSW =3D 0x5403; > > > + riscv_linux_record_tdep.ioctl_TCSETSF =3D 0x5404; > > > + riscv_linux_record_tdep.ioctl_TCGETA =3D 0x5405; > > > + riscv_linux_record_tdep.ioctl_TCSETA =3D 0x5406; > > > + riscv_linux_record_tdep.ioctl_TCSETAW =3D 0x5407; > > > + riscv_linux_record_tdep.ioctl_TCSETAF =3D 0x5408; > > > + riscv_linux_record_tdep.ioctl_TCSBRK =3D 0x5409; > > > + riscv_linux_record_tdep.ioctl_TCXONC =3D 0x540a; > > > + riscv_linux_record_tdep.ioctl_TCFLSH =3D 0x540b; > > > + riscv_linux_record_tdep.ioctl_TIOCEXCL =3D 0x540c; > > > + riscv_linux_record_tdep.ioctl_TIOCNXCL =3D 0x540d; > > > + riscv_linux_record_tdep.ioctl_TIOCSCTTY =3D 0x540e; > > > + riscv_linux_record_tdep.ioctl_TIOCGPGRP =3D 0x540f; > > > + riscv_linux_record_tdep.ioctl_TIOCSPGRP =3D 0x5410; > > > + riscv_linux_record_tdep.ioctl_TIOCOUTQ =3D 0x5411; > > > + riscv_linux_record_tdep.ioctl_TIOCSTI =3D 0x5412; > > > + riscv_linux_record_tdep.ioctl_TIOCGWINSZ =3D 0x5413; > > > + riscv_linux_record_tdep.ioctl_TIOCSWINSZ =3D 0x5414; > > > + riscv_linux_record_tdep.ioctl_TIOCMGET =3D 0x5415; > > > + riscv_linux_record_tdep.ioctl_TIOCMBIS =3D 0x5416; > > > + riscv_linux_record_tdep.ioctl_TIOCMBIC =3D 0x5417; > > > + riscv_linux_record_tdep.ioctl_TIOCMSET =3D 0x5418; > > > + riscv_linux_record_tdep.ioctl_TIOCGSOFTCAR =3D 0x5419; > > > + riscv_linux_record_tdep.ioctl_TIOCSSOFTCAR =3D 0x541a; > > > + riscv_linux_record_tdep.ioctl_FIONREAD =3D 0x541b; > > > + riscv_linux_record_tdep.ioctl_TIOCINQ > > > + =3D riscv_linux_record_tdep.ioctl_FIONREAD; > > > + riscv_linux_record_tdep.ioctl_TIOCLINUX =3D 0x541c; > > > + riscv_linux_record_tdep.ioctl_TIOCCONS =3D 0x541d; > > > + riscv_linux_record_tdep.ioctl_TIOCGSERIAL =3D 0x541e; > > > + riscv_linux_record_tdep.ioctl_TIOCSSERIAL =3D 0x541f; > > > + riscv_linux_record_tdep.ioctl_TIOCPKT =3D 0x5420; > > > + riscv_linux_record_tdep.ioctl_FIONBIO =3D 0x5421; > > > + riscv_linux_record_tdep.ioctl_TIOCNOTTY =3D 0x5422; > > > + riscv_linux_record_tdep.ioctl_TIOCSETD =3D 0x5423; > > > + riscv_linux_record_tdep.ioctl_TIOCGETD =3D 0x5424; > > > + riscv_linux_record_tdep.ioctl_TCSBRKP =3D 0x5425; > > > + riscv_linux_record_tdep.ioctl_TIOCTTYGSTRUCT =3D 0x5426; > > > + riscv_linux_record_tdep.ioctl_TIOCSBRK =3D 0x5427; > > > + riscv_linux_record_tdep.ioctl_TIOCCBRK =3D 0x5428; > > > + riscv_linux_record_tdep.ioctl_TIOCGSID =3D 0x5429; > > > + riscv_linux_record_tdep.ioctl_TCGETS2 =3D 0x802c542a; > > > + riscv_linux_record_tdep.ioctl_TCSETS2 =3D 0x402c542b; > > > + riscv_linux_record_tdep.ioctl_TCSETSW2 =3D 0x402c542c; > > > + riscv_linux_record_tdep.ioctl_TCSETSF2 =3D 0x402c542d; > > > + riscv_linux_record_tdep.ioctl_TIOCGPTN =3D 0x80045430; > > > + riscv_linux_record_tdep.ioctl_TIOCSPTLCK =3D 0x40045431; > > > + riscv_linux_record_tdep.ioctl_FIONCLEX =3D 0x5450; > > > + riscv_linux_record_tdep.ioctl_FIOCLEX =3D 0x5451; > > > + riscv_linux_record_tdep.ioctl_FIOASYNC =3D 0x5452; > > > + riscv_linux_record_tdep.ioctl_TIOCSERCONFIG =3D 0x5453; > > > + riscv_linux_record_tdep.ioctl_TIOCSERGWILD =3D 0x5454; > > > + riscv_linux_record_tdep.ioctl_TIOCSERSWILD =3D 0x5455; > > > + riscv_linux_record_tdep.ioctl_TIOCGLCKTRMIOS =3D 0x5456; > > > + riscv_linux_record_tdep.ioctl_TIOCSLCKTRMIOS =3D 0x5457; > > > + riscv_linux_record_tdep.ioctl_TIOCSERGSTRUCT =3D 0x5458; > > > + riscv_linux_record_tdep.ioctl_TIOCSERGETLSR =3D 0x5459; > > > + riscv_linux_record_tdep.ioctl_TIOCSERGETMULTI =3D 0x545a; > > > + riscv_linux_record_tdep.ioctl_TIOCSERSETMULTI =3D 0x545b; > > > + riscv_linux_record_tdep.ioctl_TIOCMIWAIT =3D 0x545c; > > > + riscv_linux_record_tdep.ioctl_TIOCGICOUNT =3D 0x545d; > > > + riscv_linux_record_tdep.ioctl_TIOCGHAYESESP =3D 0x545e; > > > + riscv_linux_record_tdep.ioctl_TIOCSHAYESESP =3D 0x545f; > > > + riscv_linux_record_tdep.ioctl_FIOQSIZE =3D 0x5460; > > > + > > > + /* These values are the second argument of system call "sys_fcntl" > > > + and "sys_fcntl64". They are obtained from Linux Kernel source.= */ > > > + riscv_linux_record_tdep.fcntl_F_GETLK =3D 5; > > > + riscv_linux_record_tdep.fcntl_F_GETLK64 =3D 12; > > > + riscv_linux_record_tdep.fcntl_F_SETLK64 =3D 13; > > > + riscv_linux_record_tdep.fcntl_F_SETLKW64 =3D 14; > > > + > > > + riscv_linux_record_tdep.arg1 =3D RISCV_A0_REGNUM; > > > + riscv_linux_record_tdep.arg2 =3D RISCV_A1_REGNUM; > > > + riscv_linux_record_tdep.arg3 =3D RISCV_A2_REGNUM; > > > + riscv_linux_record_tdep.arg4 =3D RISCV_A3_REGNUM; > > > + riscv_linux_record_tdep.arg5 =3D RISCV_A4_REGNUM; > > > + riscv_linux_record_tdep.arg6 =3D RISCV_A5_REGNUM; > > > +} > > > + > > > /* Initialize RISC-V Linux ABI info. */ > > > > > > static void > > > @@ -205,6 +458,9 @@ riscv_linux_init_abi (struct gdbarch_info info, s= truct gdbarch *gdbarch) > > > tramp_frame_prepend_unwinder (gdbarch, &riscv_linux_sigframe); > > > > > > tdep->syscall_next_pc =3D riscv_linux_syscall_next_pc; > > > + tdep->riscv_syscall_record =3D riscv_linux_syscall_record; > > > + > > > + riscv64_linux_record_tdep_init (gdbarch, riscv_linux_record_tdep); > > > } > > > > > > /* Initialize RISC-V Linux target support. */ > > > diff --git a/gdb/riscv-linux-tdep.h b/gdb/riscv-linux-tdep.h > > > new file mode 100644 > > > index 00000000000..9dd9e373caa > > > --- /dev/null > > > +++ b/gdb/riscv-linux-tdep.h > > > @@ -0,0 +1,29 @@ > > > +/* Copyright (C) 2024-2025 Free Software Foundation, Inc. > > > + > > > + This file is part of GDB. > > > + > > > + This program is free software; you can redistribute it and/or mod= ify > > > + 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 . */ > > > + > > > +#ifndef GDB_RISCV_LINUX_TDEP_H > > > +#define GDB_RISCV_LINUX_TDEP_H > > > + > > > +#include "linux-record.h" > > > + > > > +/* riscv64_canonicalize_syscall maps from the native riscv Linux set > > > + of syscall ids into a canonical set of syscall ids used by > > > + process record. */ > > > + > > > +extern enum gdb_syscall riscv64_canonicalize_syscall (int syscall); > > > + > > > +#endif /* GDB_RISCV_LINUX_TDEP_H */ > > > diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c > > > index 91f6dffebe1..19367ff55ba 100644 > > > --- a/gdb/riscv-tdep.c > > > +++ b/gdb/riscv-tdep.c > > > @@ -54,9 +54,12 @@ > > > #include "observable.h" > > > #include "prologue-value.h" > > > #include "arch/riscv.h" > > > +#include "record-full.h" > > > #include "riscv-ravenscar-thread.h" > > > #include "gdbsupport/gdb-safe-ctype.h" > > > > > > +#include > > > + > > > /* The stack must be 16-byte aligned. */ > > > #define SP_ALIGNMENT 16 > > > > > > @@ -1669,6 +1672,11 @@ class riscv_insn > > > int imm_signed () const > > > { return m_imm.s; } > > > > > > + /* Fetch instruction from target memory at ADDR, return the conten= t of > > > + the instruction, and update LEN with the instruction length. *= / > > > + static ULONGEST fetch_instruction (struct gdbarch *gdbarch, > > > + CORE_ADDR addr, int *len); > > > + > > > private: > > > > > > /* Extract 5 bit register field at OFFSET from instruction OPCODE.= */ > > > @@ -1814,11 +1822,6 @@ class riscv_insn > > > m_rs2 =3D decode_register_index_short (ival, OP_SH_CRS2S); > > > } > > > > > > - /* Fetch instruction from target memory at ADDR, return the conten= t of > > > - the instruction, and update LEN with the instruction length. *= / > > > - static ULONGEST fetch_instruction (struct gdbarch *gdbarch, > > > - CORE_ADDR addr, int *len); > > > - > > > /* The length of the instruction in bytes. Should be 2 or 4. */ > > > int m_length; > > > > > > @@ -4433,6 +4436,9 @@ riscv_gdbarch_init (struct gdbarch_info info, > > > set_gdbarch_stap_register_indirection_suffixes > > > (gdbarch, stap_register_indirection_suffixes); > > > > > > + /* Process record-replay */ > > > + set_gdbarch_process_record (gdbarch, riscv_process_record); > > > + > > > /* Hook in OS ABI-specific overrides, if they have been registered= . */ > > > gdbarch_init_osabi (info, gdbarch); > > > > > > @@ -4866,3 +4872,673 @@ equivalent change in the disassembler output.= "), > > > &setriscvcmdlist, > > > &showriscvcmdlist); > > > } > > > + > > > +/* A wrapper to read register under number regnum to address addr. > > > + Returns false if error happened and makes warning. */ > > > + > > > +static bool > > > +try_read (struct regcache *regcache, int regnum, ULONGEST &addr) > > > +{ > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + if (regcache->raw_read (regnum, &addr) > > > + !=3D register_status::REG_VALID) > > > + { > > > + warning (_("Can not read at address %lx"), addr); > > > + return false; > > > + } > > > + return true; > > > +} > > > + > > > +/* Helper class to record instruction. */ > > > + > > > +class riscv_recorded_insn final > > > +{ > > > +public: > > > + /* Type for saved register. */ > > > + using regnum_type =3D int; > > > + /* Type for saved memory. First is address, second is length. */ > > > + using memory_type =3D std::pair; > > > + > > > + /* Enum class that represents which type does recording belong to.= */ > > > + enum class record_type > > > + { > > > + UNKNOWN, > > > + ORDINARY, > > > + > > > + /* Corner cases. */ > > > + ECALL, > > > + EBREAK, > > > + }; > > > + > > > +private: > > > + /* Type for set of registers that need to be saved. */ > > > + using recorded_regs =3D std::vector; > > > + /* Type for set of memory records that need to be saved. */ > > > + using recorded_mems =3D std::vector; > > > + > > > + /* Type for memory address, extracted from memory_type. */ > > > + using mem_addr =3D decltype (std::declval ().first); > > > + /* Type for memory length, extracted from memory_type. */ > > > + using mem_len =3D decltype (std::declval ().second); > > > + > > > + /* Record type of current instruction. */ > > > + record_type m_record_type =3D record_type::UNKNOWN; > > > + > > > + /* Flag that represents was there an error in current recording. = */ > > > + bool m_error_occured =3D false; > > > + > > > + /* Set of registers that need to be recorded. */ > > > + recorded_regs m_regs; > > > + /* Set of memory chunks that need to be recorded. */ > > > + recorded_mems m_mems; > > > + > > > + /* Width in bytes of the general purpose registers for GDBARCH, > > > + where recording is happening. */ > > > + int m_xlen =3D 0; > > > + > > > + /* Helper for decode 16-bit instruction RS1. */ > > > + static regnum_type > > > + decode_crs1_short (ULONGEST opcode) noexcept > > > + { > > > + return ((opcode >> OP_SH_CRS1S) & OP_MASK_CRS1S) + 8; > > > + } > > > + > > > + /* Helper for decode 16-bit instruction RS2. */ > > > + static regnum_type > > > + decode_crs2_short (ULONGEST opcode) noexcept > > > + { > > > + return ((opcode >> OP_SH_CRS2S) & OP_MASK_CRS2S) + 8; > > > + } > > > + > > > + /* Helper for decode 16-bit instruction CRS1. */ > > > + static regnum_type > > > + decode_crs1 (ULONGEST opcode) noexcept > > > + { > > > + return ((opcode >> OP_SH_RD) & OP_MASK_RD); > > > + } > > > + > > > + /* Helper for decode 16-bit instruction CRS2. */ > > > + static regnum_type > > > + decode_crs2 (ULONGEST opcode) noexcept > > > + { > > > + return ((opcode >> OP_SH_CRS2) & OP_MASK_CRS2); > > > + } > > > + > > > + /* Helper for decode 32-bit instruction RD. */ > > > + static regnum_type > > > + decode_rd (ULONGEST ival) noexcept > > > + { > > > + return (ival >> OP_SH_RD) & OP_MASK_RD; > > > + } > > > + > > > + /* Helper for decode 32-bit instruction RS1. */ > > > + static regnum_type > > > + decode_rs1 (ULONGEST ival) noexcept > > > + { > > > + return (ival >> OP_SH_RS1) & OP_MASK_RS1; > > > + } > > > + > > > + /* Helper for decode 32-bit instruction RS2. */ > > > + static regnum_type > > > + decode_rs2 (ULONGEST ival) noexcept > > > + { > > > + return (ival >> OP_SH_RS2) & OP_MASK_RS2; > > > + } > > > + > > > + /* Helper for decode 32-bit instruction CSR. */ > > > + static regnum_type > > > + decode_csr (ULONGEST ival) noexcept > > > + { > > > + return (ival >> OP_SH_CSR) & OP_MASK_CSR; > > > + } > > > + > > > + /* Set ordinary record type. Always returns true. */ > > > + bool > > > + set_ordinary_record_type () noexcept > > > + { > > > + m_record_type =3D record_type::ORDINARY; > > > + return true; > > > + } > > > + > > > + /* Set error happened. Always returns false. */ > > > + bool > > > + set_error () noexcept > > > + { > > > + m_error_occured =3D true; > > > + return false; > > > + } > > > + > > > + /* Check if current recording has an error. */ > > > + bool > > > + has_error () const noexcept > > > + { > > > + return m_error_occured; > > > + } > > > + > > > + /* Reads register. Sets error and returns false if error happened= . */ > > > + bool > > > + read_reg (struct regcache *regcache, regnum_type reg, > > > + ULONGEST &addr) noexcept > > > + { > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + if (!try_read (regcache, reg, addr)) > > > + return set_error (); > > > + return true; > > > + } > > > + > > > + /* Save register. Returns true or aborts if exception happened. = */ > > > + bool > > > + save_reg (regnum_type regnum) noexcept > > > + { > > > + m_regs.emplace_back (regnum); > > > + return true; > > > + } > > > + > > > + /* Save memory chunk. Returns true or aborts if exception happene= d. */ > > > + bool > > > + save_mem (mem_addr addr, mem_len len) noexcept > > > + { > > > + m_mems.emplace_back (addr, len); > > > + return true; > > > + } > > > + > > > + /* Returns true if instruction needs only saving pc. */ > > > + static bool > > > + need_save_pc (ULONGEST ival) noexcept > > > + { > > > + return (is_beq_insn (ival) || is_bne_insn (ival) || is_blt_insn = (ival) > > > + || is_bge_insn (ival) || is_bltu_insn (ival) || is_bgeu_insn= (ival) > > > + || is_fence_insn (ival) || is_pause_insn (ival) > > > + || is_fence_i_insn (ival)); > > > + } > > > + > > > + /* Returns true if instruction is classified. */ > > > + bool > > > + try_save_pc (ULONGEST ival) noexcept > > > + { > > > + if (!need_save_pc (ival)) > > > + return false; > > > + > > > + return set_ordinary_record_type (); > > > + } > > > + > > > + /* Returns true if instruction needs only saving pc and rd. */ > > > + static bool > > > + need_save_pc_rd (ULONGEST ival) noexcept > > > + { > > > + return (is_lui_insn (ival) || is_auipc_insn (ival) || is_jal_ins= n (ival) > > > + || is_jalr_insn (ival) || is_lb_insn (ival) || is_lh_insn (i= val) > > > + || is_lw_insn (ival) || is_lbu_insn (ival) || is_lhu_insn (i= val) > > > + || is_addi_insn (ival) || is_slti_insn (ival) > > > + || is_sltiu_insn (ival) || is_xori_insn (ival) || is_ori_ins= n (ival) > > > + || is_andi_insn (ival) || is_slli_rv32_insn (ival) > > > + || is_srli_rv32_insn (ival) || is_srai_rv32_insn (ival) > > > + || is_add_insn (ival) || is_sub_insn (ival) || is_sll_insn (= ival) > > > + || is_slt_insn (ival) || is_sltu_insn (ival) || is_xor_insn = (ival) > > > + || is_srl_insn (ival) || is_sra_insn (ival) || is_or_insn (i= val) > > > + || is_and_insn (ival) || is_lwu_insn (ival) || is_ld_insn (i= val) > > > + || is_slli_insn (ival) || is_srli_insn (ival) || is_srai_ins= n (ival) > > > + || is_addiw_insn (ival) || is_slliw_insn (ival) > > > + || is_srliw_insn (ival) || is_sraiw_insn (ival) > > > + || is_addw_insn (ival) || is_subw_insn (ival) || is_sllw_ins= n (ival) > > > + || is_srlw_insn (ival) || is_sraw_insn (ival) || is_mul_insn= (ival) > > > + || is_mulh_insn (ival) || is_mulhsu_insn (ival) > > > + || is_mulhu_insn (ival) || is_div_insn (ival) || is_divu_ins= n (ival) > > > + || is_rem_insn (ival) || is_remu_insn (ival) || is_mulw_insn= (ival) > > > + || is_divw_insn (ival) || is_divuw_insn (ival) > > > + || is_remw_insn (ival) || is_remuw_insn (ival) > > > + || is_lr_w_insn (ival) || is_lr_d_insn (ival) > > > + || is_fcvt_w_s_insn (ival) || is_fcvt_wu_s_insn (ival) > > > + || is_fmv_x_s_insn (ival) || is_feq_s_insn (ival) > > > + || is_flt_s_insn (ival) || is_fle_s_insn (ival) > > > + || is_fclass_s_insn (ival) || is_fcvt_l_s_insn (ival) > > > + || is_fcvt_lu_s_insn (ival) || is_feq_d_insn (ival) > > > + || is_flt_d_insn (ival) || is_fle_d_insn (ival) > > > + || is_fclass_d_insn (ival) || is_fcvt_w_d_insn (ival) > > > + || is_fcvt_wu_d_insn (ival) || is_fcvt_l_d_insn (ival) > > > + || is_fcvt_lu_d_insn (ival) || is_fmv_x_d_insn (ival)); > > > + } > > > + > > > + /* Returns true if instruction is classified. This function can s= et > > > + m_error_occured. */ > > > + bool > > > + try_save_pc_rd (ULONGEST ival) noexcept > > > + { > > > + if (!need_save_pc_rd (ival)) > > > + return false; > > > + > > > + return (!save_reg (decode_rd (ival)) || set_ordinary_record_type= ()); > > > + } > > > + > > > + /* Returns true if instruction needs only saving pc and > > > + floating point rd. */ > > > + static bool > > > + need_save_pc_fprd (ULONGEST ival) noexcept > > > + { > > > + return (is_flw_insn (ival) || is_fmadd_s_insn (ival) > > > + || is_fmsub_s_insn (ival) || is_fnmsub_s_insn (ival) > > > + || is_fnmadd_s_insn (ival) || is_fadd_s_insn (ival) > > > + || is_fsub_s_insn (ival) || is_fmul_s_insn (ival) > > > + || is_fdiv_s_insn (ival) || is_fsqrt_s_insn (ival) > > > + || is_fsgnj_s_insn (ival) || is_fsgnjn_s_insn (ival) > > > + || is_fsgnjx_s_insn (ival) || is_fmin_s_insn (ival) > > > + || is_fmax_s_insn (ival) || is_fcvt_s_w_insn (ival) > > > + || is_fcvt_s_wu_insn (ival) || is_fmv_s_x_insn (ival) > > > + || is_fcvt_s_l_insn (ival) || is_fcvt_s_lu_insn (ival) > > > + || is_fld_insn (ival) || is_fmadd_d_insn (ival) > > > + || is_fmsub_d_insn (ival) || is_fnmsub_d_insn (ival) > > > + || is_fnmadd_d_insn (ival) || is_fadd_d_insn (ival) > > > + || is_fsub_d_insn (ival) || is_fmul_d_insn (ival) > > > + || is_fdiv_d_insn (ival) || is_fsqrt_d_insn (ival) > > > + || is_fsgnj_d_insn (ival) || is_fsgnjn_d_insn (ival) > > > + || is_fsgnjx_d_insn (ival) || is_fmin_d_insn (ival) > > > + || is_fmax_d_insn (ival) || is_fcvt_s_d_insn (ival) > > > + || is_fcvt_d_s_insn (ival) || is_fcvt_d_w_insn (ival) > > > + || is_fcvt_d_wu_insn (ival) || is_fcvt_d_l_insn (ival) > > > + || is_fcvt_d_lu_insn (ival) || is_fmv_d_x_insn (ival)); > > > + } > > > + > > > + /* Returns true if instruction is classified. This function can s= et > > > + m_error_occured. */ > > > + bool > > > + try_save_pc_fprd (ULONGEST ival) noexcept > > > + { > > > + if (!need_save_pc_fprd (ival)) > > > + return false; > > > + > > > + return (!save_reg (RISCV_FIRST_FP_REGNUM + decode_rd (ival)) > > > + || set_ordinary_record_type ()); > > > + } > > > + > > > + /* Returns true if instruction needs only saving pc, rd and csr. = */ > > > + static bool > > > + need_save_pc_rd_csr (ULONGEST ival) noexcept > > > + { > > > + return (is_csrrw_insn (ival) || is_csrrs_insn (ival) || is_csrrc= _insn (ival) > > > + || is_csrrwi_insn (ival) || is_csrrsi_insn (ival) > > > + || is_csrrc_insn (ival)); > > > + } > > > + > > > + /* Returns true if instruction is classified. This function can s= et > > > + m_error_occured. */ > > > + bool > > > + try_save_pc_rd_csr (ULONGEST ival) noexcept > > > + { > > > + if (!need_save_pc_rd_csr (ival)) > > > + return false; > > > + > > > + return (!save_reg (decode_rd (ival)) > > > + || !save_reg (RISCV_FIRST_CSR_REGNUM + decode_csr (ival)) > > > + || set_ordinary_record_type ()); > > > + } > > > + > > > + /* Returns the size of the memory chunk that needs to be saved if = the > > > + instruction belongs to the group that needs only saving pc and = memory. > > > + Otherwise returns 0. */ > > > + static mem_len > > > + need_save_pc_mem (ULONGEST ival) noexcept > > > + { > > > + if (is_sb_insn (ival)) > > > + return 1; > > > + if (is_sh_insn (ival)) > > > + return 2; > > > + if (is_sw_insn (ival) || is_fsw_insn (ival)) > > > + return 4; > > > + if (is_sd_insn (ival) || is_fsd_insn (ival)) > > > + return 8; > > > + return 0; > > > + } > > > + > > > + /* Returns true if instruction is classified. This function can s= et > > > + m_error_occured. */ > > > + bool > > > + try_save_pc_mem (ULONGEST ival, struct regcache *regcache) noexcep= t > > > + { > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + mem_addr addr =3D mem_addr{}; > > > + mem_len len =3D need_save_pc_mem (ival); > > > + if (len <=3D 0) > > > + return false; > > > + > > > + mem_len offset =3D EXTRACT_STYPE_IMM (ival); > > > + return (!read_reg (regcache, decode_rs1 (ival), addr) > > > + || !save_mem (addr + offset, len) || set_ordinary_record_typ= e ()); > > > + } > > > + > > > + /* Returns the size of the memory chunk that needs to be saved if = the > > > + instruction belongs to the group that needs only saving pc, rd = and memory. > > > + Otherwise returns 0. */ > > > + static mem_len > > > + need_save_pc_rd_mem (ULONGEST ival) noexcept > > > + { > > > + if (is_sc_w_insn (ival) || is_amoswap_w_insn (ival) > > > + || is_amoadd_w_insn (ival) || is_amoxor_w_insn (ival) > > > + || is_amoand_w_insn (ival) || is_amoor_w_insn (ival) > > > + || is_amomin_w_insn (ival) || is_amomax_w_insn (ival) > > > + || is_amominu_w_insn (ival) || is_amomaxu_w_insn (ival)) > > > + return 4; > > > + if (is_sc_d_insn (ival) || is_amoswap_d_insn (ival) > > > + || is_amoadd_d_insn (ival) || is_amoxor_d_insn (ival) > > > + || is_amoand_d_insn (ival) || is_amoor_d_insn (ival) > > > + || is_amomin_d_insn (ival) || is_amomax_d_insn (ival) > > > + || is_amominu_d_insn (ival) || is_amomaxu_d_insn (ival)) > > > + return 8; > > > + return 0; > > > + } > > > + > > > + /* Returns true if instruction is classified. This function can s= et > > > + m_error_occured. */ > > > + bool > > > + try_save_pc_rd_mem (ULONGEST ival, struct regcache *regcache) noex= cept > > > + { > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + mem_len len =3D need_save_pc_rd_mem (ival); > > > + mem_addr addr =3D 0; > > > + if (len <=3D 0) > > > + return false; > > > + > > > + return (!read_reg (regcache, decode_rs1 (ival), addr) > > > + || !save_mem (addr, len) || !save_reg (decode_rd (ival)) > > > + || set_ordinary_record_type ()); > > > + } > > > + > > > + /* Returns true if instruction is successfully recordered. The le= ngth of > > > + the instruction must be equal 4 bytes. */ > > > + bool > > > + record_insn_len4 (ULONGEST ival, struct regcache *regcache) noexce= pt > > > + { > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + if (is_ecall_insn (ival)) > > > + { > > > + m_record_type =3D record_type::ECALL; > > > + return true; > > > + } > > > + > > > + if (is_ebreak_insn (ival)) > > > + { > > > + m_record_type =3D record_type::EBREAK; > > > + return true; > > > + } > > > + > > > + if (try_save_pc (ival) || try_save_pc_rd (ival) || try_save_pc_f= prd (ival) > > > + || try_save_pc_rd_csr (ival) || try_save_pc_mem (ival, regcache= ) > > > + || try_save_pc_rd_mem (ival, regcache)) > > > + return !has_error (); > > > + > > > + warning (_("Currently this instruction with len 4(%lx) is unsupp= orted"), > > > + ival); > > > + return false; > > > + } > > > + > > > + /* Returns true if instruction is successfully recordered. The le= ngth of > > > + the instruction must be equal 2 bytes. */ > > > + bool > > > + record_insn_len2 (ULONGEST ival, struct regcache *regcache) noexce= pt > > > + { > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + mem_addr addr =3D mem_addr{}; > > > + > > > + /* The order here is very important, because > > > + opcodes of some instructions may be the same. */ > > > + > > > + if (is_c_addi4spn_insn (ival) || is_c_lw_insn (ival) > > > + || (m_xlen =3D=3D 8 && is_c_ld_insn (ival))) > > > + return (!save_reg (decode_crs2_short (ival)) > > > + || set_ordinary_record_type ()); > > > + > > > + if (is_c_fld_insn (ival) || (m_xlen =3D=3D 4 && is_c_flw_insn (i= val))) > > > + return (!save_reg (RISCV_FIRST_FP_REGNUM + decode_crs2_short (= ival)) > > > + || set_ordinary_record_type ()); > > > + > > > + if (is_c_fsd_insn (ival) || (m_xlen =3D=3D 8 && is_c_sd_insn (iv= al))) > > > + { > > > + ULONGEST offset =3D ULONGEST{EXTRACT_CLTYPE_LD_IMM (ival)}; > > > + return (!read_reg (regcache, decode_crs1_short (ival), addr) > > > + || !save_mem (addr + offset, 8) || set_ordinary_record_t= ype ()); > > > + } > > > + > > > + if ((m_xlen =3D=3D 4 && is_c_fsw_insn (ival)) || is_c_sw_insn (i= val)) > > > + { > > > + ULONGEST offset =3D ULONGEST{EXTRACT_CLTYPE_LW_IMM (ival)}; > > > + return (!read_reg (regcache, decode_crs1_short (ival), addr) > > > + || !save_mem (addr + offset, 4) || set_ordinary_record_t= ype ()); > > > + } > > > + > > > + if (is_c_nop_insn (ival)) > > > + return set_ordinary_record_type (); > > > + > > > + if (is_c_addi_insn (ival)) > > > + return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_= type ()); > > > + > > > + if (m_xlen =3D=3D 4 && is_c_jal_insn (ival)) > > > + return (!save_reg (RISCV_RA_REGNUM) || set_ordinary_record_typ= e ()); > > > + > > > + if ((m_xlen =3D=3D 8 && is_c_addiw_insn (ival)) || is_c_li_insn = (ival)) > > > + return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_= type ()); > > > + > > > + if (is_c_addi16sp_insn (ival)) > > > + return (!save_reg (RISCV_SP_REGNUM) || set_ordinary_record_typ= e ()); > > > + > > > + if (is_c_lui_insn (ival)) > > > + return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_= type ()); > > > + > > > + if (is_c_srli_insn (ival) || is_c_srai_insn (ival) || is_c_andi_= insn (ival) > > > + || is_c_sub_insn (ival) || is_c_xor_insn (ival) || is_c_or_insn= (ival) > > > + || is_c_and_insn (ival) || (m_xlen =3D=3D 8 && is_c_subw_insn (= ival)) > > > + || (m_xlen =3D=3D 8 && is_c_addw_insn (ival))) > > > + return (!save_reg (decode_crs1_short (ival)) > > > + || set_ordinary_record_type ()); > > > + > > > + if (is_c_j_insn (ival) || is_c_beqz_insn (ival) || is_c_bnez_ins= n (ival)) > > > + return set_ordinary_record_type (); > > > + > > > + if (is_c_slli_insn (ival)) > > > + return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_= type ()); > > > + > > > + if (is_c_fldsp_insn (ival) || (m_xlen =3D=3D 4 && is_c_flwsp_ins= n (ival))) > > > + return (!save_reg (RISCV_FIRST_FP_REGNUM + decode_crs1 (ival)) > > > + || set_ordinary_record_type ()); > > > + > > > + if (is_c_lwsp_insn (ival) || (m_xlen =3D=3D 8 && is_c_ldsp_insn = (ival))) > > > + return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_= type ()); > > > + > > > + if (is_c_jr_insn (ival)) > > > + return set_ordinary_record_type (); > > > + > > > + if (is_c_mv_insn (ival)) > > > + return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_= type ()); > > > + > > > + if (is_c_ebreak_insn (ival)) > > > + { > > > + m_record_type =3D record_type::EBREAK; > > > + return true; > > > + } > > > + > > > + if (is_c_jalr_insn (ival)) > > > + return (!save_reg (RISCV_RA_REGNUM) || set_ordinary_record_typ= e ()); > > > + > > > + if (is_c_add_insn (ival)) > > > + return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_= type ()); > > > + > > > + if (is_c_fsdsp_insn (ival) || (m_xlen =3D=3D 8 && is_c_sdsp_insn= (ival))) > > > + { > > > + ULONGEST offset =3D ULONGEST{EXTRACT_CSSTYPE_SDSP_IMM (ival)}; > > > + return (!read_reg (regcache, RISCV_SP_REGNUM, addr) > > > + || !save_mem (addr + offset, 8) || set_ordinary_record_t= ype ()); > > > + } > > > + > > > + if (is_c_swsp_insn (ival) || (m_xlen =3D=3D 4 && is_c_fswsp_insn= (ival))) > > > + { > > > + ULONGEST offset =3D ULONGEST{EXTRACT_CSSTYPE_SWSP_IMM (ival)}; > > > + return (!read_reg (regcache, RISCV_SP_REGNUM, addr) > > > + || !save_mem (addr + offset, 4) || set_ordinary_record_t= ype ()); > > > + } > > > + > > > + warning (_("Currently this instruction with len 2(%lx) is unsupp= orted"), > > > + ival); > > > + return false; > > > + } > > > + > > > +public: > > > + /* Iterator for registers that need to be recorded. */ > > > + using regs_iter =3D recorded_regs::const_iterator; > > > + /* Iterator for memory chunks that need to be recorded. */ > > > + using mems_iter =3D recorded_mems::const_iterator; > > > + > > > + /* Record instruction at address addr. Returns false if error hap= pened. */ > > > + bool > > > + record (gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR add= r) noexcept > > > + { > > > + gdb_assert (gdbarch !=3D nullptr); > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + int m_length =3D 0; > > > + m_xlen =3D riscv_isa_xlen (gdbarch); > > > + ULONGEST ival =3D riscv_insn::fetch_instruction (gdbarch, addr, = &m_length); > > > + if (!save_reg (RISCV_PC_REGNUM)) > > > + return false; > > > + > > > + if (m_length =3D=3D 4) > > > + return record_insn_len4 (ival, regcache); > > > + > > > + if (m_length =3D=3D 2) > > > + return record_insn_len2 (ival, regcache); > > > + > > > + /* 6 bytes or more. If the instruction is longer than 8 bytes, = we don't > > > + have full instruction bits in ival. At least, such long inst= ructions > > > + are not defined yet, so just ignore it. */ > > > + gdb_assert (m_length > 0 && m_length % 2 =3D=3D 0); > > > + > > > + warning (_("Can not record unknown instruction (opcode =3D %lx)"= ), ival); > > > + return false; > > > + } > > > + > > > + /* Get record type of instruction. */ > > > + record_type > > > + get_record_type () const noexcept > > > + { > > > + return m_record_type; > > > + } > > > + > > > + /* Returns an iterator to the beginning of the registers that need > > > + to be saved. */ > > > + regs_iter > > > + regs_begin () const noexcept > > > + { > > > + return m_regs.begin (); > > > + } > > > + > > > + /* Returns an iterator to the end of the registers that need > > > + to be saved. */ > > > + regs_iter > > > + regs_end () const noexcept > > > + { > > > + return m_regs.end (); > > > + } > > > + > > > + /* Returns an iterator to the beginning of the memory chunks that = need > > > + to be saved. */ > > > + mems_iter > > > + mems_begin () const noexcept > > > + { > > > + return m_mems.begin (); > > > + } > > > + > > > + /* Returns an iterator to the end of the memory chunks that need > > > + to be saved. */ > > > + mems_iter > > > + mems_end () const noexcept > > > + { > > > + return m_mems.end (); > > > + } > > > +}; > > > + > > > +/* A helper function to record instruction using record API. */ > > > + > > > +static int > > > +riscv_record_insn_details (struct gdbarch *gdbarch, struct regcache = *regcache, > > > + const riscv_recorded_insn &insn) > > > +{ > > > + gdb_assert (gdbarch !=3D nullptr); > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + riscv_gdbarch_tdep *tdep =3D gdbarch_tdep (gdb= arch); > > > + auto regs_begin =3D insn.regs_begin (); > > > + auto regs_end =3D insn.regs_end (); > > > + if (std::any_of (regs_begin, > > > + regs_end, > > > + [®cache] (auto &®_it) > > > + { > > > + return record_full_arch_list_add_reg (regcache, re= g_it); > > > + })) > > > + return -1; > > > + > > > + auto mems_begin =3D insn.mems_begin (); > > > + auto mems_end =3D insn.mems_end (); > > > + if (std::any_of (mems_begin, > > > + mems_end, > > > + [] (auto &&mem_it) > > > + { > > > + return record_full_arch_list_add_mem (mem_it.first= , > > > + mem_it.secon= d); > > > + })) > > > + return -1; > > > + > > > + switch (insn.get_record_type ()) > > > + { > > > + case riscv_recorded_insn::record_type::ORDINARY: > > > + break; > > > + > > > + case riscv_recorded_insn::record_type::ECALL: > > > + { > > > + if (!tdep->riscv_syscall_record) > > > + { > > > + warning (_("Syscall record is not supported")); > > > + return -1; > > > + } > > > + ULONGEST reg_val =3D ULONGEST{}; > > > + if (!try_read (regcache, RISCV_A7_REGNUM, reg_val)) > > > + return -1; > > > + return tdep->riscv_syscall_record (regcache, reg_val); > > > + } > > > + > > > + case riscv_recorded_insn::record_type::EBREAK: > > > + break; > > > + > > > + default: > > > + return -1; > > > + } > > > + return 0; > > > +} > > > + > > > +/* Parse the current instruction and record the values of the regist= ers and > > > + memory that will be changed in current instruction to record_arch= _list. > > > + Return -1 if something is wrong. */ > > > + > > > +int > > > +riscv_process_record (struct gdbarch *gdbarch, struct regcache *regc= ache, > > > + CORE_ADDR addr) > > > +{ > > > + gdb_assert (gdbarch !=3D nullptr); > > > + gdb_assert (regcache !=3D nullptr); > > > + > > > + riscv_recorded_insn insn; > > > + if (!insn.record (gdbarch, regcache, addr)) > > > + { > > > + record_full_arch_list_add_end (); > > > + return -1; > > > + } > > > + > > > + int ret_val =3D riscv_record_insn_details (gdbarch, regcache, insn= ); > > > + > > > + if (record_full_arch_list_add_end ()) > > > + return -1; > > > + > > > + return ret_val; > > > +} > > > diff --git a/gdb/riscv-tdep.h b/gdb/riscv-tdep.h > > > index ad1e9596b83..2903aefd007 100644 > > > --- a/gdb/riscv-tdep.h > > > +++ b/gdb/riscv-tdep.h > > > @@ -35,7 +35,11 @@ enum > > > RISCV_FP_REGNUM =3D 8, /* Frame Pointer. */ > > > RISCV_A0_REGNUM =3D 10, /* First argument. */ > > > RISCV_A1_REGNUM =3D 11, /* Second argument. */ > > > - RISCV_A7_REGNUM =3D 17, /* Seventh argument. */ > > > + RISCV_A2_REGNUM =3D 12, /* Third argument. */ > > > + RISCV_A3_REGNUM =3D 13, /* Forth argument. */ > > > + RISCV_A4_REGNUM =3D 14, /* Fifth argument. */ > > > + RISCV_A5_REGNUM =3D 15, /* Sixth argument. */ > > > + RISCV_A7_REGNUM =3D 17, /* Register to pass syscall n= umber. */ > > > RISCV_PC_REGNUM =3D 32, /* Program Counter. */ > > > > > > RISCV_NUM_INTEGER_REGS =3D 32, > > > @@ -113,6 +117,10 @@ struct riscv_gdbarch_tdep : gdbarch_tdep_base > > > /* Return the expected next PC assuming FRAME is stopped at a sysc= all > > > instruction. */ > > > CORE_ADDR (*syscall_next_pc) (const frame_info_ptr &frame) =3D nul= lptr; > > > + > > > + /* Syscall record. */ > > > + int (*riscv_syscall_record) (struct regcache *regcache, > > > + unsigned long svc_number) =3D nullptr; > > > }; > > > > > > > > > @@ -177,6 +185,12 @@ extern void riscv_supply_regset (const struct re= gset *regset, > > > struct regcache *regcache, int regnum= , > > > const void *regs, size_t len); > > > > > > +/* Parse the current instruction, and record the values of the > > > + registers and memory that will be changed by the current > > > + instruction. Returns -1 if something goes wrong, 0 otherwise. *= / > > > +extern int riscv_process_record (struct gdbarch *gdbarch, > > > + struct regcache *regcache, CORE_ADDR a= ddr); > > > + > > > /* The names of the RISC-V target description features. */ > > > extern const char *riscv_feature_name_csr; > > > > > > diff --git a/gdb/syscalls/riscv-canonicalize-syscall-gen.py b/gdb/sys= calls/riscv-canonicalize-syscall-gen.py > > > new file mode 100755 > > > index 00000000000..30e52b7e472 > > > --- /dev/null > > > +++ b/gdb/syscalls/riscv-canonicalize-syscall-gen.py > > > @@ -0,0 +1,163 @@ > > > +#!/usr/bin/env python3 > > > +# pylint: disable=3Dinvalid-name > > > + > > > +# Copyright (C) 2024-2025 Free Software Foundation, Inc. > > > +# Contributed by Timur Golubovich > > > + > > > +# This file is part of GDB. > > > + > > > +# This program is free software; you can redistribute it and/or modi= fy > > > +# 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 . > > > + > > > + > > > +# To get help message for this script, run: > > > +# ./gdb/syscalls/riscv-canonicalize-syscall-gen.py --help > > > + > > > +# Execution result: > > > + > > > +# usage: riscv-canonicalize-syscall-gen.py [-h] -i INPUT > > > +# > > > +# Generate file gdb/riscv-canonicalize-syscall-gen.c from path to ri= scv linux syscalls. > > > +# > > > +# options: > > > +# -h, --help show this help message and exit > > > +# -i INPUT, --input INPUT > > > +# path to riscv linux syscalls (glibc/sysdep= s/unix/sysv/linux/riscv/rv64/arch-syscall.h) > > > + > > > +import argparse > > > +import re > > > +import sys > > > +from pathlib import Path as _Path > > > + > > > +head =3D """\ > > > +/* DO NOT EDIT: Autogenerated by riscv-canonicalize-syscall-gen.py > > > + > > > + Copyright (C) 2024-2025 Free Software Foundation, Inc. > > > + > > > + This file is part of GDB. > > > + > > > + This program is free software; you can redistribute it and/or mod= ify > > > + 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 . */ > > > + > > > +#include "defs.h" > > > +#include "riscv-linux-tdep.h" > > > + > > > +/* riscv64_canonicalize_syscall maps from the native riscv 64 Linux = set > > > + of syscall ids into a canonical set of syscall ids used by > > > + process record. */ > > > + > > > +enum gdb_syscall > > > +riscv64_canonicalize_syscall (int syscall) > > > +{ > > > + switch (syscall) > > > + { > > > +""" > > > + > > > +tail =3D """\ > > > + default: > > > + return gdb_sys_no_syscall; > > > + } > > > +} > > > +""" > > > + > > > + > > > +class Generator: > > > + def _get_gdb_syscalls(self, gdb_syscalls_path: _Path) -> list[s= tr]: > > > + gdb_syscalls: list[str] =3D [] > > > + with open(gdb_syscalls_path, "r", encoding=3D"UTF-8") a= s file: > > > + lines =3D file.readlines() > > > + for line in lines: > > > + match =3D re.search(r"\s*(?Pgdb_s= ys_[^S]+)\S*=3D", line) > > > + if match: > > > + gdb_syscalls.append(match.group= ("name").strip()) > > > + return gdb_syscalls > > > + > > > + def _get_canon_syscalls_lines(self, syscalls_path: _Path, gdb_s= yscalls: list[str]) -> list[str]: > > > + canon_syscalls: dict[int, str] =3D {} > > > + with open(syscalls_path, "r", encoding=3D"UTF-8") as fi= le: > > > + lines =3D file.readlines() > > > + for line in lines: > > > + match =3D re.match(r"#define\s+__NR_(?P= [^\s]+)\s+(?P\d+)", line) > > > + if match: > > > + syscall_name =3D match.group("n= ame") > > > + syscall_num =3D int(match.group= ("number")) > > > + gdb_syscall_name =3D f"gdb_sys_= {syscall_name}" > > > + if gdb_syscall_name in gdb_sysc= alls: > > > + value =3D f" case {s= yscall_num}: return {gdb_syscall_name};\n" > > > + canon_syscalls[syscall_= num] =3D value > > > + # this is a place for corner ca= ses > > > + elif syscall_name =3D=3D "mmap"= : > > > + gdb_old_syscall_name = =3D "gdb_old_mmap" > > > + value =3D f" case {s= yscall_num}: return {gdb_old_syscall_name};\n" > > > + canon_syscalls[syscall_= num] =3D value > > > + else: > > > + value =3D f" /* case= {syscall_num}: return {gdb_syscall_name}; */\n" > > > + canon_syscalls[syscall_= num] =3D value > > > + return [canon_syscalls[syscall_num] for syscall_num in = sorted(canon_syscalls)] > > > + > > > + def generate(self, syscalls_path: _Path) -> None: > > > + repo_path =3D _Path(__file__).parent.parent.parent > > > + gdb_syscalls_path =3D repo_path / "gdb" / "linux-record= .h" > > > + canon_syscalls_path =3D repo_path / "gdb" / "riscv-cano= nicalize-syscall-gen.c" > > > + > > > + gdb_syscalls =3D self._get_gdb_syscalls(gdb_syscalls_pa= th) > > > + canon_syscalls_lines =3D self._get_canon_syscalls_lines= (syscalls_path, gdb_syscalls) > > > + > > > + with open(canon_syscalls_path, "w", encoding=3D"UTF-8")= as file: > > > + file.writelines(head) > > > + file.writelines(canon_syscalls_lines) > > > + file.writelines(tail) > > > + > > > + > > > +help_message =3D """\ > > > +Generate file gdb/riscv-canonicalize-syscall-gen.c > > > +from path to riscv linux syscalls. > > > +""" > > > + > > > + > > > +def setup_parser() -> argparse.ArgumentParser: > > > + parser =3D argparse.ArgumentParser(description=3Dhelp_message) > > > + parser.add_argument( > > > + "-i", > > > + "--input", > > > + type=3D_Path, > > > + required=3DTrue, > > > + help=3D"path to riscv linux syscalls (glibc/sysdeps/uni= x/sysv/linux/riscv/rv64/arch-syscall.h)", > > > + ) > > > + return parser > > > + > > > + > > > +def main(argv: list[str]) -> int: > > > + try: > > > + parser =3D setup_parser() > > > + args =3D parser.parse_args(argv) > > > + generator =3D Generator() > > > + generator.generate(args.input) > > > + return 0 > > > + except RuntimeError as e: > > > + print(str(e)) > > > + return -1 > > > + > > > + > > > +if __name__ =3D=3D "__main__": > > > + sys.exit(main(sys.argv[1:])) > > > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > > > index c37cc8974e2..0149125e60a 100644 > > > --- a/gdb/testsuite/lib/gdb.exp > > > +++ b/gdb/testsuite/lib/gdb.exp > > > @@ -3758,7 +3758,8 @@ proc supports_reverse {} { > > > || [istarget "aarch64*-*-linux*"] > > > || [istarget "loongarch*-*-linux*"] > > > || [istarget "powerpc*-*-linux*"] > > > - || [istarget "s390*-*-linux*"] } { > > > + || [istarget "s390*-*-linux*"] > > > + || [istarget "riscv*-*-linux*"] } { > > > return 1 > > > } > > > > > > -- > > > 2.34.1 > >