From nobody Mon Sep 16 19:49:52 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1707508150; cv=none; d=zohomail.com; s=zohoarc; b=aLJG8SDszSBJD4jitXnf29K7Q3kNXIixp5a90/clVc99jRJz38VWYhP1vIvTelBa+n394D/9SJ5bPt1Fh/HuXDIhzkstm6HEHs4pbZ4Tc7Uz36sQkmyhh1MYRbLKLDTaHl+cTx7pqaWQUB9oljZoy5uEWHPhVLWpuyzDeWl2jfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707508150; 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=0d2pZ0e5UPseU4WURy0h/XaynSRo4oQrGrKaJsFP1mk=; b=LMNe1xw4J1t2jyfFAjAszdEK9r1Ex8Ydc352oYhwap2WrU2EaaZsmOBRfLrDZ/G1SbmVPtjGFHHWpyzuWRV3I042SDHA5qvLFsvnXs4oeIU7vRjVtlSxjYh7pwSL2L0aLtL4VZi1afMER8VAQqyuMZQqZoE0PegX0YBYu1zbOWc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1707508150082205.52296902007254; Fri, 9 Feb 2024 11:49:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYWrG-0006CD-7k; Fri, 09 Feb 2024 14:48:22 -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 1rYWqg-0005XN-4U for qemu-devel@nongnu.org; Fri, 09 Feb 2024 14:47:46 -0500 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rYWqd-0005Bs-CN for qemu-devel@nongnu.org; Fri, 09 Feb 2024 14:47:45 -0500 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5114cd44f6aso1727827e87.1 for ; Fri, 09 Feb 2024 11:47:42 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id bv4-20020a0560001f0400b0033b670b0a6asm43626wrb.74.2024.02.09.11.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 11:47:37 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A40AC5F7DF; Fri, 9 Feb 2024 19:47:35 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707508061; x=1708112861; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0d2pZ0e5UPseU4WURy0h/XaynSRo4oQrGrKaJsFP1mk=; b=D04MeVw6XDM2wuEcccS4EWl4dfDc2uL0JAho5nfkoK1E6wkaTHWI7YYnaId0JfBfs9 ieCwt8xZnhKROJZHL/TF9zG9IyRqsES+odLEhlH2kjJrIf3Um5CmG3Vsl3ezUgVVAloo 9WaUR/GjzWIyuV1viOGyat3aNMPSvJ7cOBaj/okNROEwLBlu0AEl2vUE+ouGiNluhAl1 9VWb98LzIutt4sV99bWgtqbvH523ne1P2jxRa+JM83/JA1+TlQYymLBhpqqZukogU8lh Ij2Kq6HPrP6nVelIIJSqcXlc3WA6MO1s1I0vrk2Qj0LoymvV2qOCgP61NfNEtSR6v/7t F7kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707508061; x=1708112861; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0d2pZ0e5UPseU4WURy0h/XaynSRo4oQrGrKaJsFP1mk=; b=MU+B98y45T09ZtCJzlftC1oEzVKzj9YJOpyJLvOt1qFYXjY0AixJ9xAJA9hFlTk++D iZ+sRkmVm6NKVHbkwi3NYfq+p/6MHdYMHmDQkZwA2+A3MszXGgao+wLu+1oK0b5JkQ8/ MDYgusRC4owI7wMIkmQAHk1Z7nzA+C8WevQ5glkR+S5MeK0jekdsj+XyU0U4JPS1iWhD xb/AP1J5T/JfLzqMwg0o3QNYqvVcraTALY6D9LAXN3dZETKkSBDUqZ65YhxQ9ocpMX2U uknded/Vz7/++h05QEwHPmbQcZBOea4IJmwiQvLf2M8mK2ghUW3CNoWJfkaABLjOqWQz Pd7Q== X-Gm-Message-State: AOJu0YxN1CUGLN3ulOweNXNXNn2RSHYODeCzplN0GGXSwH8wLgk73l0w XN/skRxgqWE176h+DABV54TDBiShlW3WwBK5DFUoxPrWsK+8Ql9YBYssFpEsGdE= X-Google-Smtp-Source: AGHT+IFo/GcgeTYSLnKUjtLnTsCI+xoMMfe+qP1u0yFX/16OlthLP6p6a5udSi8yIOaMsMTE55ilYQ== X-Received: by 2002:ac2:46c9:0:b0:511:7a9f:58c4 with SMTP id p9-20020ac246c9000000b005117a9f58c4mr13997lfo.38.1707508061303; Fri, 09 Feb 2024 11:47:41 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV+GudEapOEZ8vtHIuZXPTnXLEBWebpO7XOzUgL8Vqawfr9vXcTZobC9GsRAPt6F8h31WrkA2MEJggGgMxf8k3oBpm3nKQghWIUpSSC8SS1EHgiQohmKViknw== From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 10/10] tests/tcg: Add the syscall catchpoint gdbstub test Date: Fri, 9 Feb 2024 19:47:34 +0000 Message-Id: <20240209194734.3424785-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240209194734.3424785-1-alex.bennee@linaro.org> References: <20240209194734.3424785-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::135; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x135.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 @linaro.org) X-ZM-MESSAGEID: 1707508150979100013 From: Ilya Leoshkevich Check that adding/removing syscall catchpoints works. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Ilya Leoshkevich Message-Id: <20240202152506.279476-6-iii@linux.ibm.com> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240207163812.3231697-15-alex.bennee@linaro.org> 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/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/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.39.2