1 /* Host callback routines for GDB.
2 Copyright 1995 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file provides a standard way for targets to talk to the host OS
25 This interface will probably need a bit more banging to make it
26 smooth. Currently the simulator uses this file to provide the
27 callbacks for itself when it's built standalone, which is rather
30 #ifndef INSIDE_SIMULATOR
36 #ifdef ANSI_PROTOTYPES
49 /* Set the callback copy of errno from what we see now. */
55 p
->last_errno
= errno
;
59 /* Make sure the FD provided is ok. If not, return non-zero
67 if (fd
< 0 || fd
> MAX_CALLBACK_FDS
|| !p
->fdopen
[fd
])
69 p
->last_errno
= EINVAL
;
90 result
= fdbad (p
, fd
);
93 result
= wrap (p
, close (fdmap (p
, fd
)));
101 /* !!! fixme, translate from host to taget errno value */
102 return p
->last_errno
;
113 result
= fdbad (p
, fd
);
116 result
= wrap (p
, isatty (fdmap (fd
)));
121 os_lseek (p
, fd
, off
, way
)
129 result
= fdbad (p
, fd
);
132 result
= lseek (fdmap (p
, fd
), off
, way
);
137 os_open (p
, name
, flags
)
143 for (i
= 0; i
< MAX_CALLBACK_FDS
; i
++)
147 int f
= open (name
, flags
);
150 p
->last_errno
= errno
;
158 p
->last_errno
= EMFILE
;
163 os_read (p
, fd
, buf
, len
)
171 result
= fdbad (p
, fd
);
174 result
= wrap (p
, read (fdmap (p
, fd
), buf
, len
));
179 os_read_stdin (p
, buf
, len
)
184 return wrap (p
, read (0, buf
, len
));
188 os_write (p
, fd
, buf
, len
)
196 result
= fdbad (p
, fd
);
199 result
= wrap (p
, write (fdmap (p
, fd
), buf
, len
));
203 /* ignore the grossness of INSIDE_SIMULATOR, it will go away one day. */
205 os_write_stdout (p
, buf
, len
)
210 #ifdef INSIDE_SIMULATOR
211 return os_write (p
, 1, buf
, len
);
215 for (i
= 0; i
< len
; i
++)
219 if (target_output_hook
)
220 target_output_hook (b
);
222 fputs_filtered (b
, gdb_stdout
);
229 os_rename (p
, f1
, f2
)
234 return wrap (p
, rename (f1
, f2
));
243 return wrap (p
, system (s
));
251 return wrap (p
, time (t
));
260 return wrap (p
, unlink (f1
));
269 for (i
= 0; i
< MAX_CALLBACK_FDS
; i
++)
271 if (p
->fdopen
[i
] && !p
->alwaysopen
[i
]) {
284 for (i
= 0; i
< 3; i
++)
288 p
->alwaysopen
[i
] = 1;
295 This bit is ugly. When the interface has settled down I'll
296 move the whole file into sim/common and remove this bit. */
300 #ifdef ANSI_PROTOTYPES
301 os_printf_filtered (host_callback
*p
, const char *format
, ...)
303 os_printf_filtered (p
, va_alist
)
309 #ifdef ANSI_PROTOTYPES
310 va_start (args
, format
);
315 format
= va_arg (args
, char *);
318 #ifdef INSIDE_SIMULATOR
319 vprintf (format
, args
);
321 vfprintf_filtered (stdout
, format
, args
);
327 host_callback default_callback
=