From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BYe5D4zbsGgDwg4AWB0awg (envelope-from ) for ; Thu, 28 Aug 2025 18:43:24 -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=LqcWnw/k; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2F7D01E023; Thu, 28 Aug 2025 18:43:24 -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 E2FEE1E023 for ; Thu, 28 Aug 2025 18:43:20 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FCBF3858C40 for ; Thu, 28 Aug 2025 22:43:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FCBF3858C40 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=LqcWnw/k Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 7EAA73839E19 for ; Thu, 28 Aug 2025 22:42:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7EAA73839E19 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 7EAA73839E19 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756420960; cv=none; b=H47XeTTVu33og4E0ujZAhFaioOr1wZb7AF0wRhK8tSR/ax6gmNmkPfyxWE+GwmFFz+iMv9gxBt1iFqPa3HZJ3KwTUpdjs1lq9tcCb1Gzckwuu9VPjgcNkMgLJB2gZnNd5yD67ZqaX2fY329miLIsMXYbysHLMf1S8NM53r/t99w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756420960; c=relaxed/simple; bh=3C5fU/GNq8sLDAaH56fySHbbyKb141voDPi2YW8xe8s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=NBSdLQBqIRQH1Brv99iGn07Y8+tujOZDS45lp8/VMOrGwoqQ5eglh86OZDL6/W+YzM2U2LHfFV8OaXpJzfICfxOb/Qx2XAFMtI/QcR5Y0drsSVF+YuLB0yXqs072nq1oolv0cOND8lzSvnhoAggL5kwuRL8pDTh83hQTsMm1P+A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EAA73839E19 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-45a1b05a59fso10460625e9.1 for ; Thu, 28 Aug 2025 15:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756420959; x=1757025759; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rIB4tb5hMB3ypFs4VMES22m0OnFFFpQKwxEbQ7lGbcE=; b=LqcWnw/khbZWYPkj5nOIrgNv5Q6iYvyDvOnjJIQaqSIh2BFSycXwE/yxFm2t7P5hf6 3PdvTG2m9lqUK6gdQtG0JtCxbSZwhRLio4rzauafl4l2PoP8yODywaAM+Mpc1flxnEyP TAD6WcoixF5YRqGJNaaS/CskeSMEsrYlfk/EoLol75dyFRRIBGlYDJnCc1MP3qr2C447 ssCy2FtgoPNrFG7Swpj0Q2yGDHD44gUG5jgmEHRpVceuvWtU72OGYsgygGI8JzSuWSGq IjmZPs0osSiQ5LkFie2LxeShcgjY/XwAFb0aNZVE4Zbd/O/hltwnMHCc2A3XOmUdkGtt KJLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756420959; x=1757025759; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rIB4tb5hMB3ypFs4VMES22m0OnFFFpQKwxEbQ7lGbcE=; b=a91NV+tzRW2qnllQ0gzlvqM88nPfni8d4tNXjoYparlqZMgwjWbm+3oo4CN/142C/c l99ab2MWTcwq477cr17WNDHNxE5TA31tjxC89jBMkqGx/O8hBmR91SJvv+Eya48o96Dt C0gFbtk6+mcwXlMTYWfGLkzADcldp7KH39gw/vUgfWLA8fJM1xN9iyXjBER5ZFV7GNpF g2jHfzBgqWCCTRrFzj62AESMULMHI1LG6QRKtIiq5XJTGVIa+f4PDbDypF23AC+HogQD 7fYKHCA4PaSAaBw3PbOi9y1vK6kGz1Oc453GdAvlzI/KoR8bZowOndCKXO/bkmbIWrg+ rLbw== X-Gm-Message-State: AOJu0YykaAbfiKKR6Cv4nJRPDHQePc8JU2apXHLDr/JkAKK9dwZGip/i HtZhZuQgKyJJ5v3PVwUlNHQ2s/HgDhEVFdYsjk7zBddNVSCFM1Tgt8PEUQdAFOOc X-Gm-Gg: ASbGnct2z5nmrWZk7BsAsViQ+2ExbUDjYgFn58uCJvdbyxf8P7kR/B9+TLcsSfV4037 XY+FZKvl7G81aAgyGIMhvw1ujBquHyWG4FTaSALsF7ZqoW5DW1pW4yCEPXo7W/OmgaIjhtm5gYa yneUKG5zlYkAfoj/xGBJXyb5hupmw5r1Sb6GLp9r62KSGar4aHqxqbFqlcq4w3/UUkm6E7KsS2H uB1geuK3YttA58QVfZeXbs61hHkFaVICvF1TcVS3abIYJQ4jHQOOLo7DB/S82p+Zkec18F6pYGw ZeizgG/sQPrlMoJE35T1ndz42Lp+ej5BzxZLDJf1EJENxCU5Zxt2SefarjwZ/MHgrY8AWzy14H+ 8g9J8wYKBYHV0w85GvN43L0uelpBxB7LVOfj4S1SBvcKGCCwNnKyqA/q6nzptMUM1GpqMjQycza z16k4OTios X-Google-Smtp-Source: AGHT+IG2xf5Rxb6zlSXcgTnTObB7B/bhrebbS8K3YPJhpxUqc6QZ3cMmsmXhr683C33gZIdYi7Xdug== X-Received: by 2002:a05:600c:4f03:b0:458:a7b5:9f6c with SMTP id 5b1f17b1804b1-45b5ec68358mr157808305e9.11.1756420958858; Thu, 28 Aug 2025 15:42:38 -0700 (PDT) Received: from timur-HP-ProBook-440-14-inch-G9-Notebook-PC.corp.yadro.com ([37.214.63.42]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b6f0c6b99sm93194225e9.4.2025.08.28.15.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Aug 2025 15:42:38 -0700 (PDT) From: timurgol007 To: gdb-patches@sourceware.org Cc: Timur Golubovich Subject: [PATCH] This commit adds support for catching syscalls on riscv Date: Fri, 29 Aug 2025 01:42:32 +0300 Message-Id: <20250828224232.206247-1-timurgol007@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 = \ 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 *gdbarch, 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 = 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) + != 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, struct gdbarch *gdbarch) tdep->riscv_syscall_record = 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_number); } /* 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.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/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="arch/arm/tools/syscall.tbl" h="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=2015 ;; + *riscv-linux.xml.in) + startyear=2025 + ;; esac year=$(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) override; }; /* 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 = (int)l_sysno; +} + /* Implementation of linux target ops method "low_arch_setup". */ void -- 2.34.1