From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CSMnIftVuWi2yRMAWB0awg (envelope-from ) for ; Thu, 04 Sep 2025 05:03:55 -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=ARtxMA2p; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 82AF41E087; Thu, 04 Sep 2025 05:03:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.8 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_LOW,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no 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 3102B1E023 for ; Thu, 04 Sep 2025 05:03:53 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D467385840B for ; Thu, 4 Sep 2025 09:03:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D467385840B 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=ARtxMA2p Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id D38F43858D1E for ; Thu, 4 Sep 2025 09:01:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D38F43858D1E 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 D38F43858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::533 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756976471; cv=none; b=OYGHXQXU1SJoRl+6e9GC/CNl2Pydo3j8okbtBx4DZ/irdCV15T5Ycj9c2G+Y8WHYMcliqrJRy84NeY8FYS4zCwUT27FvOSrO7nDCniHugvmIuiqWq/6MQtCgLxvE3/CxLx5WklUCymJl8uneML7E0FcfKw25RMv+TQqCu7BQYrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756976471; c=relaxed/simple; bh=2AlYG1pSyck9t2jE2tuCO8s+J+fPIis9Lx3tKvlVYLg=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=viHnrBpPoAxKDmkPSMWg0gFimaw5zQxDJJyUUMl0uVdJkXu7JfQiVhcZwJ4t5sORaQt7xbQnwoxzofp5GpBSa20y2IP28xWTwCeE47Fww7yHCRdidNjqH9ZOaAFP7sGsre6lsbdid80zASS7HrEESm3datrKtEDnsXwvHsv7dXo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D38F43858D1E Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-61e425434bbso1304977a12.2 for ; Thu, 04 Sep 2025 02:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756976469; x=1757581269; darn=sourceware.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0uCJg6s2+mlj7YFYIn0EsE1uz8gt6DtTIxa0YY49HNM=; b=ARtxMA2pYtSTajQBng/FuN9eHp4lHCw6QN2sqmuGWZyrFeJ4P/2aR5ReZayIpDO5cK M3Mk25p7ZgcdaeAk91lKIv05n7DyE6aWW3sF6PCGfvIdJHUNaMbzQXaRo6aK0xCIraSl foWkJfdQA/szKXdkzYfthdQaCGHkUmfo/YnYL8sKLopPwEDz840uNHoetirMCvMa9tpH qxWfDemMKJl8f2KTM0DNC3LIfRZAkAFiBJNkKjQTOL70vb5gehdOziJ1eELs142qKsf7 4fvVB5pWEb7EMqfTkUUXeezjW7U74reHu1vlFKfzPybWZ46QPOigGJfG3hRIv0z3F1Vr P+2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756976469; x=1757581269; h=content-transfer-encoding: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=0uCJg6s2+mlj7YFYIn0EsE1uz8gt6DtTIxa0YY49HNM=; b=gm9Og3m9GcRp4+jDjqaIcLzKv2vjc1IjF4frQjFB1dw8ucind/dZHo284CbO+17jF8 8YvmT3g3+7YhYeq9Ogt78/H3sso7c/10OTkqKytT+raLsN9KctxkkYdwwTAhzdhzMTfh MV52bx2KFBQp6VoRuD9RLezbyfzUzAIAA2SqS2Nh1xQWMweJ1rjOT00TA9lrw3Uk5zkK 6zZ9ql39FnaIknkZ3UcWWfxmPUk4gtd7t690vjNjSkiWwKTkkD4ZnR9lG+vXHzzocOGA 0SJ/bc+BOeeBxWD4VV2lJFcdc64j059sjkw/vBgUJFoPD5XimfmklpIOUqPs16WG5erp sbQQ== X-Gm-Message-State: AOJu0YyxRxsWzDlOY0/TLb2b+gyZdcR5qe7FJxm1xZePnt0M8qjcNC78 7zdzlNITQ1OZe+5n9U0xZi4peV0s8eflsp7WMG2+W5hZC240tn6L0LT3S0SGjKFPr23CY+2n6Ka AC+T5K2/RrIQOr/7XM/D/t93OJ5/65dh/Tj+w X-Gm-Gg: ASbGncs1d2jzkUv5E/NnaTyJp8XPbjBCwXsq5xEOlaWJovLzjwrW0WPeieFVurujhrj fT98GYAbnGY7/uBLUWzSzVBHTvy2IOIh01OsiGjIKlLy8SoH96a07p6YGGsbLgzYKhaKgl4iGXm np/Cq8poMm73pKZswtkPLg046O6ZNRT4gqNL7LMSJZ6JTukglRVRkaX4UN5IA3+OuWb8u3LlCT0 xR4Pylvag== X-Google-Smtp-Source: AGHT+IEgZzYpB45Th3c9sc4TeBF19zyf0ds/kcc1fb3Gpsnr9x53S5+8Rh/MRrMBREqhjWP8x5lIjsJqTyF3V62Xiyc= X-Received: by 2002:a05:6402:3583:b0:61d:e5a2:ea78 with SMTP id 4fb4d7f45d1cf-61de5a2ec3amr14790203a12.10.1756976468828; Thu, 04 Sep 2025 02:01:08 -0700 (PDT) MIME-Version: 1.0 References: <20250828224232.206247-1-timurgol007@gmail.com> In-Reply-To: <20250828224232.206247-1-timurgol007@gmail.com> From: Timur Golubovich Date: Thu, 4 Sep 2025 12:00:56 +0300 X-Gm-Features: Ac12FXzBJ8-pK89ZjmhFE_-wgPIaKiivFKTFsM_I2ma1ULFtnY-VjKJ6N0Ga1e4 Message-ID: Subject: Re: [PATCH] This commit adds support for catching syscalls on riscv To: gdb-patches@sourceware.org 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! A week has passed, so I am pinging. Apart from the generated files, this patch is actually quite simple due to the simplicity of the riscv architecture. I also prepared another patch that would generate riscv-canonicalize-syscall-gen.c not from glibc sources, but from the generated riscv-linux.xml.in file. I also have an idea to use this logic for all architectures that support record-syscall. At least for those who have an xml file with syscal= ls. On Fri, Aug 29, 2025 at 1:42=E2=80=AFAM timurgol007 = wrote: > > From: Timur Golubovich > > It affects following files: > - gdb/riscv-linux-tdep.c: a function to get syscall number. > - gdbserver/linux-riscv-low.cc: syscall trapinfo function to enable > catching syscalls on remote targets. > - gdb/syscalls/riscv-linux.xml.in: a file with syscalls, generated from > linux kernel sources using gdb/syscalls/update-linux-from-src.sh script. > - gdb/syscalls/riscv-linux.xml: a file with syscalls, patched with group > names gdb/syscalls/apply-defaults.xsl using xsltproc tool. > - gdb/syscalls/update-linux.sh: set startyear to 2025 on riscv. > - gdb/syscalls/update-linux-from-src.sh: riscv syscall table must be > generated from kernel headers. > - gdb/NEWS: catch-syscall feature is now available on riscv. > - gdb/data-directory/Makefile.in: adding file with syscalls to Makefile. > --- > gdb/NEWS | 2 + > gdb/data-directory/Makefile.in | 1 + > gdb/riscv-linux-tdep.c | 26 ++ > gdb/syscalls/riscv-linux.xml | 340 +++++++++++++++++++++++++ > gdb/syscalls/riscv-linux.xml.in | 344 ++++++++++++++++++++++++++ > gdb/syscalls/update-linux-from-src.sh | 5 + > gdb/syscalls/update-linux.sh | 3 + > gdbserver/linux-riscv-low.cc | 24 ++ > 8 files changed, 745 insertions(+) > create mode 100644 gdb/syscalls/riscv-linux.xml > create mode 100644 gdb/syscalls/riscv-linux.xml.in > > diff --git a/gdb/NEWS b/gdb/NEWS > index db0e74a2623..3d4cf901444 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -48,6 +48,8 @@ > > * Add record full support for rv64gc architectures > > +* The "catch syscall" command now works on riscv*-linux* targets. > + > * New commands > > maintenance check psymtabs > diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile= .in > index 2ca2b8e7e5f..d7f4c988fb6 100644 > --- a/gdb/data-directory/Makefile.in > +++ b/gdb/data-directory/Makefile.in > @@ -61,6 +61,7 @@ GEN_SYSCALLS_FILES =3D \ > mips-o32-linux.xml \ > ppc-linux.xml \ > ppc64-linux.xml \ > + riscv-linux.xml \ > s390-linux.xml \ > s390x-linux.xml \ > sparc-linux.xml \ > diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c > index 982273a0b9d..0a946111b9d 100644 > --- a/gdb/riscv-linux-tdep.c > +++ b/gdb/riscv-linux-tdep.c > @@ -502,6 +502,28 @@ riscv_linux_get_tls_dtp_offset (struct gdbarch *gdba= rch, ptid_t ptid, > return 0; > } > > +/* Function to extract syscall number. */ > + > +static LONGEST > +riscv_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *th= read) > +{ > + struct regcache *regcache =3D get_thread_regcache (thread); > + LONGEST ret; > + > + /* Getting the system call number from the register. > + When dealing with riscv architecture, this information > + is stored in $a7 register. */ > + if (regcache->cooked_read (RISCV_A7_REGNUM, &ret) > + !=3D register_status::REG_VALID) > + { > + warning (_ ("Can not read a7 register")); > + return -1; > + } > + > + /* The result. */ > + return ret; > +} > + > /* Initialize RISC-V Linux ABI info. */ > > static void > @@ -540,6 +562,10 @@ riscv_linux_init_abi (struct gdbarch_info info, stru= ct gdbarch *gdbarch) > tdep->riscv_syscall_record =3D riscv_linux_syscall_record; > > riscv64_linux_record_tdep_init (gdbarch, riscv_linux_record_tdep); > + > + /* Functions for 'catch syscall'. */ > + set_gdbarch_xml_syscall_file (gdbarch, "syscalls/riscv-linux.xml"); > + set_gdbarch_get_syscall_number (gdbarch, riscv_linux_get_syscall_numbe= r); > } > > /* Initialize RISC-V Linux target support. */ > diff --git a/gdb/syscalls/riscv-linux.xml b/gdb/syscalls/riscv-linux.xml > new file mode 100644 > index 00000000000..3578c3fcce5 > --- /dev/null > +++ b/gdb/syscalls/riscv-linux.xml > @@ -0,0 +1,340 @@ > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > diff --git a/gdb/syscalls/riscv-linux.xml.in b/gdb/syscalls/riscv-linux.x= ml.in > new file mode 100644 > index 00000000000..17b2b0ae2de > --- /dev/null > +++ b/gdb/syscalls/riscv-linux.xml.in > @@ -0,0 +1,344 @@ > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > + > diff --git a/gdb/syscalls/update-linux-from-src.sh b/gdb/syscalls/update-= linux-from-src.sh > index ea06c133242..26c38f6c531 100755 > --- a/gdb/syscalls/update-linux-from-src.sh > +++ b/gdb/syscalls/update-linux-from-src.sh > @@ -325,6 +325,11 @@ regen () > gen_from_kernel_headers "$f" arm64 > return > ;; > + riscv-linux.xml.in) > + # No syscall.tbl. > + gen_from_kernel_headers "$f" riscv > + return > + ;; > arm-linux.xml.in) > t=3D"arch/arm/tools/syscall.tbl" > h=3D"arch/arm/include/uapi/asm/unistd.h" > diff --git a/gdb/syscalls/update-linux.sh b/gdb/syscalls/update-linux.sh > index 107ce05b4e8..cbc8a9d82d5 100755 > --- a/gdb/syscalls/update-linux.sh > +++ b/gdb/syscalls/update-linux.sh > @@ -40,6 +40,9 @@ case "$f" in > *aarch64-linux.xml.in) > startyear=3D2015 > ;; > + *riscv-linux.xml.in) > + startyear=3D2025 > + ;; > esac > > year=3D$(date +%Y) > diff --git a/gdbserver/linux-riscv-low.cc b/gdbserver/linux-riscv-low.cc > index 8c742f406a2..f70ed597051 100644 > --- a/gdbserver/linux-riscv-low.cc > +++ b/gdbserver/linux-riscv-low.cc > @@ -58,6 +58,10 @@ protected: > void low_set_pc (regcache *regcache, CORE_ADDR newpc) override; > > bool low_breakpoint_at (CORE_ADDR pc) override; > + > + bool low_supports_catch_syscall () override; > + > + void low_get_syscall_trapinfo (regcache *regcache, int *sysno) overrid= e; > }; > > /* The singleton target ops object. */ > @@ -78,6 +82,26 @@ riscv_target::low_cannot_store_register (int regno) > "is not implemented by the target"); > } > > +/* Implementation of linux target ops method "low_supports_catch_syscall= ". */ > + > +bool > +riscv_target::low_supports_catch_syscall () > +{ > + return true; > +} > + > +/* Implementation of linux target ops method "low_get_syscall_trapinfo".= */ > + > +void > +riscv_target::low_get_syscall_trapinfo (regcache *regcache, int *sysno) > +{ > + LONGEST l_sysno; > + > + /* The content of a register. */ > + collect_register_by_name (regcache, "a7", &l_sysno); > + *sysno =3D (int)l_sysno; > +} > + > /* Implementation of linux target ops method "low_arch_setup". */ > > void > -- > 2.34.1 >