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: 88823 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0FDB83858294 for ; Sun, 21 Apr 2024 22:27:37 +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-Google-Smtp-Source: AGHT+IHc/+aolU8hwpv90UEd7xiQF/w2Gf5Q4OaT3unciga0JUZfOMe5n3VosWnuyVWOThZ7ego8Jg== 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+patchwork=sourceware.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"