From patchwork Mon Apr 22 23:06:59 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: 790968 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp57497wrq; Mon, 22 Apr 2024 16:07:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXvmEfq/GJLBJkoc3+1RXaE6wNm9+ZOfCiNndHjIxjuqF2oIW2Knz+TrTgVDLjYzzVlGIgCprydC1LnRkkocPjl X-Google-Smtp-Source: AGHT+IGDdO1YX6Pw4+BuziNf77BEAwfv3LLECWYM0zUeFb/x0Z/ID6O7W8jqZF9pVMCYGfifDR/w X-Received: by 2002:a05:6214:123:b0:6a0:669f:ff2c with SMTP id w3-20020a056214012300b006a0669fff2cmr8811115qvs.64.1713827237024; Mon, 22 Apr 2024 16:07:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713827237; cv=pass; d=google.com; s=arc-20160816; b=Kq2RZciChHfe25orhjwUG0U+8RaaD53IKK52Ant62O1GwcHRVJuLkMbRFddpwnPuea ZLOyDhbsRFW4pX2+TXHl0fDgVqiFr3r7dRbT7cCnIOt372DArzJXyPMQrNs8QDXqchdT Dw1mW/y0Ar8DQqJGAKgpotW0V15HkBeEjYxGp79Upb7BKeV1ukP9Ec2Mbiwn2jytf+1b pPQJF8XI2427J/Bmrm4IIgA2hDnjxuGVqNZto+iRtnbX6ycsAm/E+42Q+XxGnfb/JwBl Olnkv7iXvTX4L4e470XZjdSzPw5KN3ypYU5a7sdY7PjvR1MpD0C2bJtu9bcQcsd+/IRo 9Y/w== 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:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Waq7f27F5L6ywgsBNtXlKHPIZFYfTqbirajDo2U5lxc=; fh=y/ZCQqSANpq/59o3vprgYq6u8DsuqvIy99EFJaMciK8=; b=VNdmBLoM9jmRJlItJiDzkmVRpC/PQ/mmpVMniFbPCSUmKlRSuF/1ap7UBe2z4u/WV3 SaZid/GeAGU9Sbeay9Qnnr+DN7xjHYsNx6bw93Z8dIzHLr//C6uJWTiBvCpcThpxuc33 Bh1nltXvWHBGIQ/nObQJJu7nLcX0j1CcZOMeStcoBrSpQGYcmvrCjxrheqDBEE53RZl7 xR5kg3WEIXvvqqjSrQBINT9BC2oDE0a3BCizhoZmINaIq4Z3jOVrXxKV8IKXjLg9xNS9 BJjkpRBaKoHbL0l/8EhLXCFIsTEuubIpRucvpaRmjPQ354qgmAKmOobOQncUM7gbgA/y IybQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AOizKtGK; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id pm23-20020ad446d7000000b006a07f208bc7si3614892qvb.61.2024.04.22.16.07.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 16:07:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AOizKtGK; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 61E213858C98 for ; Mon, 22 Apr 2024 23:07:16 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id B87193858D38 for ; Mon, 22 Apr 2024 23:07:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B87193858D38 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 B87193858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::532 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713827229; cv=none; b=bgQYtfTo/iEdaoBqxY572h8qb4XGf35joe4B+gA//9hEucnJJmNrz5Lv+ApeFonMCuDq+aQBSSpjztwLhN+UtvDIGxtxqbIkeIDl9F0xvkZJDge39EVQsKGufxwlioVrkgJNrytuztR9xYonGrJ0+s5jv8RMAkNp0rripdWHfbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713827229; c=relaxed/simple; bh=A03BjH/kUFd+vwoQ4oYZY+4chL5U+3YWws8JzC+jmY8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=r7YdUfV4a14qG87LwtC7E//duksMXCeyPKn3iSPJQmg7rxyTUzaM6Cnls+cIfARZsJMcPiuebocsLUxL6kVrqJTaY0wFRzQIOElxN8KfPeBcK/v1fK0rNp8VTP5RfoKczW0TA8SqJzXbdBjHuwUq9BeBrkmjGRTE3cHZhMbGF8A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5d8b887bb0cso3808372a12.2 for ; Mon, 22 Apr 2024 16:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713827226; x=1714432026; darn=sourceware.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=Waq7f27F5L6ywgsBNtXlKHPIZFYfTqbirajDo2U5lxc=; b=AOizKtGK4GYQszYXVGfqSsyvM451u2TsuvqAqCYnsnlz+G4gtZWUh6hALNnGDVvRac TVe+DVP17jEAc0P1TH9mZkvb5LN2TCHXxKSMW82vCyGrDTY1tEqpubMHyESQoMFl6cMU bVW5Qt7KbALZVT9QSehMfgv9XBG2RTqiSJqrQvYnuEIWCmdz16qKglTWBL/PVkeTUKyM +ne+KOjdqWVylxH5TTTPEtY63YHyEO7Tmkae+oDtnBQrRdOCuzJgmq/ddrZ1/BcrBtXG FrccmrHV1BJ/2O/6lC0DbWTit+GpsKMRDUeB1l0HZ+FY/jffPfQcwAnPHX/C/IsrM/XZ UZvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713827226; x=1714432026; 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=Waq7f27F5L6ywgsBNtXlKHPIZFYfTqbirajDo2U5lxc=; b=hoqpiaja3k15lsmdT/TJXJPTvka7lY70vpaKUobChCikg8PICpSHU+Eu149stMzy3r SSzYlhwWQr/XwYJeDfRxZKfkEbchApo+7i/0BCNE9J8CTflFcu7EZBu2BrdiyWVeAABv vqluDcQjZXL2JaqoJX687IxUomZUvwKgcRPrT4AlWorTeob758IhmrB0UBvIIVU6ZHgb okqKJSpjKpJR55lvef9Ctkb0fFjNgeovKfFp7ebQbIUrZMFqk7Y+sAJe0Vqb+ZPYoiwl auJ0vwtWqXBzcHTJVXt/DDw5JubY+nIncflghpd8zzTOKTkC868f3SfPnZIjdhRpyeTw NzQQ== X-Gm-Message-State: AOJu0Yzas9GFgeE1q4KCBTZBzo5RScj/qc3JdWVFJaAm7ECT4tKef8of CKsKHbVLrutHtDzRC/wFzH2m1VL1ZrBsH+nFFBi2k7R6HNSlMgCizIn0jI2L+ckSI1bfFLsbh5s s X-Received: by 2002:a17:90a:5e46:b0:2ad:e74a:f4f4 with SMTP id u6-20020a17090a5e4600b002ade74af4f4mr4713125pji.6.1713827225755; Mon, 22 Apr 2024 16:07:05 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:25e4:a74b:cf9:5423]) by smtp.gmail.com with ESMTPSA id sv14-20020a17090b538e00b002ab3bffb765sm8226906pjb.32.2024.04.22.16.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 16:07:05 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Kevin Buettner , Luis Machado Subject: [PATCH v3 1/2] gdb/testsuite: Add libc_has_debug_info require helper Date: Mon, 22 Apr 2024 20:06:59 -0300 Message-ID: <20240422230700.1173173-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240422230700.1173173-1-thiago.bauermann@linaro.org> References: <20240422230700.1173173-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.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, URIBL_BLACK 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 Factor the test for libc debug info out of gdb.base/relativedebug.exp to a new procedure. Also, change the "info sharedlibrary" test to explicitly detect when libc has debug info. --- As mentioned in the cover letter, the new testcase doesn't use this helper procedure anymore so this is an optional patch. I think it's a nice cleanup, though I didn't find any other testcase that need it so perhaps the new helper is not as useful as I imagine it to be. I'm fine with not committing this patch. Changes in v3: - Include in test program to avoid error when using clang (suggested by Kevin). gdb/testsuite/gdb.base/relativedebug.exp | 13 +----- gdb/testsuite/lib/gdb.exp | 56 ++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/gdb/testsuite/gdb.base/relativedebug.exp b/gdb/testsuite/gdb.base/relativedebug.exp index bf8d76887122..f882a5cf1676 100644 --- a/gdb/testsuite/gdb.base/relativedebug.exp +++ b/gdb/testsuite/gdb.base/relativedebug.exp @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -require {!target_info exists gdb,nosignals} +require {!target_info exists gdb,nosignals} libc_has_debug_info standard_testfile .c @@ -28,17 +28,6 @@ clean_restart ${binfile} runto_main -set test "info sharedlibrary" -gdb_test_multiple $test $test { - -re ".*\(\\*\)\[^\r\n\]*/libc\.so.*$gdb_prompt $" { - # Skip the test below if libc doesn't have debug info. - unsupported "libc doesn't have debug info" - return -1 - } - -re ".*$gdb_prompt $" { - } -} - # pause () -> SIGALRM -> handler () -> abort () gdb_test "continue" "Program received signal SIGABRT.*" diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index cbd37fd30947..1e26937c0dcf 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -3699,6 +3699,62 @@ proc support_displaced_stepping {} { return 0 } +# Return 1 if GDB can find the libc debug info, or 0 and a reason string if it +# can't. This procedure is meant to be called by the require procedure. +gdb_caching_proc libc_has_debug_info {} { + global srcdir subdir gdb_prompt inferior_exited_re + + set me "libc_has_debug_info" + + # Compile a test program. + set src { + #include + + int main (void) { + printf ("Hello, world!\n"); + return 0; + } + } + if {![gdb_simple_compile $me $src executable {debug}]} { + return [list 0 "failed to compile test program"] + } + + # No error message, compilation succeeded so now run it via gdb. + + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load "$obj" + runto_main + set test "info sharedlibrary libc.so" + gdb_test_multiple $test $test { + -re ".*\(\\*\)\[^\r\n\]*/libc\.so.*$gdb_prompt $" { + # Matched the "(*)" in the "Syms Read" columns which means: + # "(*): Shared library is missing debugging information." + verbose -log "$me: libc doesn't have debug info" + set libc_has_debug_info 0 + set message "libc doesn't have debug info" + } + -re ".*Yes\[ \t\]+\[^\r\n\]*/libc\.so.*$gdb_prompt $" { + verbose -log "$me: libc has debug info" + set libc_has_debug_info 1 + } + default { + set libc_has_debug_info 0 + set message "libc not found in the inferior" + } + } + gdb_exit + remote_file build delete $obj + + verbose "$me: returning $libc_has_debug_info" 2 + if { $libc_has_debug_info } { + return $libc_has_debug_info + } else { + return [list $libc_has_debug_info $message] + } +} + # Run a test on the target to see if it supports vmx hardware. Return 1 if so, # 0 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. From patchwork Mon Apr 22 23:07:00 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: 790969 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp57615wrq; Mon, 22 Apr 2024 16:07:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBRXq9JXmCaI4BHEYwFFDdg/0ueqrrWsC6Q72cVJ2tBKvZQ/Wuj8NEQdrxiLX1aDwh13Etx7s+qVVez7gkdfiF X-Google-Smtp-Source: AGHT+IEUs8zfQBv9g9wFuiVm6BjTxvlIa7Ua2tAEyUhXUMnz9vxSGcaVFsK9AJuKXBY4XJGMaRp0 X-Received: by 2002:a05:6870:e3d2:b0:232:f98d:8e21 with SMTP id y18-20020a056870e3d200b00232f98d8e21mr15305297oad.19.1713827257865; Mon, 22 Apr 2024 16:07:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713827257; cv=pass; d=google.com; s=arc-20160816; b=dJ3cMP+GsSGZppWkEQNgr2nwnWE/qmstUpXZRivBm9wCn6y3A+NYp+DGtidEPHrhlh NTpNFYWyYA8EI6hMpxPW6HGFaGnQ++TrGDijZJR6WWHcmVypnSKgizy9R2ab/NQMDR6J snZo9LAU6QS/9zsyoHGA9SUahgAxELK/H1A58r/Qm9LCirfGFihJQxo8PqJWFaN2EikN kU2yxZ6DUTR0cWJZa1telq7LMa3D0VY/dhLrwyBHqRL1ozCPPogAmY81C8pTplTlvEUC cSPkOqj4AeZvkCelsHnXZOPETVrtBXxFtWfSFYH2TRNpq6h7WdAPb4VfFWKT/TgDZDhY cmUA== 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:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=l5XbXj66666gwRBH2tRJXHEMCWVFhx1bgvIMsBmSyWM=; fh=y/ZCQqSANpq/59o3vprgYq6u8DsuqvIy99EFJaMciK8=; b=ynJZgf5hGXr/NhTwC8nVDOZEas9M4jcQT+aJA0Bq4h+DNglrB/HUTxLDcqZTetyU6V bFC0/WMgUUL/L6oTt4a3BXobH7zgF5yv5MzkTJXtL/ZNm8qpnu8+PMbYFDwGPAYjQm+J SalaqlXZK50BTygMSLzil++cjaa4egYi7ACDPkxjhao30VWFdEBwQCb70y2NrM3ttntf +RUGEq5bavKd5Ig1RCRvRVDDiz/uQQbAYzSRWQg0IM4qK0ddqRTP/8uKU8WcTmEv4npT 5p2SbZNTKxf7fmXJ8GLYgOuwsE670BAaewjxvZXZU0vEzbE9Hh6B3nLPA65UwkRYYyRW Jvmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ze8m6uSm; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v10-20020a05622a144a00b00434f39ed0efsi12080320qtx.68.2024.04.22.16.07.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 16:07:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ze8m6uSm; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 76C4D384AB65 for ; Mon, 22 Apr 2024 23:07:37 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id BFA803858D3C for ; Mon, 22 Apr 2024 23:07:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFA803858D3C 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 BFA803858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713827236; cv=none; b=cfWHPnI4nRd79tAoKyPHmGr5vcS8hAJh5LiaUY5I6qG+BikS8rxvNGYHfpdHsb4PkbgsyyZmlO6DyUQK3rnEVhGuCUDKO24NuGtczRjxJzLUalJEJtIuPCMgm6Aq2ErfLiuEwoDscJkOPt+NUalTcZrJrMUf5Meyr2RIu9ue+no= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713827236; c=relaxed/simple; bh=YuOjanYLUVrrOzQD4ouhpVdnV5bOT5ZfEq1Es9Lb8V0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KXEouvLrf3njGnWTKBlt5Ja4tD2Fa08/nyYHrYPAoa3kqGBzG0d/RW4Y5riwlW160wBalCa1Q6DUarKHlTrRu0bOW/kcPXb/ICGFhcFsoWaj/E9hkM4sNo2BWPvXUjBLkN9oDMcJek61li9AoCknXmUL6ShBhL3TCR80TUJJ75A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6f074520c8cso4863122b3a.0 for ; Mon, 22 Apr 2024 16:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713827230; x=1714432030; darn=sourceware.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=l5XbXj66666gwRBH2tRJXHEMCWVFhx1bgvIMsBmSyWM=; b=Ze8m6uSm4I78xevN+sPjxDTry4MtISqWXJaqSiddgv5LO6IPDUIIUUf4hIYLuo3B+V ESxPPYiWnmgKRJA7lOCHCQkjq72XVCGeCvwY3nWrPyhpqy3y+xQbDfC4Jedvn14gYpDk IUWTyz6SCh2+0Tq0YKsga2qG58OzuBpLRWmiciYOTvRkOaYkwqCQryIH6QmvzTkFj9j5 Xb6uYmUHApGxTvjoc2j2R3EAFqxdWd7Go/lNYh1IT6tYN7i5QBNpq5WV/vrid3vZ/YG3 cwpxKExTMUCUXZE5WQYuTMAWK5P8IS+UeSHmAx8+z6h9GnMv5jRoJKHuoV7TZSHYlTm5 2+XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713827230; x=1714432030; 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=l5XbXj66666gwRBH2tRJXHEMCWVFhx1bgvIMsBmSyWM=; b=hR3+yV0X5+pFpyZUTM6YdcDwffnqmnfkbKrXvz8b3GNqoJ1UkMp9Qo3pvA1aXXkZpr VPIvzuIo3AeHOAeVkBi/ccliqw3PgqcApv9OB+pfimP7+v2rkoroNjOZ5EMRnV+0DMen 4zSKvhCrM1FIzra/2UnSqaS2ipMYW23pbl/ZOQeR0ce8LTxWD7JA9rGsHe8nypUq4Mvm CYEuXpJBaUCTYAh3dn/+mKez30uSAaAKKEoUGi3GNW1FolM7azFUWMiklJvQ+47dhDY0 p5B8NXznrkcf+pBjTlwAq0FDAzjvwXfRAgBtk/I/9uJ3KdkBrsCQDr97W8fC/ozZ72Bj Y+sg== X-Gm-Message-State: AOJu0YyZJiyJStgtdy4dvRnNE6mHKYjsCzFQuWVqYkNY9JcOYkTz2Gvi v/wAHYgVj3lKbpOxWecJy0N35lqzIpSvHsZ5X5auRyqu8CUqBKwsQnupL6jyudzOSMBSHlTW5js z X-Received: by 2002:a05:6a00:8d2:b0:6e9:74d7:7092 with SMTP id s18-20020a056a0008d200b006e974d77092mr16809597pfu.24.1713827229710; Mon, 22 Apr 2024 16:07:09 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:25e4:a74b:cf9:5423]) by smtp.gmail.com with ESMTPSA id x37-20020a056a000be500b006edcceffcb0sm8380667pfu.161.2024.04.22.16.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 16:07:09 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Kevin Buettner , Luis Machado Subject: [PATCH v3 2/2] gdb/testsuite: Add gdb.base/memops-watchpoint.exp Date: Mon, 22 Apr 2024 20:07:00 -0300 Message-ID: <20240422230700.1173173-3-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240422230700.1173173-1-thiago.bauermann@linaro.org> References: <20240422230700.1173173-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 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 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 | 160 +++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 gdb/testsuite/gdb.base/memops-watchpoint.c create mode 100644 gdb/testsuite/gdb.base/memops-watchpoint.exp 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..4005b1eecf85 --- /dev/null +++ b/gdb/testsuite/gdb.base/memops-watchpoint.exp @@ -0,0 +1,160 @@ +# 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 + } + } +} + +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.* \\(\\) at .*:$decimal\r\n" { + set saw_function 1 + exp_continue + } + -re ".*memcpy.* \\(\\) 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 ".*(memmove|memcpy).* \\(\\) at .*:$decimal\r\n" { + set saw_function 1 + exp_continue + } + -re ".*(memmove|memcpy).* \\(\\) 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 + } + } +}