From 1c4b552ba553c4dbbb066c9ef8667209553444ca Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Wed, 25 Mar 2015 11:26:43 +0000 Subject: Associate target_ops with target_fileio file descriptors Various target_fileio_* functions use integer file descriptors to refer to open files. File operation functions are looked up from the target stack as they are used, which causes problems if the target stack changes after the file is opened. For example, if a file is opened on a remote target and the remote target disconnects or closes the remote target will be popped off the stack. If target_fileio_close is then called on that file and "set auto-connect-native-target" is "on" (the default) then the native target's close method will be called. If the file opened on the remote happens to share the same number with a file open in GDB then that file will be closed by mistake. This commit changes target_fileio_open to store newly opened file descriptors in a table together with the target_ops used to open them. The index into the table is returned and used as the file descriptor argument to all target_fileio_* functions that accept file descriptor arguments. gdb/ChangeLog: * target.c (fileio_ft_t): New typedef, define object vector. (fileio_fhandles): New static variable. (is_closed_fileio_fh): New macro. (lowest_closed_fd): New static variable. (acquire_fileio_fd): New function. (release_fileio_fd): Likewise. (fileio_fd_to_fh): New macro. (target_fileio_open): Wrap the file descriptor on success. (target_fileio_pwrite): Updated to use wrapped file descriptor. (target_fileio_pread): Likewise. (target_fileio_close): Likewise. --- gdb/ChangeLog | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'gdb/ChangeLog') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a5abe28..591a114 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2015-03-25 Gary Benson + Pedro Alves + + * target.c (fileio_ft_t): New typedef, define object vector. + (fileio_fhandles): New static variable. + (is_closed_fileio_fh): New macro. + (lowest_closed_fd): New static variable. + (acquire_fileio_fd): New function. + (release_fileio_fd): Likewise. + (fileio_fd_to_fh): New macro. + (target_fileio_open): Wrap the file descriptor on success. + (target_fileio_pwrite): Updated to use wrapped file descriptor. + (target_fileio_pread): Likewise. + (target_fileio_close): Likewise. + 2015-03-24 Pedro Alves * thread.c (thread_apply_all_command): Take exited threads into -- cgit v1.1