From patchwork Fri Apr 26 01:46:26 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: 792331 Delivered-To: patch@linaro.org Received: by 2002:adf:cc13:0:b0:346:15ad:a2a with SMTP id x19csp232892wrh; Thu, 25 Apr 2024 18:46:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXt3tM4W8z8fHzej7q+JgEyMseYXJCGwMdg7bFcZ0uJvaCZH9GJ87Z6Qc0TsK4aqnGYTdWHvOWh+j3Hr6WsefjA X-Google-Smtp-Source: AGHT+IFRbiMYk4dhPH1cUbMDlHbits1CApAXjTIWO0awD1/+RzXimCQvQIRrTCg+3ZhFbg6orfue X-Received: by 2002:a05:6214:dad:b0:6a0:8dc4:8174 with SMTP id h13-20020a0562140dad00b006a08dc48174mr1639548qvh.44.1714096013559; Thu, 25 Apr 2024 18:46:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714096013; cv=pass; d=google.com; s=arc-20160816; b=UDUg084gZWodQ2uepvf4yhik60HzfMd24LIpGbiy1aIMisi1Fgzvpf026Rz3oHN88i +H8JaSGeBcaEf/iMPokjKHMlpr4/ExvytGi6mv25psULQ4t/1uPRctse+3XIVXCSac3G S3576f91iAyob5poO+A/HHzP/IX7VPfHnUI3TkhMFZCt+d2R8QEtN/ZYlsm/bn4MJaZ3 ewKx3sTOIgwgZj9K/wCDCrbNmQ2SxbTR+qO3v3UzLMpOLAtu7EqNZWtmGJPLldFeNlq9 gwJVIvTC59vUAkfkPjwF/UraL47LQkdlSTJ3l0+fEugQ9yYRKQ238UtjEJ6qW33oVlJz ehrQ== 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:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=e6pzQ/V6ED+l3Gzj0+m1gA7wz5sgs47eeU6QHj2+sS4=; fh=y/ZCQqSANpq/59o3vprgYq6u8DsuqvIy99EFJaMciK8=; b=rvZpNiO3EYjv8c7y7VTH+q/h97wnPHsd+UlQEZ5prmqmgOz3lnKnKAxMp1+Rhgq+xf 040qPwO3VMktMNEYdAZoFITIAtbTzvNyGSzLSktJ8X421y0Rs+OCplH/OyL0reimgKO2 yA6VXsmjytrYMjhwq3apucqUkD9tC7/Tonmij9kvznMZTq8A1plKccrRUwHosymlSfU6 DZS+rqphaOvzBuXFoC6ozd6DNcapVMwNOlhsH3L/rAMK4ZGAfsWeiuuPiaaFQoHcfPCF ZfmqjY7Y35EkuPw1MXEhdn7K4VYAFFFk1c0gD0k1RslrU/QQPkVBjVancMtCMw/f60vj wH2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O6vhDEn2; 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 fn10-20020ad45d6a000000b0069b1f1c4be7si18875501qvb.166.2024.04.25.18.46.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 18:46:53 -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=O6vhDEn2; 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 349AB384AB54 for ; Fri, 26 Apr 2024 01:46:53 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id B9E1F3858414 for ; Fri, 26 Apr 2024 01:46:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9E1F3858414 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 B9E1F3858414 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714095993; cv=none; b=uiWcyEs0J9TRq/sRUr6YzPSHsMopKRj0Umu4G3I9IwfTrJmaVnlhCSpt2ahAytMZ5iViUOI+M7mr0IWH0JMloTvhW1RUIfqsOD7sxRyN4+l3ttYwXE3Ktvir041uMmMKWb44IYKMuKJiG5zRcIs/1WLUNuBrNXZmDgb76YJH59I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714095993; c=relaxed/simple; bh=3D8hW1ZaagF2R9vIBmoj6ydo+t0RuKq8XCOCK2USla8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MfZfWHR2tnnsPfrLd3hV8qTo9zmZ+CGdVLXEi1ei7ZqaDGN7cz9DkafyDG7wZPW5a9S/kZbzTB2C8MDAA1p9bkWXFRIHp+pOfnpwB4YTdY7DtnnWDiDoYa7NyFBGYC5+eW6bPxQHJDWHRrBQlh8birBxcJA+67ynkIE4ormI9/A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1e2b137d666so12515875ad.2 for ; Thu, 25 Apr 2024 18:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714095990; x=1714700790; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=e6pzQ/V6ED+l3Gzj0+m1gA7wz5sgs47eeU6QHj2+sS4=; b=O6vhDEn2xPTiQqKS7Uv7Y4ln+PtdVRMbx9dL5oavdqH2QWQmlm+FTJXL7a8OSfsqOK qQkv2aL2cyJ8U1O/VcTPV1F1JTP3l8mw2xdJomRefOisZuqFqJRdYcdKZ1erndGFK43n Q6avdjW++jAWUV5jn3XKOn4jb+kSEh8kOGVvx4VK2VzXa7dvgJcZdU3gCCjemXK+u8rU 0Aah5Ol+mTdvZvvQj6VYfGPEgRYSmN7Y2Hx1BrrR0IVm1jbXlXHft1KaAjJSsIcWPNfm +cm42tuIMc62InKkgXojJTG78xTy90t/riGDsKgAOv8Cyyo+wiEHvljQy5oH5lzZY+RU gW/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714095990; x=1714700790; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=e6pzQ/V6ED+l3Gzj0+m1gA7wz5sgs47eeU6QHj2+sS4=; b=w7FsI7NUFVQpG/lWkBlBo3YVvtjKr4RoDdGdBfjmvR0asojF6BAfz0AHHjBxHhL0Fu S0pS4gYC33fyRGPRzM94RyCZ0nfrJAePdx8klz98IKL6iGE6oe4q52zVTrkritowxLMi aLd5N1do3lSXh/7ZfssfX7CwMZYx/hOT+qsKox96bpmfGfOtJMq/yPYZKiV8gN06ywab NfH9ZlnzaUzXb/iApZl7JvqJE9SOQVgnHUSdudgn7Szg2nOT8FKwJ0bm4w65O7yA0erb poiTYiLPmPFydovZsUlJMKZ4HddZ8Y6whtDq0Z+Klc9tevN70gRkd1EWR61sCjG/kbEh HP8Q== X-Gm-Message-State: AOJu0YwO8w2bD4PNV96S8J4UUJIKQ/7Gbx/vpetItDhv6YBHU/bdkzTp 1eeLa2/6yPnoDDTj/AWEO7picqhhqOfVmtFQa9JKbHeueSSj2DLheXBcOxbmdle7mH0QeKONj8A S X-Received: by 2002:a17:903:2450:b0:1ea:9585:a07b with SMTP id l16-20020a170903245000b001ea9585a07bmr1806816pls.0.1714095989624; Thu, 25 Apr 2024 18:46:29 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:8e77:627f:e823:2d9f]) by smtp.gmail.com with ESMTPSA id im15-20020a170902bb0f00b001e45572a253sm14716964plb.14.2024.04.25.18.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 18:46:29 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Kevin Buettner , Luis Machado Subject: [PATCH v4] gdb/testsuite: Add gdb.base/memops-watchpoint.exp Date: Thu, 25 Apr 2024 22:46:26 -0300 Message-ID: <20240426014626.1668298-1-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 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 --- Changes in v4: - Also accept memmove symbol for memcpy watchpoint test (Suggested by Kevin). Changes in v3: - Reworked "continue until memset/memcpy/memmove watchpoint hits" tests to have a chance to work even without libc debug info (Suggested by Kevin). - Dropped "require libc6_has_debug_info" call (Suggested by Kevin). Changes in v2: - Ensure watchpoints are aligned to 4 bytes. - Add kfail for arm-linux. gdb/testsuite/gdb.base/memops-watchpoint.c | 45 ++++++ gdb/testsuite/gdb.base/memops-watchpoint.exp | 161 +++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 gdb/testsuite/gdb.base/memops-watchpoint.c create mode 100644 gdb/testsuite/gdb.base/memops-watchpoint.exp base-commit: d3c2603167baf9f6fea006f8b747b8186f89b177 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..cee2d799c67a --- /dev/null +++ b/gdb/testsuite/gdb.base/memops-watchpoint.exp @@ -0,0 +1,161 @@ +# 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. + +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 -1 +} + +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" + +# For the tests below, split the pattern matching in two parts: one for the +# watchpoint trigger, and another for the line showing the function name. +# This is to allow the tests to work if there's a properly named symbol for +# the function, even if there's no libc debug info. + +set saw_watch_trigger 0 +set saw_function 0 +set is_supported 1 +set message "continue until memset watchpoint hits" +set watch_trigger \ + [multi_line \ + "Continuing\\." \ + "" \ + "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \ + "" \ + "Old value = 104 'h'" \ + "New value = 0 '\\\\000'"] +gdb_test_multiple "continue" $message { + -re $watch_trigger { + set saw_watch_trigger 1 + exp_continue + } + -re ".*memset.* \\(\\) at .*:$decimal\r\n" { + set saw_function 1 + exp_continue + } + -re ".*memset.* \\(\\) from .*libc\[^\r\n\]+\r\n" { + set saw_function 1 + exp_continue + } + -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" { + set is_supported 0 + unsupported "symbol for memset not found" + exp_continue + } + -re "$gdb_prompt $" { + if { $is_supported } { + setup_kfail breakpoints/31665 arm*-*-linux* + gdb_assert { $saw_watch_trigger && $saw_function } $message + } + } +} + +# Note: Some architectures use memmove for memcpy. +set saw_watch_trigger 0 +set saw_function 0 +set is_supported 1 +set message "continue until memcpy watchpoint hits" +set watch_trigger \ + [multi_line \ + "Continuing\\." \ + "" \ + "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \ + "" \ + "Old value = 101 'e'" \ + "New value = 114 'r'"] +gdb_test_multiple "continue" $message { + -re $watch_trigger { + set saw_watch_trigger 1 + exp_continue + } + -re ".*(memcpy|memmove).* \\(\\) at .*:$decimal\r\n" { + set saw_function 1 + exp_continue + } + -re ".*(memcpy|memmove).* \\(\\) from .*libc\[^\r\n\]+\r\n" { + set saw_function 1 + exp_continue + } + -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" { + set is_supported 0 + unsupported "symbol for memcpy not found" + exp_continue + } + -re "$gdb_prompt $" { + if { $is_supported } { + setup_kfail breakpoints/31665 arm*-*-linux* + gdb_assert { $saw_watch_trigger && $saw_function } $message + } + } +} + +# Note: Some architectures use memcpy for memmove. +set saw_watch_trigger 0 +set saw_function 0 +set is_supported 1 +set message "continue until memmove watchpoint hits" +set watch_trigger \ + [multi_line \ + "Continuing\\." \ + "" \ + "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \ + "" \ + "Old value = 100 'd'" \ + "New value = 114 'r'"] +gdb_test_multiple "continue" $message { + -re $watch_trigger { + set saw_watch_trigger 1 + exp_continue + } + -re ".*(memcpy|memmove).* \\(\\) at .*:$decimal\r\n" { + set saw_function 1 + exp_continue + } + -re ".*(memcpy|memmove).* \\(\\) from .*libc\[^\r\n\]+\r\n" { + set saw_function 1 + exp_continue + } + -re "in \\?\\? \\(\\) from .*libc\[^\r\n\]+\r\n" { + set is_supported 0 + unsupported "symbol for memmove not found" + exp_continue + } + -re "$gdb_prompt $" { + if { $is_supported } { + setup_kfail breakpoints/31665 arm*-*-linux* + gdb_assert { $saw_watch_trigger && $saw_function } $message + } + } +}