From patchwork Sun Apr 21 22:26:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 790694 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp2079639wrm; Sun, 21 Apr 2024 15:27:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0iyz5ugWxkumlZ65h3eXxjPDNRw/uKqvT1xrMlxGSMsp4AOr7CnM5V6GtHv61XOZFWa4L+WSpPxlAd9JCKWLn X-Google-Smtp-Source: AGHT+IHi8IvQtQSGq/ph1gTdPDy23ghtA7rbmvXy4IPYmewDf1bNPfNXBeK+EX93tMwOJ+h9CNxs X-Received: by 2002:a05:6214:1414:b0:69b:188a:f31e with SMTP id pr20-20020a056214141400b0069b188af31emr9335238qvb.38.1713738462726; Sun, 21 Apr 2024 15:27:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713738462; cv=pass; d=google.com; s=arc-20160816; b=e2Xw4N29mj+m+ePqLtqCNTers8qMNiN8jXz/QyliuE72G5Bo5DRi+9xL/G0wulwTUF p/O7bVEd34j6Yg75y/PdEXJPmJjtn8DyJntcIPSdRKfufWlLt13jmbtM+8ZX98gXkQOb zPM/Xcb9Hj+1/pzDhkyPpCpGJrw9OiLiMQ8l7ZOmgiER0FmMDdsT2E8veXXHI3FtmJr2 5oazHKryHyqHvuR+G7kx5ygsXRhRy+vDmNka3R9VF6oRFR/yrbcWVbXNPlSgDLiuQwyP kv0mhYlXXo5JsZdf5wqDyu7QFd0PHqPUo6iO1WxmM6QOFjhiTlrHlll9S9n3dzozRbcx zdgg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=/ukqTm7EusgO/4PrZreRAKZ7V5bilS9/CkQd/KbnJ7w=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=NfttVTo7edq8NcbmakE2M+/TKTPdXH2otkZlntACez7rYyASiX3/h2eutBP9kg+8Ra UTVcrdTJ1UJShkLJBfqcvp2FD2M5e459tV3YgqCexkFL0e9UAj2QxVVo8T6BxsE7Jugd ZzcixfMNoyv0wv7/hd7zOxQadTd7OArlX6tv4OIkXQfEeOIYMxWfK477Irt3wudQibSz ts1xhZQMFWuEJctlZ/BKeUhlI34SxJ1VqSOZVxt8+dRbgLCPVy4YZVGXHDY/9zY0a7tH 2vDn9biktxjrVa+TM3H8QHaNWd0r6+hLNzfE4GNNX9BtEtksurq+DG4XSgvIbPeAixRc Daaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vTMhQNrA; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ed14-20020ad44eae000000b006a081cb5adcsi566927qvb.334.2024.04.21.15.27.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 15:27:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vTMhQNrA; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41BA73858D37 for ; Sun, 21 Apr 2024 22:27:42 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id C5C973858D39 for ; Sun, 21 Apr 2024 22:27:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5C973858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C5C973858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713738432; cv=none; b=p30tv7f6+nAe7GWjFxiDM/JHbtsUsFwO86TmvpH9yxta+ARphKYsv1HVuRxz46wZWCRMZ7pDox7iNf6+z4sy8SmN8AUO2ZNxJTVqT0EKjh2Hv7+UPQVl6c26rF3jl3h0Sx+QmBnqAr+MzNRSkn/OWy2zcolx6NPnsIe1pKMnxQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713738432; c=relaxed/simple; bh=es1Nk4sKaz0Do04kHIwwX55l694pYc49tXV59xPvJ/0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tBBIYi6Whfkhr4aAsk1mgtoiQWtgPg++tRVvYsDoLjQOcK5T65EM0Ql+hPchgWPBTfv9oiLQc1t3Ftf1kM4zHLSAsvf9/Z290hEgBp+A5Acg/n7mEt6G8cNej0X4w4Y6iQFfU4Jc0j1hpt7PHCIkjM2WtuWxdYAxldF7Ye9JkBU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5f415fd71f8so2794004a12.3 for ; Sun, 21 Apr 2024 15:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713738429; x=1714343229; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=/ukqTm7EusgO/4PrZreRAKZ7V5bilS9/CkQd/KbnJ7w=; b=vTMhQNrAwxqJLlfIu/3vphKE6tYmK+GLf2aiV4eE8fXNvPSKA16KjKWh4JjZ5g/UMC m9ukYOu2rNqmsa0h6OjmSmOEb9G/Qu0lSlL7XperCHa8Cs3cAIcIQJmYTRg/HrqDgFIA Xsi7hk6CJ13L0CfwLOUfM/E5VcL2vlW522YQ0GEBQDaa2RVivaB5td3/W7MVQagRP07T 5z7Nxnc6bL5Hd5UiQ4O6qIxWHn4A1JTXG/5jQiMJnRebeIv8PohIKr37Vu5Futk5ltiH BTr4mqJ1ufo1wGOrq8s3DkP0UtSo4H71QT7e2/QQeEpLiudhxRKRXdXByeVrq6DQmUV8 pk/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713738429; x=1714343229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/ukqTm7EusgO/4PrZreRAKZ7V5bilS9/CkQd/KbnJ7w=; b=Ss71wvPXVXGizv52BNCTc821COE329uH/G38p5bT5GrtgjvkiD/4erz7ZHmHZApplX Df5Auxatix57+qT8JeZXwMACIrAEL3QB2B1B857HTPE7Qgd64NLXgDTBSDuyGhBL5Jbs FyPqwfi0bpXuU3unLUU9zvGadJ7DJFL682tyfyPEod5ivTEyE+TYh4mUwjlRS+qp2cVI 8h0C36cghYz0OBpS4ur7rCkHumUeCFrx7ExNN7/Pi0GsrI4Zt0k1gPIin6YIbgsXihsk kGvlduurRdRuWE29s/EhCDumYE1Xru+gHvAvBBJdsNxGAE3Y08zCMmxbWbvs/KuJ56oL CweQ== X-Gm-Message-State: AOJu0YxGrxDR3UJ06fsuUdIINPSEpIqG+0/W38cIsWigQkyGVYNMJ/l+ Z6qv6+6T9Lr7hQc/Sq/nsNvSuDtzF0KT9YdGO7Y2RDHYVmGlQDMn/C+jUIXrwBDO301UFYd5EoY e X-Received: by 2002:a17:902:f68b:b0:1e5:9da5:a799 with SMTP id l11-20020a170902f68b00b001e59da5a799mr9811180plg.6.1713738428641; Sun, 21 Apr 2024 15:27:08 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:3224:7231:e42f:1da5]) by smtp.gmail.com with ESMTPSA id u7-20020a17090341c700b001dcfaf4db22sm6773051ple.2.2024.04.21.15.27.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 15:27:08 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [PATCH v2 2/2] gdb/testsuite: Add gdb.base/memops-watchpoint.exp Date: Sun, 21 Apr 2024 19:26:57 -0300 Message-ID: <20240421222657.1052635-3-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240421222657.1052635-1-thiago.bauermann@linaro.org> References: <20240421222657.1052635-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patch=linaro.org@sourceware.org Test behaviour of watchpoints triggered by libc's memset/memcpy/memmove. These functions are frequently optimized with specialized instructions that favor larger memory access operations, so make sure GDB behaves correctly in their presence. There's a separate watched variable for each function so that the testcase can test whether GDB correctly identified the watchpoint that triggered. Also, the watchpoint is 28 bytes away from the beginning of the buffer being modified, so that large memory accesses (if present) are exercised. PR testsuite/31484 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31484 --- gdb/testsuite/gdb.base/memops-watchpoint.c | 45 ++++++++++ gdb/testsuite/gdb.base/memops-watchpoint.exp | 86 ++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 gdb/testsuite/gdb.base/memops-watchpoint.c create mode 100644 gdb/testsuite/gdb.base/memops-watchpoint.exp NB: As with v1, please let me know if you think there are more interesting tests regarding watchpoint and memory accesses that can be done. I tried to make it cover the interesting scenarios but the testcase is small, so maybe I'm not very creative. Changes in v2: - Ensure watchpoints are aligned to 4 bytes. - Add kfail for arm-linux. diff --git a/gdb/testsuite/gdb.base/memops-watchpoint.c b/gdb/testsuite/gdb.base/memops-watchpoint.c new file mode 100644 index 000000000000..0255cfb43404 --- /dev/null +++ b/gdb/testsuite/gdb.base/memops-watchpoint.c @@ -0,0 +1,45 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include + +int +main (void) +{ + /* Some targets need 4-byte alignment for hardware watchpoints. */ + char s[40] __attribute__ ((aligned (4))) + = "This is a relatively long string..."; + char a[40] __attribute__ ((aligned (4))) + = "String to be overwritten with zeroes"; + char b[40] __attribute__ ((aligned (4))) + = "Another string to be memcopied..."; + char c[40] __attribute__ ((aligned (4))) + = "Another string to be memmoved..."; + + /* Break here. */ + memset (a, 0, sizeof (a)); + + memcpy (b, s, sizeof (b)); + + memmove (c, s, sizeof (c)); + + printf ("b = '%s'\n", b); + printf ("c = '%s'\n", c); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/memops-watchpoint.exp b/gdb/testsuite/gdb.base/memops-watchpoint.exp new file mode 100644 index 000000000000..0edc646e67aa --- /dev/null +++ b/gdb/testsuite/gdb.base/memops-watchpoint.exp @@ -0,0 +1,86 @@ +# Copyright 2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test a binary that uses standard libc memory operation functions. They are +# frequently optimized with specialized instructions, so make sure GDB behaves +# correctly in their presence. + +# It's not possible to check in which libc function the watchpoint triggers +# without its debug info. +require libc_has_debug_info + +standard_testfile + +set options "-fno-builtin-memset -fno-builtin-memcpy -fno-builtin-memmove" +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + [list debug additional_flags=$options]] } { + return -1 +} + +set linespec ${srcfile}:[gdb_get_line_number "Break here"] + +if ![runto ${linespec}] { + return +} + +gdb_test "watch -location a\[28\]" \ + "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \ + "set watch on a" +gdb_test "watch -location b\[28\]" \ + "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \ + "set watchpoint on b" +gdb_test "watch -location c\[28\]" \ + "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \ + "set watchpoint on c" + +setup_kfail breakpoints/31665 arm*-*-linux* +gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \ + "" \ + "Old value = 104 'h'" \ + "New value = 0 '\\\\000'" \ + ".*memset.* \\(\\) at .*:$decimal" \ + ".*"] \ + "continue until memset watchpoint hits" + +setup_kfail breakpoints/31665 arm*-*-linux* +gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \ + "" \ + "Old value = 101 'e'" \ + "New value = 114 'r'" \ + ".*memcpy.* \\(\\) at .*:$decimal" \ + ".*"] \ + "continue until memcpy watchpoint hits" + +# Note: Some architectures use memcpy for memmove. +setup_kfail breakpoints/31665 arm*-*-linux* +gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \ + "" \ + "Old value = 100 'd'" \ + "New value = 114 'r'" \ + ".*(memmove|memcpy).* \\(\\) at .*:$decimal" \ + ".*"] \ + "continue until memmove watchpoint hits"