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 -1
67 if (fd
< 0 || fd
> MAX_CALLBACK_FDS
|| !p
->fdopen
[fd
])
69 p
->last_errno
= EINVAL
;
88 return fdbad (p
, fd
) || wrap (p
, close (fdmap (p
, fd
)));
95 /* !!! fixme, translate from host to taget errno value */
105 return fdbad (p
, fd
) || wrap (p
, isatty (fdmap (fd
)));
109 os_lseek (p
, fd
, off
, way
)
115 return fdbad (p
, fd
) || lseek (fdmap (p
, fd
), off
, way
);
119 os_open (p
, name
, flags
)
125 for (i
= 0; i
< MAX_CALLBACK_FDS
; i
++)
129 int f
= open (name
, flags
);
132 p
->last_errno
= errno
;
140 p
->last_errno
= EMFILE
;
145 os_read (p
, fd
, buf
, len
)
151 return fdbad (p
, fd
) || wrap (p
, read (fdmap (p
, fd
), buf
, len
));
155 os_read_stdin (p
, buf
, len
)
160 return wrap (p
, read (0, buf
, len
));
164 os_write (p
, fd
, buf
, len
)
170 return fdbad (p
, fd
) || wrap (p
, write (fdmap (p
, fd
), buf
, len
));
173 /* ignore the grossness of INSIDE_SIMULATOR, it will go away one day. */
175 os_write_stdout (p
, buf
, len
)
180 #ifdef INSIDE_SIMULATOR
181 return os_write (1, buf
, len
);
185 for (i
= 0; i
< len
; i
++)
189 if (target_output_hook
)
190 target_output_hook (b
);
192 fputs_filtered (b
, gdb_stdout
);
199 os_rename (p
, f1
, f2
)
204 return wrap (p
, rename (f1
, f2
));
213 return wrap (p
, system (s
));
221 return wrap (p
, time (t
));
230 return wrap (p
, unlink (f1
));
239 for (i
= 0; i
< MAX_CALLBACK_FDS
; i
++)
241 if (p
->fdopen
[i
] && !p
->alwaysopen
[i
]) {
254 for (i
= 0; i
< 3; i
++)
258 p
->alwaysopen
[i
] = 1;
265 This bit is ugly. When the interface has settled down I'll
266 move the whole file into sim/common and remove this bit. */
270 #ifdef ANSI_PROTOTYPES
271 os_printf_filtered (host_callback
*p
, const char *format
, ...)
273 os_printf_filtered (p
, va_alist
)
279 #ifdef ANSI_PROTOTYPES
280 va_start (args
, format
);
285 format
= va_arg (args
, char *);
288 #ifdef INSIDE_SIMULATOR
289 vprintf (format
, args
);
291 vfprintf_filtered (stdout
, format
, args
);
297 host_callback default_callback
=