From nobody Tue Nov 26 15:46:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1706887576; cv=none; d=zohomail.com; s=zohoarc; b=lrSh2fWicd8N94YJWXbnXTMYHzeQcRcqksNrUvyCdupD4GjxmmVFVH6gQQYCBkGeXZGno0zEOglC4QbI//Mlm3hiTAJW6d2PNxf/sq8PgZOV3fNdFqAytyDH73rLLhjIjdBYw0iaLSuEV58/4MuL7ce4LdL0nSGdUMV8BhpxU9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706887576; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ThK0J2z926TCL3KX9DE5uwvh5Uu6dZYanJiPNY0QH38=; b=RW0uvjPbtgkNegZFIvb+0ZPIvm+n5OFGTtZudNw0nATcTeyeigw2rhv+qrsmDstZrymuR1IgD7W2Iwd6IYmhrE4lmIQyeDCW+qxw3WOkaIpf1+FzDnficbJaHt+3WHaaoYFM4LnaC68EJCiYCKYNTAIfewq0nYwZLT6sfw/L1K8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706887576443466.82444401479324; Fri, 2 Feb 2024 07:26:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVvQC-0005g0-5h; Fri, 02 Feb 2024 10:25:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVvQ5-0005Uu-FU for qemu-devel@nongnu.org; Fri, 02 Feb 2024 10:25:34 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVvQ2-00073p-P3 for qemu-devel@nongnu.org; Fri, 02 Feb 2024 10:25:32 -0500 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 412EQ9pW026113; Fri, 2 Feb 2024 15:25:15 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w11xrht84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 02 Feb 2024 15:25:14 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 412ECCUl007189; Fri, 2 Feb 2024 15:25:13 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vwev2unyt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 02 Feb 2024 15:25:13 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 412FPCcX36045548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Feb 2024 15:25:12 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2B802004F; Fri, 2 Feb 2024 15:25:11 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BDD8C2004E; Fri, 2 Feb 2024 15:25:11 +0000 (GMT) Received: from black.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 2 Feb 2024 15:25:11 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=ThK0J2z926TCL3KX9DE5uwvh5Uu6dZYanJiPNY0QH38=; b=JVSMP+wIUriuN41ijVL0leUdOm+OAdS6OVmIYcSuDV3cpqPXMorWCBUeCsiUHMCAQrE1 ewOwfeQX94npTqKgd3rJrFYTpwHZ3w3Ya5DQxiULgA8JKacl0EVKsgVya/hbQU//6Dr9 12BmiUnQKeKxKlKOVRWpeAhgkFPi/7F8RqjbIQHWpWeG0595JCNvkiwFbpAhnFXpl5qY hQoC1ZgbFLRe+TZ3c+pa9lCPuevOtGtVEFq1YpOKtUlVFIbiXwrkL3cK57TL3iuy/px9 5FuBo1Y2Av7JF+BscoUFUImUfNcDB4Y/I7mJyMX+XCEeFd0ltX1dgyD0f7FMcvszqJGP tw== From: Ilya Leoshkevich To: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Riku Voipio Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Ilya Leoshkevich Subject: [PATCH v3 5/5] tests/tcg: Add the syscall catchpoint gdbstub test Date: Fri, 2 Feb 2024 16:23:47 +0100 Message-ID: <20240202152506.279476-6-iii@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202152506.279476-1-iii@linux.ibm.com> References: <20240202152506.279476-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: C8R0RJuowzVEYgkl4Aox3qJKE4WTBr60 X-Proofpoint-GUID: C8R0RJuowzVEYgkl4Aox3qJKE4WTBr60 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-02_08,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402020112 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1706887578396100007 Check that adding/removing syscall catchpoints works. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Ilya Leoshkevich --- tests/tcg/multiarch/Makefile.target | 10 +++- tests/tcg/multiarch/catch-syscalls.c | 51 ++++++++++++++++++ tests/tcg/multiarch/gdbstub/catch-syscalls.py | 53 +++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/multiarch/catch-syscalls.c create mode 100644 tests/tcg/multiarch/gdbstub/catch-syscalls.py diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Make= file.target index 315a2e13588..e10951a8016 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -108,13 +108,21 @@ run-gdbstub-prot-none: prot-none --bin $< --test $(MULTIARCH_SRC)/gdbstub/prot-none.py, \ accessing PROT_NONE memory) =20 +run-gdbstub-catch-syscalls: catch-syscalls + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(GDB) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(MULTIARCH_SRC)/gdbstub/catch-syscalls.py, \ + hitting a syscall catchpoint) + else run-gdbstub-%: $(call skip-test, "gdbstub test $*", "need working gdb with $(patsubst -%= ,,$(TARGET_NAME)) support") endif EXTRA_RUNS +=3D run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read \ run-gdbstub-proc-mappings run-gdbstub-thread-breakpoint \ - run-gdbstub-registers run-gdbstub-prot-none + run-gdbstub-registers run-gdbstub-prot-none \ + run-gdbstub-catch-syscalls =20 # ARM Compatible Semi Hosting Tests # diff --git a/tests/tcg/multiarch/catch-syscalls.c b/tests/tcg/multiarch/cat= ch-syscalls.c new file mode 100644 index 00000000000..d1ff1936a7a --- /dev/null +++ b/tests/tcg/multiarch/catch-syscalls.c @@ -0,0 +1,51 @@ +/* + * Test GDB syscall catchpoints. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#define _GNU_SOURCE +#include +#include + +const char *catch_syscalls_state =3D "start"; + +void end_of_main(void) +{ +} + +int main(void) +{ + int ret =3D EXIT_FAILURE; + char c0 =3D 'A', c1; + int fd[2]; + + catch_syscalls_state =3D "pipe2"; + if (pipe2(fd, 0)) { + goto out; + } + + catch_syscalls_state =3D "write"; + if (write(fd[1], &c0, sizeof(c0)) !=3D sizeof(c0)) { + goto out_close; + } + + catch_syscalls_state =3D "read"; + if (read(fd[0], &c1, sizeof(c1)) !=3D sizeof(c1)) { + goto out_close; + } + + catch_syscalls_state =3D "check"; + if (c0 =3D=3D c1) { + ret =3D EXIT_SUCCESS; + } + +out_close: + catch_syscalls_state =3D "close"; + close(fd[0]); + close(fd[1]); + +out: + catch_syscalls_state =3D "end"; + end_of_main(); + return ret; +} diff --git a/tests/tcg/multiarch/gdbstub/catch-syscalls.py b/tests/tcg/mult= iarch/gdbstub/catch-syscalls.py new file mode 100644 index 00000000000..ccce35902fb --- /dev/null +++ b/tests/tcg/multiarch/gdbstub/catch-syscalls.py @@ -0,0 +1,53 @@ +"""Test GDB syscall catchpoints. + +SPDX-License-Identifier: GPL-2.0-or-later +""" +from test_gdbstub import main, report + + +def check_state(expected): + """Check the catch_syscalls_state value""" + actual =3D gdb.parse_and_eval("catch_syscalls_state").string() + report(actual =3D=3D expected, "{} =3D=3D {}".format(actual, expected)) + + +def run_test(): + """Run through the tests one by one""" + gdb.Breakpoint("main") + gdb.execute("continue") + + # Check that GDB stops for pipe2/read calls/returns, but not for write. + gdb.execute("delete") + try: + gdb.execute("catch syscall pipe2 read") + except gdb.error as exc: + exc_str =3D str(exc) + if "not supported on this architecture" in exc_str: + print("SKIP: {}".format(exc_str)) + return + raise + for _ in range(2): + gdb.execute("continue") + check_state("pipe2") + for _ in range(2): + gdb.execute("continue") + check_state("read") + + # Check that deletion works. + gdb.execute("delete") + gdb.Breakpoint("end_of_main") + gdb.execute("continue") + check_state("end") + + # Check that catch-all works (libc should at least call exit). + gdb.execute("delete") + gdb.execute("catch syscall") + gdb.execute("continue") + gdb.execute("delete") + gdb.execute("continue") + + exitcode =3D int(gdb.parse_and_eval("$_exitcode")) + report(exitcode =3D=3D 0, "{} =3D=3D 0".format(exitcode)) + + +main(run_test) --=20 2.43.0