diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-26 21:39:46 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-08-03 07:58:52 -0600 |
commit | d419f42dd3f3635fc036413258ed530676998191 (patch) | |
tree | 63b46767bc2a7a0211eb9923b6e07a9fc95c7594 /gdb/remote.c | |
parent | 4a2b031d5452226cf7894f313b3aac603f7ec5fb (diff) | |
download | gdb-d419f42dd3f3635fc036413258ed530676998191.zip gdb-d419f42dd3f3635fc036413258ed530676998191.tar.gz gdb-d419f42dd3f3635fc036413258ed530676998191.tar.bz2 |
Introduce and use gdb_file_up
This introduces gdb_file_up, a unique pointer holding a FILE*, and
then changes some code in gdb to use it. In particular
gdb_fopen_cloexec now returns a gdb_file_up. This allow removing some
cleanups.
ChangeLog
2017-08-03 Tom Tromey <tom@tromey.com>
* xml-support.c (xml_fetch_content_from_file): Update.
* ui-file.c (stdio_file::open): Update.
* tracefile-tfile.c (tfile_start): Update.
* remote.c (remote_file_put, remote_file_get): Update.
* nat/linux-procfs.c (linux_proc_get_int)
(linux_proc_pid_get_state, linux_proc_tid_get_name): Update.
* nat/linux-osdata.c (linux_common_core_of_thread): Update.
(command_from_pid, commandline_from_pid, linux_xfer_osdata_cpus)
(print_sockets, linux_xfer_osdata_shm, linux_xfer_osdata_sem)
(linux_xfer_osdata_msg, linux_xfer_osdata_modules): Update.
* nat/linux-btrace.c (linux_determine_kernel_start): Update.
* linux-nat.c (linux_proc_pending_signals): Update.
* dwarf2read.c (write_psymtabs_to_index): Use gdb_file_up.
(file_closer): Remove.
* compile/compile.c (compile_to_object): Update.
* common/filestuff.h (struct gdb_file_deleter): New.
(gdb_file_up): New typedef.
(gdb_fopen_cloexec): Change return type.
* common/filestuff.c (gdb_fopen_cloexec): Return gdb_file_up.
* cli/cli-dump.c (fopen_with_cleanup): Remove.
(dump_binary_file, restore_binary_file): Update.
* auto-load.c (auto_load_objfile_script_1): Update.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r-- | gdb/remote.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/gdb/remote.c b/gdb/remote.c index d363a36..c381743 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -11902,7 +11902,6 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty) { struct cleanup *back_to, *close_cleanup; int retcode, fd, remote_errno, bytes, io_size; - FILE *file; gdb_byte *buffer; int bytes_in_buffer; int saw_eof; @@ -11912,10 +11911,9 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty) if (!rs->remote_desc) error (_("command can only be used with remote target")); - file = gdb_fopen_cloexec (local_file, "rb"); + gdb_file_up file = gdb_fopen_cloexec (local_file, "rb"); if (file == NULL) perror_with_name (local_file); - back_to = make_cleanup_fclose (file); fd = remote_hostio_open (find_target_at (process_stratum), NULL, remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT @@ -11928,7 +11926,7 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty) remote packet limit, so we'll transfer slightly fewer. */ io_size = get_remote_packet_size (); buffer = (gdb_byte *) xmalloc (io_size); - make_cleanup (xfree, buffer); + back_to = make_cleanup (xfree, buffer); close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd); @@ -11941,10 +11939,10 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty) { bytes = fread (buffer + bytes_in_buffer, 1, io_size - bytes_in_buffer, - file); + file.get ()); if (bytes == 0) { - if (ferror (file)) + if (ferror (file.get ())) error (_("Error reading %s."), local_file); else { @@ -11995,7 +11993,6 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty) { struct cleanup *back_to, *close_cleanup; int fd, remote_errno, bytes, io_size; - FILE *file; gdb_byte *buffer; ULONGEST offset; struct remote_state *rs = get_remote_state (); @@ -12009,16 +12006,15 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty) if (fd == -1) remote_hostio_error (remote_errno); - file = gdb_fopen_cloexec (local_file, "wb"); + gdb_file_up file = gdb_fopen_cloexec (local_file, "wb"); if (file == NULL) perror_with_name (local_file); - back_to = make_cleanup_fclose (file); /* Send up to this many bytes at once. They won't all fit in the remote packet limit, so we'll transfer slightly fewer. */ io_size = get_remote_packet_size (); buffer = (gdb_byte *) xmalloc (io_size); - make_cleanup (xfree, buffer); + back_to = make_cleanup (xfree, buffer); close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd); @@ -12035,7 +12031,7 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty) offset += bytes; - bytes = fwrite (buffer, 1, bytes, file); + bytes = fwrite (buffer, 1, bytes, file.get ()); if (bytes == 0) perror_with_name (local_file); } |