From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SgVLAm580mjoJw8AWB0awg (envelope-from ) for ; Tue, 23 Sep 2025 06:54:38 -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=TaLqUoT1; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E6BCA1E0BA; Tue, 23 Sep 2025 06:54:37 -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 D49701E047 for ; Tue, 23 Sep 2025 06:54:33 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 263363858C24 for ; Tue, 23 Sep 2025 10:54:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 263363858C24 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=TaLqUoT1 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id B53A83858D26 for ; Tue, 23 Sep 2025 10:53:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B53A83858D26 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 B53A83858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758624825; cv=none; b=M7PWBrJVItuvZW+oxpxXJgbiYHhP4idCX6m2vnmMQEjKQ7ddeA80l/ED6bjCUR8tdSHcmH4OjNvSyNUQMPnf0yd6ueyJusggurCSK9vQPNTbTerudjtAkcTHvl+VYYfPuv8SbJffj5oMRDfah7hsXO4i4cBn0ABPDdyN3EFl+l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758624825; c=relaxed/simple; bh=LOjoK0eIZ5X7BO5JHGsw4qDD62JQgZe+CidtmjKxP6E=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=cDsYEITkVjiKtBnmAJJ/0v3cuQSIoJ7gp4V13/hq4rJpnh489CpA/LwN2nwinRw7QAsEosUkN1aW97pBSA7UyZR4r1esHBWf5qrE8aQuzQtIS0TIRzgS+WwjVaWp4mEgyN9il687Rt+GBFiKbPhsAEOueQjoePKzY4Kl9LnrbOU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B53A83858D26 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-62fbfeb097eso6348118a12.2 for ; Tue, 23 Sep 2025 03:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758624823; x=1759229623; 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=PUpfRLJ5a+LVYINWE111RdbmuA1foUWLi97X11E0uzE=; b=TaLqUoT10x5cNUlVZ6oJ+72YJvDkLY8EVRWN1m2HfNoTjD8GNYz5dLplwPjnjhZJQJ zTp8AZ6eC1DU1ltBS0KQVl/AAfbAyZzRPXP7m1wpPcVznvgcxDsJd3KTxqrNkiPQKv6a y2yCLci8VHWlPPneDwNZBK5KFn+8FLjHSyYx5zntc5dnadtD1l/46w9/XoAC1uxFmh/O uLKP16Y6RAuXUBky9FIVmNrr/yyzOeHfti8wIYkg6/zwsU57UN3WrHk0nz2DSXZmJ2ET a3z8OfvOpLdB4l/Ylvd0kANhor2aK3DJJVSoGvSAwW/wT0kKuyxSx4xQgJe2DNa6+9J9 MAZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758624823; x=1759229623; 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=PUpfRLJ5a+LVYINWE111RdbmuA1foUWLi97X11E0uzE=; b=N5VmRuaUJthUU++2CQeBbSgMvxp3nSbRGNaijjf03ptKsD2GxuQm27WxeHYvFL4mvA nz5AdY8Ja3DbPryiJk9mBBeN9nXxjl5ZWB99wG2y7wPkUQAXCJoYJWbhQ9XxCM+aUWmS y24rjVDBP6eHMwS4oakw76LV5bh2yICDQ8Olp0vxWNUhs50v+qYBTfdVC/fEFQHTSor9 islYU1OVnlRhOcoxKBQX6cYPSSGw/CI/bAYhTuGLpKRGGJMN55Y/pg/QLCteH1xVNYvY 2avTqRg10RUz5o2ej5YPKU1KZCBr5IqZVhRRcKIZGbGJ1UHo5uUNvSH3mUUCyqBvi3gJ /rxA== X-Forwarded-Encrypted: i=1; AJvYcCXMIWeReuklgdVAKkqTSYbViYSoeZGoWAuznoff4BVpIeCalv69k3V7Mx1XdE65OnFFjji9y85bgSpz7g==@sourceware.org X-Gm-Message-State: AOJu0Ywm1fB9Pa6m7mcNNYv7f80+y5ZS++WjtrmsTHU1yOTpOAWOQqUd BIizq2jLvmwev/FMfLX35palO5lfSca+RDnyMlxlUiQ0+2jCj/3MYR2K+lCQ+rlgSatOGlPB3Pb UJ0+rc4xfiiRvl0kNN7pg1P0CNj371Is= X-Gm-Gg: ASbGncsHKuI7LAK71M41OSoiBiZMXa6TWZIHDh54/h2Btu902gM3bq/PDHxr5qXbef1 gRPFvcmgN6pzbsyQXkYWsR9Mzd1EtrT7GyP15PsF8uaGqbHigTQVSCfGaNDJX22XX4b6Mi0xwee xKA5MqN07T5ZJx0b/rHF6Yz7WHFE7XYKBhZd/zR3/tgEshprg7q4O8QM9m8psRsVMM6vTCh86Jf EvATas= X-Google-Smtp-Source: AGHT+IFRCisfHwzv3efxqvDeq2QuMm4QlbITfcjC2qOioiNopUpxfu4SJDr3a90s2CZCijnD/8yFnHqvAyoX0COwsiM= X-Received: by 2002:a05:6402:51d4:b0:634:505c:fc9b with SMTP id 4fb4d7f45d1cf-634677f65efmr2232972a12.28.1758624822983; Tue, 23 Sep 2025 03:53:42 -0700 (PDT) MIME-Version: 1.0 References: <20250910093804.16250-1-timurgol007@gmail.com> In-Reply-To: From: Timur Golubovich Date: Tue, 23 Sep 2025 13:53:30 +0300 X-Gm-Features: AS18NWDGbJdRiI-ijPppfrIVYmYHAGudd791wuOz7Ul-UA4w7gdEEJNo1nf6o7Q 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! One more week has passed, so I am politely pinging. On Tue, Sep 16, 2025 at 3:31=E2=80=AFPM Timur Golubovich wrote: > > 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 grou= p > > 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 = now > > 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/Makefi= le.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 *gd= barch, ptid_t ptid, > > return 0; > > } > > > > +/* Function to extract syscall number. */ > > + > > +static LONGEST > > +riscv_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *= thread) > > +{ > > + 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, st= ruct 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_num= ber); > > } > > > > /* Initialize RISC-V Linux target support. */ > > diff --git a/gdb/syscalls/riscv-linux.xml b/gdb/syscalls/riscv-linux.xm= l > > 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= .xml.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/updat= e-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.s= h > > 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.c= c > > 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) overr= ide; > > }; > > > > /* 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_sysca= ll". */ > > + > > +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 > >