From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ilcqCSlIwWj4vD4AWB0awg (envelope-from ) for ; Wed, 10 Sep 2025 05:43:05 -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=g/+b5BtG; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 121F01E04C; Wed, 10 Sep 2025 05:43:05 -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 C5AA31E04C for ; Wed, 10 Sep 2025 05:43:01 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A77D3858401 for ; Wed, 10 Sep 2025 09:43:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A77D3858401 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=g/+b5BtG Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 49D063858412 for ; Wed, 10 Sep 2025 09:38:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49D063858412 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 49D063858412 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757497098; cv=none; b=UxQVzq4FHAalvviK9INsUJjXuH27OsyLn7nKux86VxEgnqVhhCl0enU/842Jm116MplCZJf8CO1Om/PgC4q6NtR6kBdUc8RlXiwYzMi6oq2j772XeAg8Gn2ex8UxKHObaWnBxJkcYkWbl5FmHh0vn65UUu1542skm+b3I+zH9qw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757497098; c=relaxed/simple; bh=sASpH4EvTEZjgvuKtHrpV19Eh4o/z+T+lK0LtxklutA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=fOVBwpDB/AC4R02tGor9jBODxicGxJLRv0GSJGpDQAZ4veKFQ9dsnQDXGuXOoXe4orEJttQFB2ByZpQZPpId8XCODwlicxQd4/izIpuM22qbkwWLRencghw8QW+4sEKK+uKwIj0DfFpojdGU6hra919jTOOCkajq0PoQO8d5Ztg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49D063858412 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-5688ac2f39dso1793436e87.3 for ; Wed, 10 Sep 2025 02:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757497097; x=1758101897; 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=04dxKNTltnxv08KuI32YSE3+wy6wbjXuyVcNiKMlIwk=; b=g/+b5BtGiRLVrC6qs5zvsvVdTs0F/yjNW3YJAyN2+bv4jGKQOi6Ce07BwGLQVzl8hb e0hbVapR7aSwkGUwaMKCTRizuePDmSs9faEg1caaoyxAj8OcIx2fXj37oNmxpI5iha15 mnQeHNR3gErq1FvwllEhsMRbIQH8BlLFK90cp1lwe2SygRvP+dc22+VZsEWZ/C8Qtxwh bp67fo1d15KzTHzrPh55q4vO2XGobmqndBgQ1E853nC9cmQ63rOWN2g3CQnetE9ZJgSE AF2PIgC/nlum2+JoVw5EPg5oKt/cHSw/3pneNsQmMd4MV2wQ7jWN6tiaDZDPk2Tjf+UD 5IeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757497097; x=1758101897; 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=04dxKNTltnxv08KuI32YSE3+wy6wbjXuyVcNiKMlIwk=; b=Vb1RcOhZ+r2NiEZ1k+j2bOxe1WgyzKe/Q1w1OXuEm4Gl6/UM8q/NNMzKziIFcmqJ8X RZSlpFpzhlnKlgD2ejEzOMgnRrVUa4H1UhuN9qZgN6S5D4HnJb8V+RxULYlWbVgifEow UfenLmnS2bkACmlIl1hmxIgSmNsfR9LfvraRpvm2Bw4HbTopclPaazpcc1oN2VDraPXq VloTSbBBzYjqNPonwSrcLmNomltCtw3HTFGCANuApo6FdzhyeRCozvgj0RqLo+qzoFa/ +IvaPDm6IKuvnIXaFYKRdYS07YY+/GlXPOLaPnlkfL05h5XPU8tW8yjIS5KI5C4Ef2PL vihA== X-Forwarded-Encrypted: i=1; AJvYcCWUjiqslOdR0IHVuyEjM6Zpmhp6fuXo8isZqh6UIerCAfoA4R9ZLAqcWpK5+SS2Izig20BVAG5xkd7Mnw==@sourceware.org X-Gm-Message-State: AOJu0YwCXqzuBReNhlP0/4+45v+M6t5KeS5iwuarpWXbUgQOM4luFVP7 XRfucRTbG20FR9Wbv7CRACyLvxg8R5BWUQ8y9uFp7uoOUs14RzgB2lmbJnRFS4zF X-Gm-Gg: ASbGncsCxsG9n90ZSK2zB1YPN1/MisMbkDjieki0GCkwsRUSTUp03JPHaDkmJay68CY FKR8yXbJoTFhpVr9XrMYGo9LfmcKZpkmbiWf+4E2ndeeSNCRKSKlFf/xZTbMRqHA9YMHbnQIXh7 443WtLIus3gCz6Z5HRCLYsxgsW6D7s2OILOkepINBI4ztOX3pXXqC3UuMrPe1AqQBLJf6fufbdD ItYiKFMO86wS/nz+BsYdA8POhWkqooxP6Ym4R1ULPSRhOTYKudzPcQEXzWcTvOqNiGVvdNaYX6a bRXtiL2PxNxf6SFEvQzs0+LeWiwapDU7HnR30d0/jB5mM37wl9HZ+J1ti3ngPNMisccB2esyaXl FADgJFmyxI0qGxtEt1IjBbhyFtX+S9pzyh2xkG5DJOjnGuDWtOcFiH18S7whya98HGhPLrnpaHS U+cxkfQOCsbkKmyUiskl2m6wb4rmeQtlvJmodEum8OseNKrVouLVznir6wXuU= X-Google-Smtp-Source: AGHT+IERQ1IJU9DqQmUz+Hk9C8MOcXsytlBFKMRhkQa2wPmE3TLAxLbbbYd2+TaeaFDo+Ynv85GvXg== X-Received: by 2002:ac2:51c3:0:b0:55f:48d6:1cfc with SMTP id 2adb3069b0e04-5625f5362e2mr6168946e87.3.1757497096285; Wed, 10 Sep 2025 02:38:16 -0700 (PDT) Received: from timur-HP-ProBook-440-14-inch-G9-Notebook-PC.corp.yadro.com (mm-217-163-124-178.static.mgts.by. [178.124.163.217]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5680cdee07dsm1136982e87.53.2025.09.10.02.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Sep 2025 02:38:15 -0700 (PDT) From: timurgol007 To: tom@tromey.com, gdb-patches@sourceware.org, tdevries@suse.de Cc: Timur Golubovich Subject: [PATCH] This commit adds support for catching syscalls on riscv Date: Wed, 10 Sep 2025 12:38:04 +0300 Message-Id: <20250910093804.16250-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. 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/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