From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kq3bL/RYyWiLnAYAWB0awg (envelope-from ) for ; Tue, 16 Sep 2025 08:32:52 -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=a1K5zNCf; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id ACEDA1E0BA; Tue, 16 Sep 2025 08:32:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 185B11E04C for ; Tue, 16 Sep 2025 08:32:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A95E43857400 for ; Tue, 16 Sep 2025 12:32:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A95E43857400 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=a1K5zNCf Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 4416B3858D39 for ; Tue, 16 Sep 2025 12:32:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4416B3858D39 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 4416B3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758025926; cv=none; b=M4NpM3ysPOB+N7/LfXooHgto/vYvmUo3g9EwG0FcTMh5T7TG78KzNQSqx+3luyH4u9FagSMIg+aDOukKFT5aDMb6YOm/TDEeUQEdYa4KgCT+jsZgofdqM/T19tAKL4gPo59z98lK1rljmvpgnR6jWZ3gGUDulJal0uI/4r20w3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758025926; c=relaxed/simple; bh=NcPn4gxx780Q8ayrwN9dTm1HsQr699TjotERpdg/cZ4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=VQuX0vL0OqfpVguMWBRxDXys5ljnEfP1h/TptSlyqeyjxOVONihwAh/OTyiuOe1+xFv/wrqUTJHx7T4BDcm5WTR79mnoAZWqb89GHAA1/938er9U7CeoQngLMZWEVf4yB5dSZi30xR9DuTvPJGizPKMj192uMZk0o3rG0NeJKPE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4416B3858D39 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-62f6b1fd718so563378a12.2 for ; Tue, 16 Sep 2025 05:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758025925; x=1758630725; 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=2KTzOwxv2Pxax+2FcdGjLAO0tNf5PsZPLdxUswVuvss=; b=a1K5zNCfdlHPKblZ+LJH4v1K+zKBlihcl6HXRPYi/uFXDBo736WdagGvfRauttgDxV Aq8dLtE7JXn/4AgA8aRvMOSTAw3uYeH1ImHfMcgjLZUwOolHMGEtVUKyGfqkrFil6R0q zSToBIF+k9dTFJpKoOnhODTBHQjZ6ykoWY+0O/HAUjYj0BWKDLm6+aQJmTzp/Af4JWoy qVH6blegqB4gUxnEtaJcTatnW7NpYOCGtu7bgknV6exdJqvRK37V1ctCWY/wV3r/nKt2 LPnYpdOE341PslZ2kRlyWVj2iMVwRR3rmDsLNU3czHh80fgVX4429niWyyV1Zq+q6Ro5 b+1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758025925; x=1758630725; 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=2KTzOwxv2Pxax+2FcdGjLAO0tNf5PsZPLdxUswVuvss=; b=nLOmXQPM+Z951gUydMY2KTX9U4nshkWFm8gLz9YgAYGUKP2LzOnmK5bOBZzQ+0eQdz eezPjOLBftOqnnYUHNgIOKShNUNdEPkih06dBkL6elq0yOmUFdEJJ8ZA3v76n6TgaJDJ M5rf7is/1glAtLhpkNo4zizKm8L4dNCnDEV4j+PbxmuOZXRrD8Evj50XHUd6cPfjF4Sj 0pHdkJO2H1rAAFJYnk/D3aT1s2EQ4maz7A0aSNBTL6x1BmfrGH5dFcrrBbEahb2ULheS Ldvm+GWZbzCibjWztf6GfUtuZFuwuwOeT80kSObWHGkqLwPw8g/CbFchPNiQITsf1p3T xNYA== X-Forwarded-Encrypted: i=1; AJvYcCUjkWXGZwnKVEsY14ygxUviIGpvykyJD7lDhajqxOT+ts29IsRG6S1dugMWRZF3lMHSaQ2Lfy/JMSz7Yg==@sourceware.org X-Gm-Message-State: AOJu0YzNQu65smfa4/aAL1V9BqpISwAos985K6i6I9Up7i9kyAb3zfl0 47I2uVvicZm9+abNVG15VCM5whP/Q1y/1CTyEm3W75aVydUdLQbjjoUzES774q/6ezuEARrhBDe g9fd0bOCvsBocGUvctDq81Nc4Z9uEl+JawzQp X-Gm-Gg: ASbGncuzVcEchSw3ykiKt86yvQU7LyNt5L4rAg2sqKW2XBElS7YPmKzYC8p1e7wF+xF 7hGfdzLcz6F1tBA0+edY1bYzk5BKcDWf1XmfYRUWPP9Z96m8UigTFo03kKevtCsRv8DS/cAVIqd Zk3Ink8MZcKywGECbIGUqLG5jD6aUyesOUnAmXgiBrih+bPdChCkHt7IpvBldID/JhkIX+LpCEp OuOqp0= X-Google-Smtp-Source: AGHT+IHsYt9a0I66s0ORWJf7+MJ0CEL2wUwnV3J4Vw6hTgyiA0MMHyfWBH8zWUaGZ1cNBSj+RaqfwvKlyiwKRhyIw2U= X-Received: by 2002:a05:6402:2352:b0:62f:4b7b:4949 with SMTP id 4fb4d7f45d1cf-62f4b7b4d60mr6580047a12.10.1758025924347; Tue, 16 Sep 2025 05:32:04 -0700 (PDT) MIME-Version: 1.0 References: <20250910093804.16250-1-timurgol007@gmail.com> In-Reply-To: <20250910093804.16250-1-timurgol007@gmail.com> From: Timur Golubovich Date: Tue, 16 Sep 2025 15:31:52 +0300 X-Gm-Features: AS18NWC-AmcYmd9Tc-zeFFFiJE23uj6XN-f5NKcv39A99KtOBnrQLGC1KNaHT_s Message-ID: Subject: Re: [PATCH] This commit adds support for catching syscalls on riscv To: tom@tromey.com, gdb-patches@sourceware.org, tdevries@suse.de 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! Ping. On Wed, Sep 10, 2025 at 12:38=E2=80=AFPM 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. > > Hi! > Can you please look at this patch? It has 2 big autogenerated files, so > it looks a bit complicated. But in fact it is quiet simple, so I would > prefer to merge it. > --- > 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 36065ec1943..785cbe9b4d6 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -63,6 +63,8 @@ GNU/Linux/MicroBlaze (gdbserver) microblazeel-*linux* > * Debugging Linux programs that use AArch64 Guarded Control Stacks is no= w > supported. > > +* 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 >