Make the interpreters be per UI
[deliverable/binutils-gdb.git] / gdb / guile / scm-ports.c
1 /* Support for connecting Guile's stdio to GDB's.
2 as well as r/w memory via ports.
3
4 Copyright (C) 2014-2016 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 /* See README file in this directory for implementation notes, coding
22 conventions, et.al. */
23
24 #include "defs.h"
25 #include "gdb_select.h"
26 #include "top.h"
27 #include "target.h"
28 #include "guile-internal.h"
29
30 #ifdef HAVE_POLL
31 #if defined (HAVE_POLL_H)
32 #include <poll.h>
33 #elif defined (HAVE_SYS_POLL_H)
34 #include <sys/poll.h>
35 #endif
36 #endif
37
38 /* A ui-file for sending output to Guile. */
39
40 typedef struct
41 {
42 int *magic;
43 SCM port;
44 } ioscm_file_port;
45
46 /* Data for a memory port. */
47
48 typedef struct
49 {
50 /* Bounds of memory range this port is allowed to access: [start, end).
51 This means that 0xff..ff is not accessible. I can live with that. */
52 CORE_ADDR start, end;
53
54 /* (end - start), recorded for convenience. */
55 ULONGEST size;
56
57 /* Think of this as the lseek value maintained by the kernel.
58 This value is always in the range [0, size]. */
59 ULONGEST current;
60
61 /* The size of the internal r/w buffers.
62 Scheme ports aren't a straightforward mapping to memory r/w.
63 Generally the user specifies how much to r/w and all access is
64 unbuffered. We don't try to provide equivalent access, but we allow
65 the user to specify these values to help get something similar. */
66 unsigned read_buf_size, write_buf_size;
67 } ioscm_memory_port;
68
69 /* Copies of the original system input/output/error ports.
70 These are recorded for debugging purposes. */
71 static SCM orig_input_port_scm;
72 static SCM orig_output_port_scm;
73 static SCM orig_error_port_scm;
74
75 /* This is the stdio port descriptor, scm_ptob_descriptor. */
76 static scm_t_bits stdio_port_desc;
77
78 /* Note: scm_make_port_type takes a char * instead of a const char *. */
79 static /*const*/ char stdio_port_desc_name[] = "gdb:stdio-port";
80
81 /* Names of each gdb port. */
82 static const char input_port_name[] = "gdb:stdin";
83 static const char output_port_name[] = "gdb:stdout";
84 static const char error_port_name[] = "gdb:stderr";
85
86 /* This is the actual port used from Guile.
87 We don't expose these to the user though, to ensure they're not
88 overwritten. */
89 static SCM input_port_scm;
90 static SCM output_port_scm;
91 static SCM error_port_scm;
92
93 /* Magic number to identify port ui-files.
94 Actually, the address of this variable is the magic number. */
95 static int file_port_magic;
96
97 /* Internal enum for specifying output port. */
98 enum oport { GDB_STDOUT, GDB_STDERR };
99
100 /* This is the memory port descriptor, scm_ptob_descriptor. */
101 static scm_t_bits memory_port_desc;
102
103 /* Note: scm_make_port_type takes a char * instead of a const char *. */
104 static /*const*/ char memory_port_desc_name[] = "gdb:memory-port";
105
106 /* The default amount of memory to fetch for each read/write request.
107 Scheme ports don't provide a way to specify the size of a read,
108 which is important to us to minimize the number of inferior interactions,
109 which over a remote link can be important. To compensate we augment the
110 port API with a new function that let's the user specify how much the next
111 read request should fetch. This is the initial value for each new port. */
112 static const unsigned default_read_buf_size = 16;
113 static const unsigned default_write_buf_size = 16;
114
115 /* Arbitrarily limit memory port buffers to 1 byte to 4K. */
116 static const unsigned min_memory_port_buf_size = 1;
117 static const unsigned max_memory_port_buf_size = 4096;
118
119 /* "out of range" error message for buf sizes. */
120 static char *out_of_range_buf_size;
121
122 /* Keywords used by open-memory. */
123 static SCM mode_keyword;
124 static SCM start_keyword;
125 static SCM size_keyword;
126 \f
127 /* Helper to do the low level work of opening a port.
128 Newer versions of Guile (2.1.x) have scm_c_make_port. */
129
130 static SCM
131 ioscm_open_port (scm_t_bits port_type, long mode_bits)
132 {
133 SCM port;
134
135 #if 0 /* TODO: Guile doesn't export this. What to do? */
136 scm_i_scm_pthread_mutex_lock (&scm_i_port_table_mutex);
137 #endif
138
139 port = scm_new_port_table_entry (port_type);
140
141 SCM_SET_CELL_TYPE (port, port_type | mode_bits);
142
143 #if 0 /* TODO: Guile doesn't export this. What to do? */
144 scm_i_pthread_mutex_unlock (&scm_i_port_table_mutex);
145 #endif
146
147 return port;
148 }
149 \f
150 /* Support for connecting Guile's stdio ports to GDB's stdio ports. */
151
152 /* The scm_t_ptob_descriptor.input_waiting "method".
153 Return a lower bound on the number of bytes available for input. */
154
155 static int
156 ioscm_input_waiting (SCM port)
157 {
158 int fdes = 0;
159
160 if (! scm_is_eq (port, input_port_scm))
161 return 0;
162
163 #ifdef HAVE_POLL
164 {
165 /* This is copied from libguile/fports.c. */
166 struct pollfd pollfd = { fdes, POLLIN, 0 };
167 static int use_poll = -1;
168
169 if (use_poll < 0)
170 {
171 /* This is copied from event-loop.c: poll cannot be used for stdin on
172 m68k-motorola-sysv. */
173 struct pollfd test_pollfd = { fdes, POLLIN, 0 };
174
175 if (poll (&test_pollfd, 1, 0) == 1 && (test_pollfd.revents & POLLNVAL))
176 use_poll = 0;
177 else
178 use_poll = 1;
179 }
180
181 if (use_poll)
182 {
183 /* Guile doesn't export SIGINT hooks like Python does.
184 For now pass EINTR to scm_syserror, that's what fports.c does. */
185 if (poll (&pollfd, 1, 0) < 0)
186 scm_syserror (FUNC_NAME);
187
188 return pollfd.revents & POLLIN ? 1 : 0;
189 }
190 }
191 /* Fall through. */
192 #endif
193
194 {
195 struct timeval timeout;
196 fd_set input_fds;
197 int num_fds = fdes + 1;
198 int num_found;
199
200 memset (&timeout, 0, sizeof (timeout));
201 FD_ZERO (&input_fds);
202 FD_SET (fdes, &input_fds);
203
204 num_found = interruptible_select (num_fds,
205 &input_fds, NULL, NULL,
206 &timeout);
207 if (num_found < 0)
208 {
209 /* Guile doesn't export SIGINT hooks like Python does.
210 For now pass EINTR to scm_syserror, that's what fports.c does. */
211 scm_syserror (FUNC_NAME);
212 }
213 return num_found > 0 && FD_ISSET (fdes, &input_fds);
214 }
215 }
216
217 /* The scm_t_ptob_descriptor.fill_input "method". */
218
219 static int
220 ioscm_fill_input (SCM port)
221 {
222 /* Borrowed from libguile/fports.c. */
223 long count;
224 scm_t_port *pt = SCM_PTAB_ENTRY (port);
225
226 /* If we're called on stdout,stderr, punt. */
227 if (! scm_is_eq (port, input_port_scm))
228 return (scm_t_wchar) EOF; /* Set errno and return -1? */
229
230 gdb_flush (gdb_stdout);
231 gdb_flush (gdb_stderr);
232
233 count = ui_file_read (gdb_stdin, (char *) pt->read_buf, pt->read_buf_size);
234 if (count == -1)
235 scm_syserror (FUNC_NAME);
236 if (count == 0)
237 return (scm_t_wchar) EOF;
238
239 pt->read_pos = pt->read_buf;
240 pt->read_end = pt->read_buf + count;
241 return *pt->read_buf;
242 }
243
244 /* Like fputstrn_filtered, but don't escape characters, except nul.
245 Also like fputs_filtered, but a length is specified. */
246
247 static void
248 fputsn_filtered (const char *s, size_t size, struct ui_file *stream)
249 {
250 size_t i;
251
252 for (i = 0; i < size; ++i)
253 {
254 if (s[i] == '\0')
255 fputs_filtered ("\\000", stream);
256 else
257 fputc_filtered (s[i], stream);
258 }
259 }
260
261 /* Write to gdb's stdout or stderr. */
262
263 static void
264 ioscm_write (SCM port, const void *data, size_t size)
265 {
266
267 /* If we're called on stdin, punt. */
268 if (scm_is_eq (port, input_port_scm))
269 return;
270
271 TRY
272 {
273 if (scm_is_eq (port, error_port_scm))
274 fputsn_filtered ((const char *) data, size, gdb_stderr);
275 else
276 fputsn_filtered ((const char *) data, size, gdb_stdout);
277 }
278 CATCH (except, RETURN_MASK_ALL)
279 {
280 GDBSCM_HANDLE_GDB_EXCEPTION (except);
281 }
282 END_CATCH
283 }
284
285 /* Flush gdb's stdout or stderr. */
286
287 static void
288 ioscm_flush (SCM port)
289 {
290 /* If we're called on stdin, punt. */
291 if (scm_is_eq (port, input_port_scm))
292 return;
293
294 if (scm_is_eq (port, error_port_scm))
295 gdb_flush (gdb_stderr);
296 else
297 gdb_flush (gdb_stdout);
298 }
299
300 /* Initialize the gdb stdio port type.
301
302 N.B. isatty? will fail on these ports, it is only supported for file
303 ports. IWBN if we could "subclass" file ports. */
304
305 static void
306 ioscm_init_gdb_stdio_port (void)
307 {
308 stdio_port_desc = scm_make_port_type (stdio_port_desc_name,
309 ioscm_fill_input, ioscm_write);
310
311 scm_set_port_input_waiting (stdio_port_desc, ioscm_input_waiting);
312 scm_set_port_flush (stdio_port_desc, ioscm_flush);
313 }
314
315 /* Subroutine of ioscm_make_gdb_stdio_port to simplify it.
316 Set up the buffers of port PORT.
317 MODE_BITS are the mode bits of PORT. */
318
319 static void
320 ioscm_init_stdio_buffers (SCM port, long mode_bits)
321 {
322 scm_t_port *pt = SCM_PTAB_ENTRY (port);
323 #define GDB_STDIO_BUFFER_DEFAULT_SIZE 1024
324 int size = mode_bits & SCM_BUF0 ? 0 : GDB_STDIO_BUFFER_DEFAULT_SIZE;
325 int writing = (mode_bits & SCM_WRTNG) != 0;
326
327 /* This is heavily copied from scm_fport_buffer_add. */
328
329 if (!writing && size > 0)
330 {
331 pt->read_buf
332 = (unsigned char *) scm_gc_malloc_pointerless (size, "port buffer");
333 pt->read_pos = pt->read_end = pt->read_buf;
334 pt->read_buf_size = size;
335 }
336 else
337 {
338 pt->read_pos = pt->read_buf = pt->read_end = &pt->shortbuf;
339 pt->read_buf_size = 1;
340 }
341
342 if (writing && size > 0)
343 {
344 pt->write_buf
345 = (unsigned char *) scm_gc_malloc_pointerless (size, "port buffer");
346 pt->write_pos = pt->write_buf;
347 pt->write_buf_size = size;
348 }
349 else
350 {
351 pt->write_buf = pt->write_pos = &pt->shortbuf;
352 pt->write_buf_size = 1;
353 }
354 pt->write_end = pt->write_buf + pt->write_buf_size;
355 }
356
357 /* Create a gdb stdio port. */
358
359 static SCM
360 ioscm_make_gdb_stdio_port (int fd)
361 {
362 int is_a_tty = isatty (fd);
363 const char *name;
364 const char *mode_str;
365 long mode_bits;
366 SCM port;
367
368 switch (fd)
369 {
370 case 0:
371 name = input_port_name;
372 mode_str = is_a_tty ? "r0" : "r";
373 break;
374 case 1:
375 name = output_port_name;
376 mode_str = is_a_tty ? "w0" : "w";
377 break;
378 case 2:
379 name = error_port_name;
380 mode_str = is_a_tty ? "w0" : "w";
381 break;
382 default:
383 gdb_assert_not_reached ("bad stdio file descriptor");
384 }
385
386 mode_bits = scm_mode_bits ((char *) mode_str);
387 port = ioscm_open_port (stdio_port_desc, mode_bits);
388
389 scm_set_port_filename_x (port, gdbscm_scm_from_c_string (name));
390
391 ioscm_init_stdio_buffers (port, mode_bits);
392
393 return port;
394 }
395
396 /* (stdio-port? object) -> boolean */
397
398 static SCM
399 gdbscm_stdio_port_p (SCM scm)
400 {
401 /* This is copied from SCM_FPORTP. */
402 return scm_from_bool (!SCM_IMP (scm)
403 && (SCM_TYP16 (scm) == stdio_port_desc));
404 }
405 \f
406 /* GDB's ports are accessed via functions to keep them read-only. */
407
408 /* (input-port) -> port */
409
410 static SCM
411 gdbscm_input_port (void)
412 {
413 return input_port_scm;
414 }
415
416 /* (output-port) -> port */
417
418 static SCM
419 gdbscm_output_port (void)
420 {
421 return output_port_scm;
422 }
423
424 /* (error-port) -> port */
425
426 static SCM
427 gdbscm_error_port (void)
428 {
429 return error_port_scm;
430 }
431 \f
432 /* Support for sending GDB I/O to Guile ports. */
433
434 static void
435 ioscm_file_port_delete (struct ui_file *file)
436 {
437 ioscm_file_port *stream = (ioscm_file_port *) ui_file_data (file);
438
439 if (stream->magic != &file_port_magic)
440 internal_error (__FILE__, __LINE__,
441 _("ioscm_file_port_delete: bad magic number"));
442 xfree (stream);
443 }
444
445 static void
446 ioscm_file_port_rewind (struct ui_file *file)
447 {
448 ioscm_file_port *stream = (ioscm_file_port *) ui_file_data (file);
449
450 if (stream->magic != &file_port_magic)
451 internal_error (__FILE__, __LINE__,
452 _("ioscm_file_port_rewind: bad magic number"));
453
454 scm_truncate_file (stream->port, 0);
455 }
456
457 static void
458 ioscm_file_port_put (struct ui_file *file,
459 ui_file_put_method_ftype *write,
460 void *dest)
461 {
462 ioscm_file_port *stream = (ioscm_file_port *) ui_file_data (file);
463
464 if (stream->magic != &file_port_magic)
465 internal_error (__FILE__, __LINE__,
466 _("ioscm_file_port_put: bad magic number"));
467
468 /* This function doesn't meld with ports very well. */
469 }
470
471 static void
472 ioscm_file_port_write (struct ui_file *file,
473 const char *buffer,
474 long length_buffer)
475 {
476 ioscm_file_port *stream = (ioscm_file_port *) ui_file_data (file);
477
478 if (stream->magic != &file_port_magic)
479 internal_error (__FILE__, __LINE__,
480 _("ioscm_pot_file_write: bad magic number"));
481
482 scm_c_write (stream->port, buffer, length_buffer);
483 }
484
485 /* Return a ui_file that writes to PORT. */
486
487 static struct ui_file *
488 ioscm_file_port_new (SCM port)
489 {
490 ioscm_file_port *stream = XCNEW (ioscm_file_port);
491 struct ui_file *file = ui_file_new ();
492
493 set_ui_file_data (file, stream, ioscm_file_port_delete);
494 set_ui_file_rewind (file, ioscm_file_port_rewind);
495 set_ui_file_put (file, ioscm_file_port_put);
496 set_ui_file_write (file, ioscm_file_port_write);
497 stream->magic = &file_port_magic;
498 stream->port = port;
499
500 return file;
501 }
502 \f
503 /* Helper routine for with-{output,error}-to-port. */
504
505 static SCM
506 ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
507 const char *func_name)
508 {
509 struct ui_file *port_file;
510 struct cleanup *cleanups;
511 SCM result;
512
513 SCM_ASSERT_TYPE (gdbscm_is_true (scm_output_port_p (port)), port,
514 SCM_ARG1, func_name, _("output port"));
515 SCM_ASSERT_TYPE (gdbscm_is_true (scm_thunk_p (thunk)), thunk,
516 SCM_ARG2, func_name, _("thunk"));
517
518 cleanups = set_batch_flag_and_make_cleanup_restore_page_info ();
519
520 make_cleanup_restore_integer (&current_ui->async);
521 current_ui->async = 0;
522
523 port_file = ioscm_file_port_new (port);
524
525 make_cleanup_ui_file_delete (port_file);
526
527 if (oport == GDB_STDERR)
528 {
529 make_cleanup_restore_ui_file (&gdb_stderr);
530 gdb_stderr = port_file;
531 }
532 else
533 {
534 make_cleanup_restore_ui_file (&gdb_stdout);
535
536 if (ui_out_redirect (current_uiout, port_file) < 0)
537 warning (_("Current output protocol does not support redirection"));
538 else
539 make_cleanup_ui_out_redirect_pop (current_uiout);
540
541 gdb_stdout = port_file;
542 }
543
544 result = gdbscm_safe_call_0 (thunk, NULL);
545
546 do_cleanups (cleanups);
547
548 if (gdbscm_is_exception (result))
549 gdbscm_throw (result);
550
551 return result;
552 }
553
554 /* (%with-gdb-output-to-port port thunk) -> object
555 This function is experimental.
556 IWBN to not include "gdb" in the name, but it would collide with a standard
557 procedure, and it's common to import the gdb module without a prefix.
558 There are ways around this, but they're more cumbersome.
559
560 This has % in the name because it's experimental, and we want the
561 user-visible version to come from module (gdb experimental). */
562
563 static SCM
564 gdbscm_percent_with_gdb_output_to_port (SCM port, SCM thunk)
565 {
566 return ioscm_with_output_to_port_worker (port, thunk, GDB_STDOUT, FUNC_NAME);
567 }
568
569 /* (%with-gdb-error-to-port port thunk) -> object
570 This function is experimental.
571 IWBN to not include "gdb" in the name, but it would collide with a standard
572 procedure, and it's common to import the gdb module without a prefix.
573 There are ways around this, but they're more cumbersome.
574
575 This has % in the name because it's experimental, and we want the
576 user-visible version to come from module (gdb experimental). */
577
578 static SCM
579 gdbscm_percent_with_gdb_error_to_port (SCM port, SCM thunk)
580 {
581 return ioscm_with_output_to_port_worker (port, thunk, GDB_STDERR, FUNC_NAME);
582 }
583 \f
584 /* Support for r/w memory via ports. */
585
586 /* Perform an "lseek" to OFFSET,WHENCE on memory port IOMEM.
587 OFFSET must be in the range [0,size].
588 The result is non-zero for success, zero for failure. */
589
590 static int
591 ioscm_lseek_address (ioscm_memory_port *iomem, LONGEST offset, int whence)
592 {
593 CORE_ADDR new_current;
594
595 gdb_assert (iomem->current <= iomem->size);
596
597 switch (whence)
598 {
599 case SEEK_CUR:
600 /* Catch over/underflow. */
601 if ((offset < 0 && iomem->current + offset > iomem->current)
602 || (offset > 0 && iomem->current + offset < iomem->current))
603 return 0;
604 new_current = iomem->current + offset;
605 break;
606 case SEEK_SET:
607 new_current = offset;
608 break;
609 case SEEK_END:
610 if (offset == 0)
611 {
612 new_current = iomem->size;
613 break;
614 }
615 /* TODO: Not supported yet. */
616 return 0;
617 default:
618 return 0;
619 }
620
621 if (new_current > iomem->size)
622 return 0;
623 iomem->current = new_current;
624 return 1;
625 }
626
627 /* "fill_input" method for memory ports. */
628
629 static int
630 gdbscm_memory_port_fill_input (SCM port)
631 {
632 scm_t_port *pt = SCM_PTAB_ENTRY (port);
633 ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
634 size_t to_read;
635
636 /* "current" is the offset of the first byte we want to read. */
637 gdb_assert (iomem->current <= iomem->size);
638 if (iomem->current == iomem->size)
639 return EOF;
640
641 /* Don't read outside the allowed memory range. */
642 to_read = pt->read_buf_size;
643 if (to_read > iomem->size - iomem->current)
644 to_read = iomem->size - iomem->current;
645
646 if (target_read_memory (iomem->start + iomem->current, pt->read_buf,
647 to_read) != 0)
648 gdbscm_memory_error (FUNC_NAME, _("error reading memory"), SCM_EOL);
649
650 iomem->current += to_read;
651 pt->read_pos = pt->read_buf;
652 pt->read_end = pt->read_buf + to_read;
653 return *pt->read_buf;
654 }
655
656 /* "end_input" method for memory ports.
657 Clear the read buffer and adjust the file position for unread bytes. */
658
659 static void
660 gdbscm_memory_port_end_input (SCM port, int offset)
661 {
662 scm_t_port *pt = SCM_PTAB_ENTRY (port);
663 ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
664 size_t remaining = pt->read_end - pt->read_pos;
665
666 /* Note: Use of "int offset" is specified by Guile ports API. */
667 if ((offset < 0 && remaining + offset > remaining)
668 || (offset > 0 && remaining + offset < remaining))
669 {
670 gdbscm_out_of_range_error (FUNC_NAME, 0, scm_from_int (offset),
671 _("overflow in offset calculation"));
672 }
673 offset += remaining;
674
675 if (offset > 0)
676 {
677 pt->read_pos = pt->read_end;
678 /* Throw error if unread-char used at beginning of file
679 then attempting to write. Seems correct. */
680 if (!ioscm_lseek_address (iomem, -offset, SEEK_CUR))
681 {
682 gdbscm_out_of_range_error (FUNC_NAME, 0, scm_from_int (offset),
683 _("bad offset"));
684 }
685 }
686
687 pt->rw_active = SCM_PORT_NEITHER;
688 }
689
690 /* "flush" method for memory ports. */
691
692 static void
693 gdbscm_memory_port_flush (SCM port)
694 {
695 scm_t_port *pt = SCM_PTAB_ENTRY (port);
696 ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
697 size_t to_write = pt->write_pos - pt->write_buf;
698
699 if (to_write == 0)
700 return;
701
702 /* There's no way to indicate a short write, so if the request goes past
703 the end of the port's memory range, flag an error. */
704 if (to_write > iomem->size - iomem->current)
705 {
706 gdbscm_out_of_range_error (FUNC_NAME, 0,
707 gdbscm_scm_from_ulongest (to_write),
708 _("writing beyond end of memory range"));
709 }
710
711 if (target_write_memory (iomem->start + iomem->current, pt->write_buf,
712 to_write) != 0)
713 gdbscm_memory_error (FUNC_NAME, _("error writing memory"), SCM_EOL);
714
715 iomem->current += to_write;
716 pt->write_pos = pt->write_buf;
717 pt->rw_active = SCM_PORT_NEITHER;
718 }
719
720 /* "write" method for memory ports. */
721
722 static void
723 gdbscm_memory_port_write (SCM port, const void *void_data, size_t size)
724 {
725 scm_t_port *pt = SCM_PTAB_ENTRY (port);
726 ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
727 const gdb_byte *data = (const gdb_byte *) void_data;
728
729 /* There's no way to indicate a short write, so if the request goes past
730 the end of the port's memory range, flag an error. */
731 if (size > iomem->size - iomem->current)
732 {
733 gdbscm_out_of_range_error (FUNC_NAME, 0, gdbscm_scm_from_ulongest (size),
734 _("writing beyond end of memory range"));
735 }
736
737 if (pt->write_buf == &pt->shortbuf)
738 {
739 /* Unbuffered port. */
740 if (target_write_memory (iomem->start + iomem->current, data, size) != 0)
741 gdbscm_memory_error (FUNC_NAME, _("error writing memory"), SCM_EOL);
742 iomem->current += size;
743 return;
744 }
745
746 /* Note: The edge case of what to do when the buffer exactly fills is
747 debatable. Guile flushes when the buffer exactly fills up, so we
748 do too. It's counter-intuitive to my mind, but in case there's a
749 subtlety somewhere that depends on this, we do the same. */
750
751 {
752 size_t space = pt->write_end - pt->write_pos;
753
754 if (size < space)
755 {
756 /* Data fits in buffer, and does not fill it. */
757 memcpy (pt->write_pos, data, size);
758 pt->write_pos += size;
759 }
760 else
761 {
762 memcpy (pt->write_pos, data, space);
763 pt->write_pos = pt->write_end;
764 gdbscm_memory_port_flush (port);
765 {
766 const gdb_byte *ptr = data + space;
767 size_t remaining = size - space;
768
769 if (remaining >= pt->write_buf_size)
770 {
771 if (target_write_memory (iomem->start + iomem->current, ptr,
772 remaining) != 0)
773 gdbscm_memory_error (FUNC_NAME, _("error writing memory"),
774 SCM_EOL);
775 iomem->current += remaining;
776 }
777 else
778 {
779 memcpy (pt->write_pos, ptr, remaining);
780 pt->write_pos += remaining;
781 }
782 }
783 }
784 }
785 }
786
787 /* "seek" method for memory ports. */
788
789 static scm_t_off
790 gdbscm_memory_port_seek (SCM port, scm_t_off offset, int whence)
791 {
792 scm_t_port *pt = SCM_PTAB_ENTRY (port);
793 ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
794 CORE_ADDR result;
795 int rc;
796
797 if (pt->rw_active == SCM_PORT_WRITE)
798 {
799 if (offset != 0 || whence != SEEK_CUR)
800 {
801 gdbscm_memory_port_flush (port);
802 rc = ioscm_lseek_address (iomem, offset, whence);
803 result = iomem->current;
804 }
805 else
806 {
807 /* Read current position without disturbing the buffer,
808 but flag an error if what's in the buffer goes outside the
809 allowed range. */
810 CORE_ADDR current = iomem->current;
811 size_t delta = pt->write_pos - pt->write_buf;
812
813 if (current + delta < current
814 || current + delta > iomem->size)
815 rc = 0;
816 else
817 {
818 result = current + delta;
819 rc = 1;
820 }
821 }
822 }
823 else if (pt->rw_active == SCM_PORT_READ)
824 {
825 if (offset != 0 || whence != SEEK_CUR)
826 {
827 scm_end_input (port);
828 rc = ioscm_lseek_address (iomem, offset, whence);
829 result = iomem->current;
830 }
831 else
832 {
833 /* Read current position without disturbing the buffer
834 (particularly the unread-char buffer). */
835 CORE_ADDR current = iomem->current;
836 size_t remaining = pt->read_end - pt->read_pos;
837
838 if (current - remaining > current
839 || current - remaining < iomem->start)
840 rc = 0;
841 else
842 {
843 result = current - remaining;
844 rc = 1;
845 }
846
847 if (rc != 0 && pt->read_buf == pt->putback_buf)
848 {
849 size_t saved_remaining = pt->saved_read_end - pt->saved_read_pos;
850
851 if (result - saved_remaining > result
852 || result - saved_remaining < iomem->start)
853 rc = 0;
854 else
855 result -= saved_remaining;
856 }
857 }
858 }
859 else /* SCM_PORT_NEITHER */
860 {
861 rc = ioscm_lseek_address (iomem, offset, whence);
862 result = iomem->current;
863 }
864
865 if (rc == 0)
866 {
867 gdbscm_out_of_range_error (FUNC_NAME, 0,
868 gdbscm_scm_from_longest (offset),
869 _("bad seek"));
870 }
871
872 /* TODO: The Guile API doesn't support 32x64. We can't fix that here,
873 and there's no need to throw an error if the new address can't be
874 represented in a scm_t_off. But we could return something less
875 clumsy. */
876 return result;
877 }
878
879 /* "close" method for memory ports. */
880
881 static int
882 gdbscm_memory_port_close (SCM port)
883 {
884 scm_t_port *pt = SCM_PTAB_ENTRY (port);
885 ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
886
887 gdbscm_memory_port_flush (port);
888
889 if (pt->read_buf == pt->putback_buf)
890 pt->read_buf = pt->saved_read_buf;
891 if (pt->read_buf != &pt->shortbuf)
892 xfree (pt->read_buf);
893 if (pt->write_buf != &pt->shortbuf)
894 xfree (pt->write_buf);
895 scm_gc_free (iomem, sizeof (*iomem), "memory port");
896
897 return 0;
898 }
899
900 /* "free" method for memory ports. */
901
902 static size_t
903 gdbscm_memory_port_free (SCM port)
904 {
905 gdbscm_memory_port_close (port);
906
907 return 0;
908 }
909
910 /* "print" method for memory ports. */
911
912 static int
913 gdbscm_memory_port_print (SCM exp, SCM port, scm_print_state *pstate)
914 {
915 ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (exp);
916 char *type = SCM_PTOBNAME (SCM_PTOBNUM (exp));
917
918 scm_puts ("#<", port);
919 scm_print_port_mode (exp, port);
920 /* scm_print_port_mode includes a trailing space. */
921 gdbscm_printf (port, "%s %s-%s", type,
922 hex_string (iomem->start), hex_string (iomem->end));
923 scm_putc ('>', port);
924 return 1;
925 }
926
927 /* Create the port type used for memory. */
928
929 static void
930 ioscm_init_memory_port_type (void)
931 {
932 memory_port_desc = scm_make_port_type (memory_port_desc_name,
933 gdbscm_memory_port_fill_input,
934 gdbscm_memory_port_write);
935
936 scm_set_port_end_input (memory_port_desc, gdbscm_memory_port_end_input);
937 scm_set_port_flush (memory_port_desc, gdbscm_memory_port_flush);
938 scm_set_port_seek (memory_port_desc, gdbscm_memory_port_seek);
939 scm_set_port_close (memory_port_desc, gdbscm_memory_port_close);
940 scm_set_port_free (memory_port_desc, gdbscm_memory_port_free);
941 scm_set_port_print (memory_port_desc, gdbscm_memory_port_print);
942 }
943
944 /* Helper for gdbscm_open_memory to parse the mode bits.
945 An exception is thrown if MODE is invalid. */
946
947 static long
948 ioscm_parse_mode_bits (const char *func_name, const char *mode)
949 {
950 const char *p;
951 long mode_bits;
952
953 if (*mode != 'r' && *mode != 'w')
954 {
955 gdbscm_out_of_range_error (func_name, 0,
956 gdbscm_scm_from_c_string (mode),
957 _("bad mode string"));
958 }
959 for (p = mode + 1; *p != '\0'; ++p)
960 {
961 switch (*p)
962 {
963 case '0':
964 case 'b':
965 case '+':
966 break;
967 default:
968 gdbscm_out_of_range_error (func_name, 0,
969 gdbscm_scm_from_c_string (mode),
970 _("bad mode string"));
971 }
972 }
973
974 /* Kinda awkward to convert the mode from SCM -> string only to have Guile
975 convert it back to SCM, but that's the API we have to work with. */
976 mode_bits = scm_mode_bits ((char *) mode);
977
978 return mode_bits;
979 }
980
981 /* Helper for gdbscm_open_memory to finish initializing the port.
982 The port has address range [start,end).
983 This means that address of 0xff..ff is not accessible.
984 I can live with that. */
985
986 static void
987 ioscm_init_memory_port (SCM port, CORE_ADDR start, CORE_ADDR end)
988 {
989 scm_t_port *pt;
990 ioscm_memory_port *iomem;
991 int buffered = (SCM_CELL_WORD_0 (port) & SCM_BUF0) == 0;
992
993 gdb_assert (start <= end);
994
995 iomem = (ioscm_memory_port *) scm_gc_malloc_pointerless (sizeof (*iomem),
996 "memory port");
997
998 iomem->start = start;
999 iomem->end = end;
1000 iomem->size = end - start;
1001 iomem->current = 0;
1002 if (buffered)
1003 {
1004 iomem->read_buf_size = default_read_buf_size;
1005 iomem->write_buf_size = default_write_buf_size;
1006 }
1007 else
1008 {
1009 iomem->read_buf_size = 1;
1010 iomem->write_buf_size = 1;
1011 }
1012
1013 pt = SCM_PTAB_ENTRY (port);
1014 /* Match the expectation of `binary-port?'. */
1015 pt->encoding = NULL;
1016 pt->rw_random = 1;
1017 pt->read_buf_size = iomem->read_buf_size;
1018 pt->write_buf_size = iomem->write_buf_size;
1019 if (buffered)
1020 {
1021 pt->read_buf = (unsigned char *) xmalloc (pt->read_buf_size);
1022 pt->write_buf = (unsigned char *) xmalloc (pt->write_buf_size);
1023 }
1024 else
1025 {
1026 pt->read_buf = &pt->shortbuf;
1027 pt->write_buf = &pt->shortbuf;
1028 }
1029 pt->read_pos = pt->read_end = pt->read_buf;
1030 pt->write_pos = pt->write_buf;
1031 pt->write_end = pt->write_buf + pt->write_buf_size;
1032
1033 SCM_SETSTREAM (port, iomem);
1034 }
1035
1036 /* Re-initialize a memory port, updating its read/write buffer sizes.
1037 An exception is thrown if the port is unbuffered.
1038 TODO: Allow switching buffered/unbuffered.
1039 An exception is also thrown if data is still buffered, except in the case
1040 where the buffer size isn't changing (since that's just a nop). */
1041
1042 static void
1043 ioscm_reinit_memory_port (SCM port, size_t read_buf_size,
1044 size_t write_buf_size, const char *func_name)
1045 {
1046 scm_t_port *pt = SCM_PTAB_ENTRY (port);
1047 ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
1048
1049 gdb_assert (read_buf_size >= min_memory_port_buf_size
1050 && read_buf_size <= max_memory_port_buf_size);
1051 gdb_assert (write_buf_size >= min_memory_port_buf_size
1052 && write_buf_size <= max_memory_port_buf_size);
1053
1054 /* First check if the port is unbuffered. */
1055
1056 if (pt->read_buf == &pt->shortbuf)
1057 {
1058 gdb_assert (pt->write_buf == &pt->shortbuf);
1059 scm_misc_error (func_name, _("port is unbuffered: ~a"),
1060 scm_list_1 (port));
1061 }
1062
1063 /* Next check if anything is buffered. */
1064
1065 if (read_buf_size != pt->read_buf_size
1066 && pt->read_end != pt->read_buf)
1067 {
1068 scm_misc_error (func_name, _("read buffer not empty: ~a"),
1069 scm_list_1 (port));
1070 }
1071
1072 if (write_buf_size != pt->write_buf_size
1073 && pt->write_pos != pt->write_buf)
1074 {
1075 scm_misc_error (func_name, _("write buffer not empty: ~a"),
1076 scm_list_1 (port));
1077 }
1078
1079 /* Now we can update the buffer sizes, but only if the size has changed. */
1080
1081 if (read_buf_size != pt->read_buf_size)
1082 {
1083 iomem->read_buf_size = read_buf_size;
1084 pt->read_buf_size = read_buf_size;
1085 xfree (pt->read_buf);
1086 pt->read_buf = (unsigned char *) xmalloc (pt->read_buf_size);
1087 pt->read_pos = pt->read_end = pt->read_buf;
1088 }
1089
1090 if (write_buf_size != pt->write_buf_size)
1091 {
1092 iomem->write_buf_size = write_buf_size;
1093 pt->write_buf_size = write_buf_size;
1094 xfree (pt->write_buf);
1095 pt->write_buf = (unsigned char *) xmalloc (pt->write_buf_size);
1096 pt->write_pos = pt->write_buf;
1097 pt->write_end = pt->write_buf + pt->write_buf_size;
1098 }
1099 }
1100
1101 /* (open-memory [#:mode string] [#:start address] [#:size integer]) -> port
1102 Return a port that can be used for reading and writing memory.
1103 MODE is a string, and must be one of "r", "w", or "r+".
1104 "0" may be appended to MODE to mark the port as unbuffered.
1105 For compatibility "b" (binary) may also be appended, but we ignore it:
1106 memory ports are binary only.
1107
1108 The chunk of memory that can be accessed can be bounded.
1109 If both START,SIZE are unspecified, all of memory can be accessed
1110 (except 0xff..ff). If only START is specified, all of memory from that
1111 point on can be accessed (except 0xff..ff). If only SIZE if specified,
1112 all memory in [0,SIZE) can be accessed. If both are specified, all memory
1113 in [START,START+SIZE) can be accessed.
1114
1115 Note: If it becomes useful enough we can later add #:end as an alternative
1116 to #:size. For now it is left out.
1117
1118 The result is a Scheme port, and its semantics are a bit odd for accessing
1119 memory (e.g., unget), but we don't try to hide this. It's a port.
1120
1121 N.B. Seeks on the port must be in the range [0,size].
1122 This is for similarity with bytevector ports, and so that one can seek
1123 to the first byte. */
1124
1125 static SCM
1126 gdbscm_open_memory (SCM rest)
1127 {
1128 const SCM keywords[] = {
1129 mode_keyword, start_keyword, size_keyword, SCM_BOOL_F
1130 };
1131 char *mode = NULL;
1132 CORE_ADDR start = 0;
1133 CORE_ADDR end;
1134 int mode_arg_pos = -1, start_arg_pos = -1, size_arg_pos = -1;
1135 ULONGEST size;
1136 SCM port;
1137 long mode_bits;
1138
1139 gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "#sUU", rest,
1140 &mode_arg_pos, &mode,
1141 &start_arg_pos, &start,
1142 &size_arg_pos, &size);
1143
1144 scm_dynwind_begin ((scm_t_dynwind_flags) 0);
1145
1146 if (mode == NULL)
1147 mode = xstrdup ("r");
1148 scm_dynwind_free (mode);
1149
1150 if (size_arg_pos > 0)
1151 {
1152 /* For now be strict about start+size overflowing. If it becomes
1153 a nuisance we can relax things later. */
1154 if (start + size < start)
1155 {
1156 gdbscm_out_of_range_error (FUNC_NAME, 0,
1157 scm_list_2 (gdbscm_scm_from_ulongest (start),
1158 gdbscm_scm_from_ulongest (size)),
1159 _("start+size overflows"));
1160 }
1161 end = start + size;
1162 }
1163 else
1164 end = ~(CORE_ADDR) 0;
1165
1166 mode_bits = ioscm_parse_mode_bits (FUNC_NAME, mode);
1167
1168 port = ioscm_open_port (memory_port_desc, mode_bits);
1169
1170 ioscm_init_memory_port (port, start, end);
1171
1172 scm_dynwind_end ();
1173
1174 /* TODO: Set the file name as "memory-start-end"? */
1175 return port;
1176 }
1177
1178 /* Return non-zero if OBJ is a memory port. */
1179
1180 static int
1181 gdbscm_is_memory_port (SCM obj)
1182 {
1183 return !SCM_IMP (obj) && (SCM_TYP16 (obj) == memory_port_desc);
1184 }
1185
1186 /* (memory-port? obj) -> boolean */
1187
1188 static SCM
1189 gdbscm_memory_port_p (SCM obj)
1190 {
1191 return scm_from_bool (gdbscm_is_memory_port (obj));
1192 }
1193
1194 /* (memory-port-range port) -> (start end) */
1195
1196 static SCM
1197 gdbscm_memory_port_range (SCM port)
1198 {
1199 ioscm_memory_port *iomem;
1200
1201 SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
1202 memory_port_desc_name);
1203
1204 iomem = (ioscm_memory_port *) SCM_STREAM (port);
1205 return scm_list_2 (gdbscm_scm_from_ulongest (iomem->start),
1206 gdbscm_scm_from_ulongest (iomem->end));
1207 }
1208
1209 /* (memory-port-read-buffer-size port) -> integer */
1210
1211 static SCM
1212 gdbscm_memory_port_read_buffer_size (SCM port)
1213 {
1214 ioscm_memory_port *iomem;
1215
1216 SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
1217 memory_port_desc_name);
1218
1219 iomem = (ioscm_memory_port *) SCM_STREAM (port);
1220 return scm_from_uint (iomem->read_buf_size);
1221 }
1222
1223 /* (set-memory-port-read-buffer-size! port size) -> unspecified
1224 An exception is thrown if read data is still buffered or if the port
1225 is unbuffered. */
1226
1227 static SCM
1228 gdbscm_set_memory_port_read_buffer_size_x (SCM port, SCM size)
1229 {
1230 ioscm_memory_port *iomem;
1231
1232 SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
1233 memory_port_desc_name);
1234 SCM_ASSERT_TYPE (scm_is_integer (size), size, SCM_ARG2, FUNC_NAME,
1235 _("integer"));
1236
1237 if (!scm_is_unsigned_integer (size, min_memory_port_buf_size,
1238 max_memory_port_buf_size))
1239 {
1240 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG2, size,
1241 out_of_range_buf_size);
1242 }
1243
1244 iomem = (ioscm_memory_port *) SCM_STREAM (port);
1245 ioscm_reinit_memory_port (port, scm_to_uint (size), iomem->write_buf_size,
1246 FUNC_NAME);
1247
1248 return SCM_UNSPECIFIED;
1249 }
1250
1251 /* (memory-port-write-buffer-size port) -> integer */
1252
1253 static SCM
1254 gdbscm_memory_port_write_buffer_size (SCM port)
1255 {
1256 ioscm_memory_port *iomem;
1257
1258 SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
1259 memory_port_desc_name);
1260
1261 iomem = (ioscm_memory_port *) SCM_STREAM (port);
1262 return scm_from_uint (iomem->write_buf_size);
1263 }
1264
1265 /* (set-memory-port-write-buffer-size! port size) -> unspecified
1266 An exception is thrown if write data is still buffered or if the port
1267 is unbuffered. */
1268
1269 static SCM
1270 gdbscm_set_memory_port_write_buffer_size_x (SCM port, SCM size)
1271 {
1272 ioscm_memory_port *iomem;
1273
1274 SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
1275 memory_port_desc_name);
1276 SCM_ASSERT_TYPE (scm_is_integer (size), size, SCM_ARG2, FUNC_NAME,
1277 _("integer"));
1278
1279 if (!scm_is_unsigned_integer (size, min_memory_port_buf_size,
1280 max_memory_port_buf_size))
1281 {
1282 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG2, size,
1283 out_of_range_buf_size);
1284 }
1285
1286 iomem = (ioscm_memory_port *) SCM_STREAM (port);
1287 ioscm_reinit_memory_port (port, iomem->read_buf_size, scm_to_uint (size),
1288 FUNC_NAME);
1289
1290 return SCM_UNSPECIFIED;
1291 }
1292 \f
1293 /* Initialize gdb ports. */
1294
1295 static const scheme_function port_functions[] =
1296 {
1297 { "input-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_input_port),
1298 "\
1299 Return gdb's input port." },
1300
1301 { "output-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_output_port),
1302 "\
1303 Return gdb's output port." },
1304
1305 { "error-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_error_port),
1306 "\
1307 Return gdb's error port." },
1308
1309 { "stdio-port?", 1, 0, 0, as_a_scm_t_subr (gdbscm_stdio_port_p),
1310 "\
1311 Return #t if the object is a gdb:stdio-port." },
1312
1313 { "open-memory", 0, 0, 1, as_a_scm_t_subr (gdbscm_open_memory),
1314 "\
1315 Return a port that can be used for reading/writing inferior memory.\n\
1316 \n\
1317 Arguments: [#:mode string] [#:start address] [#:size integer]\n\
1318 Returns: A port object." },
1319
1320 { "memory-port?", 1, 0, 0, as_a_scm_t_subr (gdbscm_memory_port_p),
1321 "\
1322 Return #t if the object is a memory port." },
1323
1324 { "memory-port-range", 1, 0, 0, as_a_scm_t_subr (gdbscm_memory_port_range),
1325 "\
1326 Return the memory range of the port as (start end)." },
1327
1328 { "memory-port-read-buffer-size", 1, 0, 0,
1329 as_a_scm_t_subr (gdbscm_memory_port_read_buffer_size),
1330 "\
1331 Return the size of the read buffer for the memory port." },
1332
1333 { "set-memory-port-read-buffer-size!", 2, 0, 0,
1334 as_a_scm_t_subr (gdbscm_set_memory_port_read_buffer_size_x),
1335 "\
1336 Set the size of the read buffer for the memory port.\n\
1337 \n\
1338 Arguments: port integer\n\
1339 Returns: unspecified." },
1340
1341 { "memory-port-write-buffer-size", 1, 0, 0,
1342 as_a_scm_t_subr (gdbscm_memory_port_write_buffer_size),
1343 "\
1344 Return the size of the write buffer for the memory port." },
1345
1346 { "set-memory-port-write-buffer-size!", 2, 0, 0,
1347 as_a_scm_t_subr (gdbscm_set_memory_port_write_buffer_size_x),
1348 "\
1349 Set the size of the write buffer for the memory port.\n\
1350 \n\
1351 Arguments: port integer\n\
1352 Returns: unspecified." },
1353
1354 END_FUNCTIONS
1355 };
1356
1357 static const scheme_function private_port_functions[] =
1358 {
1359 #if 0 /* TODO */
1360 { "%with-gdb-input-from-port", 2, 0, 0,
1361 as_a_scm_t_subr (gdbscm_percent_with_gdb_input_from_port),
1362 "\
1363 Temporarily set GDB's input port to PORT and then invoke THUNK.\n\
1364 \n\
1365 Arguments: port thunk\n\
1366 Returns: The result of calling THUNK.\n\
1367 \n\
1368 This procedure is experimental." },
1369 #endif
1370
1371 { "%with-gdb-output-to-port", 2, 0, 0,
1372 as_a_scm_t_subr (gdbscm_percent_with_gdb_output_to_port),
1373 "\
1374 Temporarily set GDB's output port to PORT and then invoke THUNK.\n\
1375 \n\
1376 Arguments: port thunk\n\
1377 Returns: The result of calling THUNK.\n\
1378 \n\
1379 This procedure is experimental." },
1380
1381 { "%with-gdb-error-to-port", 2, 0, 0,
1382 as_a_scm_t_subr (gdbscm_percent_with_gdb_error_to_port),
1383 "\
1384 Temporarily set GDB's error port to PORT and then invoke THUNK.\n\
1385 \n\
1386 Arguments: port thunk\n\
1387 Returns: The result of calling THUNK.\n\
1388 \n\
1389 This procedure is experimental." },
1390
1391 END_FUNCTIONS
1392 };
1393
1394 void
1395 gdbscm_initialize_ports (void)
1396 {
1397 /* Save the original stdio ports for debugging purposes. */
1398
1399 orig_input_port_scm = scm_current_input_port ();
1400 orig_output_port_scm = scm_current_output_port ();
1401 orig_error_port_scm = scm_current_error_port ();
1402
1403 /* Set up the stdio ports. */
1404
1405 ioscm_init_gdb_stdio_port ();
1406 input_port_scm = ioscm_make_gdb_stdio_port (0);
1407 output_port_scm = ioscm_make_gdb_stdio_port (1);
1408 error_port_scm = ioscm_make_gdb_stdio_port (2);
1409
1410 /* Set up memory ports. */
1411
1412 ioscm_init_memory_port_type ();
1413
1414 /* Install the accessor functions. */
1415
1416 gdbscm_define_functions (port_functions, 1);
1417 gdbscm_define_functions (private_port_functions, 0);
1418
1419 /* Keyword args for open-memory. */
1420
1421 mode_keyword = scm_from_latin1_keyword ("mode");
1422 start_keyword = scm_from_latin1_keyword ("start");
1423 size_keyword = scm_from_latin1_keyword ("size");
1424
1425 /* Error message text for "out of range" memory port buffer sizes. */
1426
1427 out_of_range_buf_size = xstrprintf ("size not between %u - %u",
1428 min_memory_port_buf_size,
1429 max_memory_port_buf_size);
1430 }
This page took 0.059261 seconds and 4 git commands to generate.