From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4163638323E6 for ; Wed, 5 Jun 2024 13:15:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4163638323E6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4163638323E6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717593333; cv=none; b=PuOcPbWfGiTRvWOeAZWrB41gZLWX3NOm/9PfdvHo6MTrup+YGrCb3YXutdEp7y74337cLsjFfN95T84+wzBg98Fv6Rue2uuLxBfkCltjAcOi1NZrxbUDOfc7fadp3z+kXrQpodv0xgL4mqn3EE4dHZCtXf8EaGnuOEesnBaSs/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717593333; c=relaxed/simple; bh=qNPYDanYlRuyjojbXh/7EzLRDYqpV2+6Py6Mxpe0I3E=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qDwuHGxzDCKo6Yj3LmjjtyEsVYVAMZAyeHFaDGWrSHb+MX4T1B4x86WzUDUyMCib3PZlNrXoHBQ2FnaJRQi/GsufnmL7anmDA2/1e29i3N8es5hFp1bpslaVcsTdjkL4++ocuArTKv8h2CHO8OtOKkwTCY3td8anLU4qz2cQ5Gs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717593329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mynC4wDlyCnBziARMR3popwTkrfz7vIrw4lTdO0A9v0=; b=cinJ1sX9oG8n/5N7tPW0GXBgq6r3OO4Oux4Q5B+ZGD9BvBwbDxbsYIk33/4coQoh3wDC71 Td4AbDuTgwMtD8lCUXhbgQ3zEFHmZIkigOowUZtSsoEIgZNHGngFrF2bjSfssNMNSzeL1C 3ZqfZQYnQsr8L7yRgi1hKct7YV0wvZc= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-7vrbR9rLOWii_QYEL5Ehyw-1; Wed, 05 Jun 2024 09:15:28 -0400 X-MC-Unique: 7vrbR9rLOWii_QYEL5Ehyw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4215a7b73aaso275405e9.3 for ; Wed, 05 Jun 2024 06:15:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717593326; x=1718198126; 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=mynC4wDlyCnBziARMR3popwTkrfz7vIrw4lTdO0A9v0=; b=nXhLDt3lxFYch1uYiFInk8QX15WBPPymrpBEeqUggMDa7zvAh/tcE89cj3S988GrCZ fxC6degt3JrKkg5qMg2IeEzhsSRlXnQxs8196LvdbeTwNtYHSlOPCMeZKMkEjHFeoBqD tABR6wHI8u3AzkdFB3LdSfc4QdXv9CMDovtyjiGZ32a7Ti+IsPEDVwrIhAVQCZdHDKKi oPvP7yQ/VtK41noYAfqP4E+yCS7Rfre6tZb5sOgS5FirZIzePKZUj8YhgVbEmiSiX3gf hUTfYsoZm1OD03htLnx8gNxdzRAOjNepKr2lcVAOW8Ky+gMsCiiF2YaD36GVbxcEwfq+ JCBg== X-Gm-Message-State: AOJu0YzAhafCvFMNPF0ZpW2wp2ZSZkCRxNF3aodKUbqiQd1tNot7DmHw 06UoZ2uCRsPeTDQuiDy6lGnSidnTkceDfvD7F0wZMaOybqtb8uh32rUvI7XKVE/LRp5BaMc3UZg IMwmhpAD8qGUWT7QItNoTNTuimYpMAHd1Q+QU2NKzuJkeKCsijhITpgM/EfL8g5PIaP0RYfzWs1 LWdPD0rZh1nUbGkHzIC9iytQqkmxQuaTdauvm2h9TTLo0= X-Received: by 2002:a05:600c:b85:b0:421:2edb:d207 with SMTP id 5b1f17b1804b1-4215632eb27mr21450485e9.28.1717593325900; Wed, 05 Jun 2024 06:15:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEG9MA0DUh2XHlh7aPjTl/zqAUCAFoQ5kfz9MiyLkJwsS8Fq9856TgD2AMC5bedZeRIMO4ocQ== X-Received: by 2002:a05:600c:b85:b0:421:2edb:d207 with SMTP id 5b1f17b1804b1-4215632eb27mr21450075e9.28.1717593325254; Wed, 05 Jun 2024 06:15:25 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd064b684sm14744563f8f.100.2024.06.05.06.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 06:15:23 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/8] gdb: warn of slow remote file reading only after a successful open Date: Wed, 5 Jun 2024 14:15:10 +0100 Message-Id: <275ae278174f9a93d1c40c1d22fce993abb5cc40.1717592684.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: While working on a later patch in this series, I noticed that GDB would print the message: Reading /path/to/file from remote target... Even when /path/to/file doesn't exist on the remote target. GDB does indeed try to open /path/to/file, but I'm not sure we really need to tell the user unless we actually manage to open the file, and plan to read content from it. If we consider how GDB probes for separate debug files, we can attempt to open multiple possible files, most of them will not exist. When we are native debugging we don't bother telling the user about each file we're checking for, we just announce any file we finally use. I think it makes sense to do a similar thing for remote files. So, in remote_target::remote_hostio_open(), I'd like to move the block of code that prints the above message to after the open call has been made, and we should only print the message if the open succeeds. Now GDB only tells the user about files that we actually open and read from the remote. --- gdb/remote.c | 36 +++--- gdb/testsuite/gdb.server/remote-read-msgs.c | 22 ++++ gdb/testsuite/gdb.server/remote-read-msgs.exp | 119 ++++++++++++++++++ 3 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 gdb/testsuite/gdb.server/remote-read-msgs.c create mode 100644 gdb/testsuite/gdb.server/remote-read-msgs.exp diff --git a/gdb/remote.c b/gdb/remote.c index 241803ab2b3..4742cdf2606 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -12751,7 +12751,24 @@ remote_target::remote_hostio_open (inferior *inf, const char *filename, char *p = rs->buf.data (); int left = get_remote_packet_size () - 1; - if (warn_if_slow) + if (remote_hostio_set_filesystem (inf, remote_errno) != 0) + return -1; + + remote_buffer_add_string (&p, &left, "vFile:open:"); + + remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename, + strlen (filename)); + remote_buffer_add_string (&p, &left, ","); + + remote_buffer_add_int (&p, &left, flags); + remote_buffer_add_string (&p, &left, ","); + + remote_buffer_add_int (&p, &left, mode); + + int res = remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_open, + remote_errno, nullptr, nullptr); + + if (warn_if_slow && res != -1) { static int warning_issued = 0; @@ -12767,22 +12784,7 @@ remote_target::remote_hostio_open (inferior *inf, const char *filename, } } - if (remote_hostio_set_filesystem (inf, remote_errno) != 0) - return -1; - - remote_buffer_add_string (&p, &left, "vFile:open:"); - - remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename, - strlen (filename)); - remote_buffer_add_string (&p, &left, ","); - - remote_buffer_add_int (&p, &left, flags); - remote_buffer_add_string (&p, &left, ","); - - remote_buffer_add_int (&p, &left, mode); - - return remote_hostio_send_command (p - rs->buf.data (), PACKET_vFile_open, - remote_errno, NULL, NULL); + return res; } int diff --git a/gdb/testsuite/gdb.server/remote-read-msgs.c b/gdb/testsuite/gdb.server/remote-read-msgs.c new file mode 100644 index 00000000000..bbcfb01316e --- /dev/null +++ b/gdb/testsuite/gdb.server/remote-read-msgs.c @@ -0,0 +1,22 @@ +/* This testcase 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 . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.server/remote-read-msgs.exp b/gdb/testsuite/gdb.server/remote-read-msgs.exp new file mode 100644 index 00000000000..d2d659aa365 --- /dev/null +++ b/gdb/testsuite/gdb.server/remote-read-msgs.exp @@ -0,0 +1,119 @@ +# This testcase 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 . + +# Setup a number of directories in the debug-file-directory, start gdbserver +# and connect GDB. The debug information is downloaded from the last +# directory in the debug-file-directory. +# +# We are checking that GDB reports 'Reading from remote target' +# only for the paths that are actually being read, and not for paths that +# GDB is simply probing for existence. + +load_lib gdbserver-support.exp + +require allow_gdbserver_tests +require {!is_remote host} + +standard_testfile + +if {[build_executable "failed to prepare" $testfile $srcfile] == -1} { + return -1 +} + +# Split out BINFILE.debug. Remove debug from BINFILE. +if {[gdb_gnu_strip_debug $binfile] != 0} { + return -1 +} + +# Get the '.build-id/xx/xxx...xxx' part of the filename. +set build_id_filename [build_id_debug_filename_get $binfile] + +set hidden_binfile [standard_output_file "hidden_$testfile"] +set hidden_debuginfo [standard_output_file "hidden_$testfile.debug"] + +# Hide (rename) BINFILE and associated debug information, this should ensure +# GDB can't find it directly. +remote_exec build "mv $binfile $hidden_binfile" +remote_exec build "mv ${binfile}.debug $hidden_debuginfo" + +# Helper called from gdb_finish when the 'target' is remote. Ensure the +# debug directory we create is deleted. +proc cleanup_remote_target {} { + remote_exec target "rm -fr debug/" +} + +if { ![is_remote target] } { + set gdbserver_dir [standard_output_file "gdbserver-dir"]/ +} else { + lappend gdb_finish_hooks cleanup_remote_target + set gdbserver_dir "" +} + +# Copy files to the target (if needed). +set target_binfile [gdb_remote_download target $hidden_binfile] +set target_debuginfo [gdb_remote_download target $hidden_debuginfo] + +# Setup the debug information on the target. +remote_exec target \ + "mkdir -p ${gdbserver_dir}debug/[file dirname $build_id_filename]" +remote_exec target \ + "ln -sf $target_debuginfo ${gdbserver_dir}debug/$build_id_filename" + +# Reading debug info from the remote target can take a bit of time, so +# increase the timeout. +with_timeout_factor 5 { + # Restart GDB. + clean_restart + + # Add some dummy entries to the debug-file-directory search list. + gdb_test_no_output "set debug-file-directory xxx:yyy:debug" + + # Set the sysroot. + gdb_test_no_output "set sysroot target:" + + # Make sure we're disconnected, in case we're testing with an + # extended-remote board, therefore already connected. + gdb_test "disconnect" ".*" + + # Start gdbserver. This needs to be done after starting GDB. When + # gdbserver is running local to GDB, start gdbserver in a sub-directory, + # this prevents GDB from finding the debug information itself. + if { ![is_remote target] } { + with_cwd $gdbserver_dir { + set res [gdbserver_start "" $target_binfile] + } + } else { + set res [gdbserver_start "" $target_binfile] + } + set gdbserver_protocol [lindex $res 0] + set gdbserver_gdbport [lindex $res 1] + + # Connect to gdbserver. The output will be placed into the global + # GDB_TARGET_REMOTE_CMD_MSG, and we'll match against this below. + gdb_assert {[gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] == 0} \ + "connect to gdbserver" + + gdb_assert { ![regexp "Reading xxx/\[^\r\n\]+ from remote target\\.\\.\\.\r\n" \ + $gdb_target_remote_cmd_msg] \ + && ![regexp "Reading yyy/\[^\r\n\]+ from remote target\\.\\.\\.\r\n" \ + $gdb_target_remote_cmd_msg] } \ + "check xxx/ and yyy/ are not mentioned" + + gdb_assert { [regexp "Reading debug/[string_to_regexp $build_id_filename] from remote target\\.\\.\\.\r\n" \ + $gdb_target_remote_cmd_msg] } \ + "check debug information is found" +} -- 2.25.4