From patchwork Fri Feb 9 19:47:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 771337 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp1036674wre; Fri, 9 Feb 2024 11:49:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXsB/w0rb9mEVmV/Sr8g9YcV7J65vuy/cFW+3JTuR7ZZk/p+kcG9oYnYinoBmGxWv+ueIsClrDXImK7/Z9VqU0Q X-Google-Smtp-Source: AGHT+IHZwYiBdEBZz9fYqjdAJIM7FgtWEeY+YMCqYOvjEG8qg8R4OVrMzpkNdWIu5CZw6XbJ9dQe X-Received: by 2002:a05:620a:39d:b0:785:be68:f991 with SMTP id q29-20020a05620a039d00b00785be68f991mr125893qkm.2.1707508151404; Fri, 09 Feb 2024 11:49:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707508151; cv=none; d=google.com; s=arc-20160816; b=VeXS58VBtOp/ds19wQPyxgIiIWb+gfPeA0WIafloL9ISC8PTqTx91zQjZul3Euhhh3 C3YQK3B25l9R0OpxiGspTlGF/atMj1Ff8Wy7MbtZV+MxcV9KTkoHWam1+XuATUgehKfh Ap6PTTmSw5qXq5EoVm1mjWhs1aWl5koW4aKDWrf+DH0X9z+L98cnOJVPJRNLhwj4jdRp 21SRS1S8MVoDT+E9MVAnM+X+bAHwJ6hK/VUUpWMcE3rNLaittcgJKGkeNQi8CEL3yPGb RSRzc4GmbpkKi3DqsZxh9tug3twIzd5Wo5Fx9gDdimoaiR5tVbNjy9jc+Z8MJ+AYDGB1 L9Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0d2pZ0e5UPseU4WURy0h/XaynSRo4oQrGrKaJsFP1mk=; fh=8NQIUPTerK6UO6HnqnwoQQObssqkjQeOBpMInMJQlYQ=; b=EB4vtW3+Cgg7klVpeeVNAOqzqDOx5fsME3VDYzPRHx3uFMV16dIiNXLr8kDBFTu9am fiTwku/DwHAC5MuawEfLYJa9pXuJP6Z86F4G1bEEVEbQBaYRedAKN9DRdecbJvDPKK9c lP/bdmoFvnm8S+VisnEfOyfINSHqSPsXoQ/ApCqBns2uO65uv296QRWpUIYAF+gtgTCX lRC1UNndXPOlPjxIUa2qteznGoH2ESW5aXQowhWMGOIK9SOWaKg2ad3Z2NKTAGvlxZvS c4Ofruw395ksnjB/1maKlfbxw/v3lPGphSJAKIT6go+txoft2SLXRJ2nQ2jVsXeB2t0i E+WQ==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D04MeVw6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=1; AJvYcCX2B59zSAqlEoyqQH99RnYH+jMRKhzhQ+gMtS/TZF+uHkabTBDbk894iWfL6F8BYSnuznD5C7lCjAOVCdSpCBxq Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id vy15-20020a05620a490f00b0078591341b5asi127792qkn.556.2024.02.09.11.49.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Feb 2024 11:49:11 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D04MeVw6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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== 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich Check that adding/removing syscall catchpoints works. Reviewed-by: Alex Bennée Signed-off-by: Ilya Leoshkevich Message-Id: <20240202152506.279476-6-iii@linux.ibm.com> Signed-off-by: Alex Bennée Message-Id: <20240207163812.3231697-15-alex.bennee@linaro.org> diff --git a/tests/tcg/multiarch/catch-syscalls.c b/tests/tcg/multiarch/catch-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 = "start"; + +void end_of_main(void) +{ +} + +int main(void) +{ + int ret = EXIT_FAILURE; + char c0 = 'A', c1; + int fd[2]; + + catch_syscalls_state = "pipe2"; + if (pipe2(fd, 0)) { + goto out; + } + + catch_syscalls_state = "write"; + if (write(fd[1], &c0, sizeof(c0)) != sizeof(c0)) { + goto out_close; + } + + catch_syscalls_state = "read"; + if (read(fd[0], &c1, sizeof(c1)) != sizeof(c1)) { + goto out_close; + } + + catch_syscalls_state = "check"; + if (c0 == c1) { + ret = EXIT_SUCCESS; + } + +out_close: + catch_syscalls_state = "close"; + close(fd[0]); + close(fd[1]); + +out: + catch_syscalls_state = "end"; + end_of_main(); + return ret; +} diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.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) +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 += 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 # ARM Compatible Semi Hosting Tests # diff --git a/tests/tcg/multiarch/gdbstub/catch-syscalls.py b/tests/tcg/multiarch/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 = gdb.parse_and_eval("catch_syscalls_state").string() + report(actual == expected, "{} == {}".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 = 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 = int(gdb.parse_and_eval("$_exitcode")) + report(exitcode == 0, "{} == 0".format(exitcode)) + + +main(run_test)