gdb: warn of slow remote file reading only after a successful open

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.

Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Andrew Burgess
2024-05-21 15:38:23 +01:00
parent c7e38ee47c
commit 1d6f5804da
3 changed files with 160 additions and 17 deletions

View File

@@ -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