1 /* The common simulator framework for GDB, the GNU Debugger.
3 Copyright 2002 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney and Red Hat.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
27 #include "targ-vals.h"
38 /* Define the rate at which the simulator should poll the host
40 #ifndef POLL_QUIT_INTERVAL
41 #define POLL_QUIT_INTERVAL 0x10
44 static int poll_quit_count
= POLL_QUIT_INTERVAL
;
46 /* See the file include/callbacks.h for a description */
50 sim_io_init(SIM_DESC sd
)
52 return STATE_CALLBACK (sd
)->init (STATE_CALLBACK (sd
));
57 sim_io_shutdown(SIM_DESC sd
)
59 return STATE_CALLBACK (sd
)->shutdown (STATE_CALLBACK (sd
));
64 sim_io_unlink(SIM_DESC sd
,
67 return STATE_CALLBACK (sd
)->unlink (STATE_CALLBACK (sd
), f1
);
72 sim_io_time(SIM_DESC sd
,
75 return STATE_CALLBACK (sd
)->time (STATE_CALLBACK (sd
), t
);
80 sim_io_system(SIM_DESC sd
, const char *s
)
82 return STATE_CALLBACK (sd
)->system (STATE_CALLBACK (sd
), s
);
87 sim_io_rename(SIM_DESC sd
,
91 return STATE_CALLBACK (sd
)->rename (STATE_CALLBACK (sd
), f1
, f2
);
96 sim_io_write_stdout(SIM_DESC sd
,
100 switch (CURRENT_STDIO
) {
102 return STATE_CALLBACK (sd
)->write_stdout (STATE_CALLBACK (sd
), buf
, len
);
105 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), 1, buf
, len
);
108 sim_io_error (sd
, "sim_io_write_stdout: unaccounted switch\n");
116 sim_io_flush_stdout(SIM_DESC sd
)
118 switch (CURRENT_STDIO
) {
120 STATE_CALLBACK (sd
)->flush_stdout (STATE_CALLBACK (sd
));
125 sim_io_error (sd
, "sim_io_flush_stdout: unaccounted switch\n");
132 sim_io_write_stderr(SIM_DESC sd
,
136 switch (CURRENT_STDIO
) {
138 return STATE_CALLBACK (sd
)->write_stderr (STATE_CALLBACK (sd
), buf
, len
);
141 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), 2, buf
, len
);
144 sim_io_error (sd
, "sim_io_write_stderr: unaccounted switch\n");
152 sim_io_flush_stderr(SIM_DESC sd
)
154 switch (CURRENT_STDIO
) {
156 STATE_CALLBACK (sd
)->flush_stderr (STATE_CALLBACK (sd
));
161 sim_io_error (sd
, "sim_io_flush_stderr: unaccounted switch\n");
168 sim_io_write(SIM_DESC sd
,
173 return STATE_CALLBACK (sd
)->write (STATE_CALLBACK (sd
), fd
, buf
, len
);
178 sim_io_read_stdin(SIM_DESC sd
,
182 switch (CURRENT_STDIO
) {
184 return STATE_CALLBACK (sd
)->read_stdin (STATE_CALLBACK (sd
), buf
, len
);
187 return STATE_CALLBACK (sd
)->read (STATE_CALLBACK (sd
), 0, buf
, len
);
190 sim_io_error (sd
, "sim_io_read_stdin: unaccounted switch\n");
198 sim_io_read(SIM_DESC sd
, int fd
,
202 return STATE_CALLBACK (sd
)->read (STATE_CALLBACK (sd
), fd
, buf
, len
);
207 sim_io_open(SIM_DESC sd
,
211 return STATE_CALLBACK (sd
)->open (STATE_CALLBACK (sd
), name
, flags
);
216 sim_io_lseek(SIM_DESC sd
,
221 return STATE_CALLBACK (sd
)->lseek (STATE_CALLBACK (sd
), fd
, off
, way
);
226 sim_io_isatty(SIM_DESC sd
,
229 return STATE_CALLBACK (sd
)->isatty (STATE_CALLBACK (sd
), fd
);
234 sim_io_get_errno(SIM_DESC sd
)
236 return STATE_CALLBACK (sd
)->get_errno (STATE_CALLBACK (sd
));
241 sim_io_close(SIM_DESC sd
,
244 return STATE_CALLBACK (sd
)->close (STATE_CALLBACK (sd
), fd
);
249 sim_io_printf(SIM_DESC sd
,
255 STATE_CALLBACK (sd
)->vprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
261 sim_io_vprintf(SIM_DESC sd
,
265 STATE_CALLBACK (sd
)->vprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
270 sim_io_eprintf(SIM_DESC sd
,
276 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
282 sim_io_evprintf(SIM_DESC sd
,
286 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
291 sim_io_error(SIM_DESC sd
,
295 if (sd
== NULL
|| STATE_CALLBACK (sd
) == NULL
) {
298 vfprintf (stderr
, fmt
, ap
);
300 fprintf (stderr
, "\n");
306 STATE_CALLBACK (sd
)->evprintf_filtered (STATE_CALLBACK (sd
), fmt
, ap
);
308 STATE_CALLBACK (sd
)->error (STATE_CALLBACK (sd
), "");
314 sim_io_poll_quit(SIM_DESC sd
)
316 if (STATE_CALLBACK (sd
)->poll_quit
!= NULL
&& poll_quit_count
-- < 0)
318 poll_quit_count
= POLL_QUIT_INTERVAL
;
319 if (STATE_CALLBACK (sd
)->poll_quit (STATE_CALLBACK (sd
)))
325 /* Based on gdb-4.17/sim/ppc/main.c:sim_io_read_stdin().
327 FIXME: Should not be calling fcntl() or grubbing around inside of
330 FIXME: Some completly new mechanism for handling the general
331 problem of asynchronous IO is needed.
333 FIXME: This function does not supress the echoing (ECHO) of input.
334 Consequently polled input is always displayed.
336 FIXME: This function does not perform uncooked reads.
337 Consequently, data will not be read until an EOLN character has
338 been entered. A cntrl-d may force the early termination of a line */
342 sim_io_poll_read (SIM_DESC sd
,
347 #if defined(O_NDELAY) && defined(F_GETFL) && defined(F_SETFL)
348 int fd
= STATE_CALLBACK (sd
)->fdmap
[sim_io_fd
];
353 STATE_CALLBACK (sd
)->last_errno
= 0;
354 /* get the old status */
355 flags
= fcntl (fd
, F_GETFL
, 0);
358 perror ("sim_io_poll_read");
361 /* temp, disable blocking IO */
362 status
= fcntl (fd
, F_SETFL
, flags
| O_NDELAY
);
365 perror ("sim_io_read_stdin");
369 nr_read
= read (fd
, buf
, sizeof_buf
);
372 /* printf ("<nr-read=%d>\n", nr_read); */
378 STATE_CALLBACK (sd
)->last_errno
= errno
;
380 /* return to regular vewing */
381 status
= fcntl (fd
, F_SETFL
, flags
);
384 perror ("sim_io_read_stdin");
389 return sim_io_read (sd
, sim_io_fd
, buf
, sizeof_buf
);
This page took 0.036445 seconds and 4 git commands to generate.