1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
|
2018-01-21 Doug Evans <dje@google.com>
PR guile/21104
* configure.ac: Add guile-2.2 back.
* configure: Regenerate.
* guile/scm-ports.c (PORTS_V22): New macro.
(ioscm_memory_port) [!PORTS_V22]: Make read_buf_size,write_buf_size
!PORTS_V22 only.
(port_type_t): New type.
(stdio_port_type): Renamed from stdio_port_desc.
(stdio_port_type_name): Renamed from stdio_port_desc_name.
(memory_port_type): Renamed from memory_port_desc.
(memmory_port_type_name): Renamed from memory_port_desc_name.
(natural_buf_size) [PORTS_V22]: New variable.
(ioscm_open_port): New argument stream. All callers updated.
(ioscm_read, ioscm_write) [PORTS_V22]: New functions.
(ioscm_init_gdb_stdio_port) [PORTS_V22]: Adapt for use in Guile >= 2.2.
(gdbscm_is_stdio_port): New function.
(gdbscm_stdio_port_p): Call it.
(gdbscm_get_natural_buffer_sizes, gdbscm_memory_port_seek)
(gdbscm_memory_port_read, gdbscm_memory_port_write) [PORTS_V22]: New
functions.
(gdbscm_memory_port_print): Adapt for use in Guile >= 2.2.
(ioscm_init_memory_port_type): Ditto.
(ioscm_init_memory_stream): Replaces ioscm_init_memory_port.
(ioscm_init_memory_port_buffers): New function.
(gdbscm_open_memory): Update.
(gdbscm_is_memory_port): Adapt for use in Guile >= 2.2.
(port_functions) [!PORTS_V22]: Only define Guile functions
memory-port-read-buffer-size, set-memory-port-read-buffer-size!,
memory-port-write-buffer-size, set-memory-port-write-buffer-size!
for Guile < 2.2.
(gdbscm_initialize_ports): Only initialize out_of_range_buf_size if
!PORTS_V22.
--- gdb/configure.orig 2019-06-26 13:50:46 UTC
+++ gdb/configure
@@ -10985,7 +10985,7 @@ fi
-try_guile_versions="guile-2.0"
+try_guile_versions="guile-2.0 guile-2.2"
have_libguile=no
case "${with_guile}" in
no)
--- gdb/guile/scm-ports.c.orig 2019-05-11 18:19:03 UTC
+++ gdb/guile/scm-ports.c
@@ -36,6 +36,13 @@
#endif
#endif
+/* Guile ports radically changed in Guile 2.2.
+ Note: We don't support Guile < 2.0.
+ TODO(dje): Suggest deprecating and then removing Guile 2.0 support
+ at some point in the future. */
+#define PORTS_V22 (SCM_MAJOR_VERSION > 2 \
+ || SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2)
+
/* A ui-file for sending output to Guile. */
class ioscm_file_port : public ui_file
@@ -66,12 +73,14 @@ typedef struct
This value is always in the range [0, size]. */
ULONGEST current;
+#if !PORTS_V22
/* The size of the internal r/w buffers.
Scheme ports aren't a straightforward mapping to memory r/w.
Generally the user specifies how much to r/w and all access is
unbuffered. We don't try to provide equivalent access, but we allow
the user to specify these values to help get something similar. */
unsigned read_buf_size, write_buf_size;
+#endif
} ioscm_memory_port;
/* Copies of the original system input/output/error ports.
@@ -80,11 +89,17 @@ static SCM orig_input_port_scm;
static SCM orig_output_port_scm;
static SCM orig_error_port_scm;
-/* This is the stdio port descriptor, scm_ptob_descriptor. */
-static scm_t_bits stdio_port_desc;
+#if PORTS_V22
+typedef scm_t_port_type *port_type_t;
+#else
+typedef scm_t_bits port_type_t;
+#endif
+/* This is the stdio port type. */
+static port_type_t stdio_port_type;
+
/* Note: scm_make_port_type takes a char * instead of a const char *. */
-static /*const*/ char stdio_port_desc_name[] = "gdb:stdio-port";
+static /*const*/ char stdio_port_type_name[] = "gdb:stdio-port";
/* Names of each gdb port. */
static const char input_port_name[] = "gdb:stdin";
@@ -101,12 +116,19 @@ static SCM error_port_scm;
/* Internal enum for specifying output port. */
enum oport { GDB_STDOUT, GDB_STDERR };
-/* This is the memory port descriptor, scm_ptob_descriptor. */
-static scm_t_bits memory_port_desc;
+/* This is the memory port type. */
+static port_type_t memory_port_type;
/* Note: scm_make_port_type takes a char * instead of a const char *. */
-static /*const*/ char memory_port_desc_name[] = "gdb:memory-port";
+static /*const*/ char memory_port_type_name[] = "gdb:memory-port";
+#if PORTS_V22
+
+/* The maximum values to use for get_natural_buffer_sizes. */
+static const unsigned natural_buf_size = 16;
+
+#else
+
/* The default amount of memory to fetch for each read/write request.
Scheme ports don't provide a way to specify the size of a read,
which is important to us to minimize the number of inferior interactions,
@@ -120,6 +142,8 @@ static const unsigned default_write_buf_size = 16;
static const unsigned min_memory_port_buf_size = 1;
static const unsigned max_memory_port_buf_size = 4096;
+#endif
+
/* "out of range" error message for buf sizes. */
static char *out_of_range_buf_size;
@@ -132,7 +156,7 @@ static SCM size_keyword;
Newer versions of Guile (2.1.x) have scm_c_make_port. */
static SCM
-ioscm_open_port (scm_t_bits port_type, long mode_bits)
+ioscm_open_port (port_type_t port_type, long mode_bits, scm_t_bits stream)
{
SCM port;
@@ -140,9 +164,12 @@ ioscm_open_port (scm_t_bits port_type, long mode_bits)
scm_i_scm_pthread_mutex_lock (&scm_i_port_table_mutex);
#endif
+#if PORTS_V22
+ port = scm_c_make_port (port_type, mode_bits, stream);
+#else
port = scm_new_port_table_entry (port_type);
-
SCM_SET_CELL_TYPE (port, port_type | mode_bits);
+#endif
#if 0 /* TODO: Guile doesn't export this. What to do? */
scm_i_pthread_mutex_unlock (&scm_i_port_table_mutex);
@@ -150,6 +177,23 @@ ioscm_open_port (scm_t_bits port_type, long mode_bits)
return port;
}
+
+/* Like fputstrn_filtered, but don't escape characters, except nul.
+ Also like fputs_filtered, but a length is specified. */
+
+static void
+fputsn_filtered (const char *s, size_t size, struct ui_file *stream)
+{
+ size_t i;
+
+ for (i = 0; i < size; ++i)
+ {
+ if (s[i] == '\0')
+ fputs_filtered ("\\000", stream);
+ else
+ fputc_filtered (s[i], stream);
+ }
+}
/* Support for connecting Guile's stdio ports to GDB's stdio ports. */
@@ -218,6 +262,72 @@ ioscm_input_waiting (SCM port)
}
}
+#if PORTS_V22
+
+static size_t
+ioscm_read (SCM port, SCM dst, size_t start, size_t count)
+{
+ /* Borrowed from libguile/fports.c. */
+ auto ptr = reinterpret_cast<char*>(SCM_BYTEVECTOR_CONTENTS (dst) + start);
+ ssize_t ret;
+
+ /* If we're called on stdout,stderr, punt. */
+ if (! scm_is_eq (port, input_port_scm))
+ return 0; /* EOF */
+
+ gdb_flush (gdb_stdout);
+ gdb_flush (gdb_stderr);
+
+ retry:
+ ret = ui_file_read (gdb_stdin, ptr, count);
+ if (ret < 0)
+ {
+ if (errno == EINTR)
+ {
+ scm_async_tick ();
+ goto retry;
+ }
+ if (errno == EWOULDBLOCK || errno == EAGAIN)
+ {
+ /* See the discussion of non-blocking I/O in the Guile manual. */
+ return -1;
+ }
+ scm_syserror ("ioscm_read");
+ }
+ return ret;
+}
+
+static size_t
+ioscm_write (SCM port, SCM src, size_t start, size_t count)
+{
+ /* Borrowed from libguile/fports.c. */
+ auto ptr = reinterpret_cast<char*>(SCM_BYTEVECTOR_CONTENTS (src) + start);
+ ssize_t ret;
+
+ /* If we're called on stdin, punt. */
+ if (scm_is_eq (port, input_port_scm))
+ {
+ errno = EIO;
+ scm_syserror("ioscm_write");
+ }
+
+ try
+ {
+ if (scm_is_eq (port, error_port_scm))
+ fputsn_filtered (ptr, count, gdb_stderr);
+ else
+ fputsn_filtered (ptr, count, gdb_stdout);
+ }
+ catch (gdbscm_gdb_exception &except)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+
+ return count;
+}
+
+#else /* !PORTS_V22 */
+
/* The scm_t_ptob_descriptor.fill_input "method". */
static int
@@ -245,23 +356,6 @@ ioscm_fill_input (SCM port)
return *pt->read_buf;
}
-/* Like fputstrn_filtered, but don't escape characters, except nul.
- Also like fputs_filtered, but a length is specified. */
-
-static void
-fputsn_filtered (const char *s, size_t size, struct ui_file *stream)
-{
- size_t i;
-
- for (i = 0; i < size; ++i)
- {
- if (s[i] == '\0')
- fputs_filtered ("\\000", stream);
- else
- fputc_filtered (s[i], stream);
- }
-}
-
/* Write to gdb's stdout or stderr. */
static void
@@ -301,6 +395,8 @@ ioscm_flush (SCM port)
gdb_flush (gdb_stdout);
}
+#endif
+
/* Initialize the gdb stdio port type.
N.B. isatty? will fail on these ports, it is only supported for file
@@ -309,13 +405,23 @@ ioscm_flush (SCM port)
static void
ioscm_init_gdb_stdio_port (void)
{
- stdio_port_desc = scm_make_port_type (stdio_port_desc_name,
- ioscm_fill_input, ioscm_write);
+ stdio_port_type = scm_make_port_type (stdio_port_type_name,
+#if PORTS_V22
+ ioscm_read,
+#else
+ ioscm_fill_input,
+#endif
+ ioscm_write);
- scm_set_port_input_waiting (stdio_port_desc, ioscm_input_waiting);
- scm_set_port_flush (stdio_port_desc, ioscm_flush);
+ scm_set_port_input_waiting (stdio_port_type, ioscm_input_waiting);
+
+#if !PORTS_V22
+ scm_set_port_flush (stdio_port_type, ioscm_flush);
+#endif
}
+#if !PORTS_V22
+
/* Subroutine of ioscm_make_gdb_stdio_port to simplify it.
Set up the buffers of port PORT.
MODE_BITS are the mode bits of PORT. */
@@ -358,6 +464,8 @@ ioscm_init_stdio_buffers (SCM port, long mode_bits)
pt->write_end = pt->write_buf + pt->write_buf_size;
}
+#endif
+
/* Create a gdb stdio port. */
static SCM
@@ -388,23 +496,36 @@ ioscm_make_gdb_stdio_port (int fd)
}
mode_bits = scm_mode_bits ((char *) mode_str);
- port = ioscm_open_port (stdio_port_desc, mode_bits);
+ port = ioscm_open_port (stdio_port_type, mode_bits, 0);
scm_set_port_filename_x (port, gdbscm_scm_from_c_string (name));
+#if !PORTS_V22
ioscm_init_stdio_buffers (port, mode_bits);
+#endif
return port;
}
+/* Return non-zero if OBJ is a stdio port. */
+
+static int
+gdbscm_is_stdio_port (SCM obj)
+{
+ /* This is copied from SCM_FPORTP. */
+#if PORTS_V22
+ return SCM_PORTP (obj) && SCM_PORT_TYPE (obj) == stdio_port_type;
+#else
+ return !SCM_IMP (obj) && SCM_TYP16 (obj) == stdio_port_type;
+#endif
+}
+
/* (stdio-port? object) -> boolean */
static SCM
-gdbscm_stdio_port_p (SCM scm)
+gdbscm_stdio_port_p (SCM obj)
{
- /* This is copied from SCM_FPORTP. */
- return scm_from_bool (!SCM_IMP (scm)
- && (SCM_TYP16 (scm) == stdio_port_desc));
+ return scm_from_bool (gdbscm_is_stdio_port (obj));
}
/* GDB's ports are accessed via functions to keep them read-only. */
@@ -567,6 +688,94 @@ ioscm_lseek_address (ioscm_memory_port *iomem, LONGEST
return 1;
}
+#if PORTS_V22
+
+/* The semantics get weird if the buffer size is larger than the port range,
+ so provide a better default buffer size. */
+
+static void
+gdbscm_get_natural_buffer_sizes (SCM port, size_t *read_size,
+ size_t *write_size)
+{
+ ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
+
+ size_t size = natural_buf_size;
+ if (iomem->size < size)
+ size = iomem->size;
+ *read_size = *write_size = size;
+}
+
+static scm_t_off
+gdbscm_memory_port_seek (SCM port, scm_t_off offset, int whence)
+{
+ ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
+ scm_t_off result;
+ int rc;
+
+ if (ioscm_lseek_address (iomem, offset, whence) == 0)
+ {
+ gdbscm_out_of_range_error (FUNC_NAME, 0,
+ gdbscm_scm_from_longest (offset),
+ _("bad seek"));
+ }
+
+ return iomem->current;
+}
+
+static size_t
+gdbscm_memory_port_read (SCM port, SCM dst, size_t start, size_t count)
+{
+ /* Borrowed from libguile/fports.c. */
+ auto ptr = reinterpret_cast<gdb_byte*>(SCM_BYTEVECTOR_CONTENTS (dst) + start);
+ ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
+ size_t to_read;
+
+ /* "current" is the offset of the first byte we want to read. */
+ gdb_assert (iomem->current <= iomem->size);
+ if (iomem->current == iomem->size)
+ return 0; /* EOF */
+
+ /* Don't read outside the allowed memory range. */
+ to_read = count;
+ if (to_read > iomem->size - iomem->current)
+ to_read = iomem->size - iomem->current;
+
+ if (target_read_memory (iomem->start + iomem->current, ptr, to_read) != 0)
+ gdbscm_memory_error (FUNC_NAME, _("error reading memory"), SCM_EOL);
+
+ iomem->current += to_read;
+ return to_read;
+}
+
+static size_t
+gdbscm_memory_port_write (SCM port, SCM src, size_t start, size_t count)
+{
+ /* Borrowed from libguile/fports.c. */
+ auto ptr = reinterpret_cast<const gdb_byte*>(SCM_BYTEVECTOR_CONTENTS (src) +
+ start);
+ ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
+ ssize_t ret;
+
+ /* "current" is the offset of the first byte we want to read. */
+ gdb_assert (iomem->current <= iomem->size);
+
+ /* There's no way to indicate a short write, so if the request goes past
+ the end of the port's memory range, flag an error. */
+ if (count > iomem->size - iomem->current)
+ {
+ gdbscm_out_of_range_error (FUNC_NAME, 0, gdbscm_scm_from_ulongest (count),
+ _("writing beyond end of memory range"));
+ }
+
+ if (target_write_memory (iomem->start + iomem->current, ptr, count) != 0)
+ gdbscm_memory_error (FUNC_NAME, _("error writing memory"), SCM_EOL);
+ iomem->current += count;
+
+ return count;
+}
+
+#else /* !PORTS_V22 */
+
/* "fill_input" method for memory ports. */
static int
@@ -850,18 +1059,19 @@ gdbscm_memory_port_free (SCM port)
return 0;
}
+#endif
+
/* "print" method for memory ports. */
static int
gdbscm_memory_port_print (SCM exp, SCM port, scm_print_state *pstate)
{
ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (exp);
- char *type = SCM_PTOBNAME (SCM_PTOBNUM (exp));
scm_puts ("#<", port);
scm_print_port_mode (exp, port);
/* scm_print_port_mode includes a trailing space. */
- gdbscm_printf (port, "%s %s-%s", type,
+ gdbscm_printf (port, "%s %s-%s", memory_port_type_name,
hex_string (iomem->start), hex_string (iomem->end));
scm_putc ('>', port);
return 1;
@@ -872,16 +1082,25 @@ gdbscm_memory_port_print (SCM exp, SCM port, scm_print
static void
ioscm_init_memory_port_type (void)
{
- memory_port_desc = scm_make_port_type (memory_port_desc_name,
+ memory_port_type = scm_make_port_type (memory_port_type_name,
+#if PORTS_V22
+ gdbscm_memory_port_read,
+#else
gdbscm_memory_port_fill_input,
+#endif
gdbscm_memory_port_write);
- scm_set_port_end_input (memory_port_desc, gdbscm_memory_port_end_input);
- scm_set_port_flush (memory_port_desc, gdbscm_memory_port_flush);
- scm_set_port_seek (memory_port_desc, gdbscm_memory_port_seek);
- scm_set_port_close (memory_port_desc, gdbscm_memory_port_close);
- scm_set_port_free (memory_port_desc, gdbscm_memory_port_free);
- scm_set_port_print (memory_port_desc, gdbscm_memory_port_print);
+#if PORTS_V22
+ scm_set_port_get_natural_buffer_sizes (memory_port_type,
+ gdbscm_get_natural_buffer_sizes);
+#else
+ scm_set_port_end_input (memory_port_type, gdbscm_memory_port_end_input);
+ scm_set_port_flush (memory_port_type, gdbscm_memory_port_flush);
+ scm_set_port_free (memory_port_type, gdbscm_memory_port_free);
+ scm_set_port_close (memory_port_type, gdbscm_memory_port_close);
+#endif
+ scm_set_port_seek (memory_port_type, gdbscm_memory_port_seek);
+ scm_set_port_print (memory_port_type, gdbscm_memory_port_print);
}
/* Helper for gdbscm_open_memory to parse the mode bits.
@@ -921,27 +1140,20 @@ ioscm_parse_mode_bits (const char *func_name, const ch
return mode_bits;
}
-/* Helper for gdbscm_open_memory to finish initializing the port.
- The port has address range [start,end).
- This means that address of 0xff..ff is not accessible.
- I can live with that. */
-
-static void
-ioscm_init_memory_port (SCM port, CORE_ADDR start, CORE_ADDR end)
+static scm_t_bits
+ioscm_init_memory_stream (bool buffered, CORE_ADDR start, CORE_ADDR end)
{
- scm_t_port *pt;
- ioscm_memory_port *iomem;
- int buffered = (SCM_CELL_WORD_0 (port) & SCM_BUF0) == 0;
+ auto iomem = reinterpret_cast<ioscm_memory_port *>(
+ scm_gc_malloc_pointerless (sizeof (ioscm_memory_port), "memory port"));
gdb_assert (start <= end);
- iomem = (ioscm_memory_port *) scm_gc_malloc_pointerless (sizeof (*iomem),
- "memory port");
-
iomem->start = start;
iomem->end = end;
iomem->size = end - start;
iomem->current = 0;
+
+#if !PORTS_V22
if (buffered)
{
iomem->read_buf_size = default_read_buf_size;
@@ -952,7 +1164,25 @@ ioscm_init_memory_port (SCM port, CORE_ADDR start, COR
iomem->read_buf_size = 1;
iomem->write_buf_size = 1;
}
+#endif
+ return reinterpret_cast<scm_t_bits>(iomem);
+}
+
+#if !PORTS_V22
+
+/* Helper for gdbscm_open_memory to finish initializing the port.
+ The port has address range [start,end).
+ This means that address of 0xff..ff is not accessible.
+ I can live with that. */
+
+static void
+ioscm_init_memory_port_buffers (SCM port)
+{
+ scm_t_port *pt;
+ auto iomem = reinterpret_cast<const ioscm_memory_port *>(SCM_STREAM (port));
+ bool buffered = (SCM_CELL_WORD_0 (port) & SCM_BUF0) == 0;
+
pt = SCM_PTAB_ENTRY (port);
/* Match the expectation of `binary-port?'. */
pt->encoding = NULL;
@@ -972,8 +1202,6 @@ ioscm_init_memory_port (SCM port, CORE_ADDR start, COR
pt->read_pos = pt->read_end = pt->read_buf;
pt->write_pos = pt->write_buf;
pt->write_end = pt->write_buf + pt->write_buf_size;
-
- SCM_SETSTREAM (port, iomem);
}
/* Re-initialize a memory port, updating its read/write buffer sizes.
@@ -1041,6 +1269,8 @@ ioscm_reinit_memory_port (SCM port, size_t read_buf_si
}
}
+#endif /* !PORTS_V22 */
+
/* (open-memory [#:mode string] [#:start address] [#:size integer]) -> port
Return a port that can be used for reading and writing memory.
MODE is a string, and must be one of "r", "w", or "r+".
@@ -1107,10 +1337,19 @@ gdbscm_open_memory (SCM rest)
end = ~(CORE_ADDR) 0;
mode_bits = ioscm_parse_mode_bits (FUNC_NAME, mode);
+ /* Edge case: empty range -> unbuffered.
+ There's no need to disallow empty ranges, but we need an unbuffered port
+ to get the semantics right. */
+ if (size == 0)
+ mode_bits |= SCM_BUF0;
- port = ioscm_open_port (memory_port_desc, mode_bits);
+ bool buffered = (mode_bits & SCM_BUF0) == 0;
+ auto stream = ioscm_init_memory_stream(buffered, start, end);
+ port = ioscm_open_port (memory_port_type, mode_bits, stream);
- ioscm_init_memory_port (port, start, end);
+#if !PORTS_V22
+ ioscm_init_memory_port_buffers (port);
+#endif
scm_dynwind_end ();
@@ -1123,7 +1362,12 @@ gdbscm_open_memory (SCM rest)
static int
gdbscm_is_memory_port (SCM obj)
{
- return !SCM_IMP (obj) && (SCM_TYP16 (obj) == memory_port_desc);
+ /* This is copied from SCM_FPORTP. */
+#if PORTS_V22
+ return SCM_PORTP (obj) && SCM_PORT_TYPE (obj) == memory_port_type;
+#else
+ return !SCM_IMP (obj) && SCM_TYP16 (obj) == memory_port_type;
+#endif
}
/* (memory-port? obj) -> boolean */
@@ -1142,13 +1386,15 @@ gdbscm_memory_port_range (SCM port)
ioscm_memory_port *iomem;
SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
- memory_port_desc_name);
+ memory_port_type_name);
iomem = (ioscm_memory_port *) SCM_STREAM (port);
return scm_list_2 (gdbscm_scm_from_ulongest (iomem->start),
gdbscm_scm_from_ulongest (iomem->end));
}
+#if !PORTS_V22
+
/* (memory-port-read-buffer-size port) -> integer */
static SCM
@@ -1157,7 +1403,7 @@ gdbscm_memory_port_read_buffer_size (SCM port)
ioscm_memory_port *iomem;
SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
- memory_port_desc_name);
+ memory_port_type_name);
iomem = (ioscm_memory_port *) SCM_STREAM (port);
return scm_from_uint (iomem->read_buf_size);
@@ -1173,7 +1419,7 @@ gdbscm_set_memory_port_read_buffer_size_x (SCM port, S
ioscm_memory_port *iomem;
SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
- memory_port_desc_name);
+ memory_port_type_name);
SCM_ASSERT_TYPE (scm_is_integer (size), size, SCM_ARG2, FUNC_NAME,
_("integer"));
@@ -1199,7 +1445,7 @@ gdbscm_memory_port_write_buffer_size (SCM port)
ioscm_memory_port *iomem;
SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
- memory_port_desc_name);
+ memory_port_type_name);
iomem = (ioscm_memory_port *) SCM_STREAM (port);
return scm_from_uint (iomem->write_buf_size);
@@ -1215,7 +1461,7 @@ gdbscm_set_memory_port_write_buffer_size_x (SCM port,
ioscm_memory_port *iomem;
SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME,
- memory_port_desc_name);
+ memory_port_type_name);
SCM_ASSERT_TYPE (scm_is_integer (size), size, SCM_ARG2, FUNC_NAME,
_("integer"));
@@ -1232,6 +1478,8 @@ gdbscm_set_memory_port_write_buffer_size_x (SCM port,
return SCM_UNSPECIFIED;
}
+
+#endif /* !PORTS_V22 */
/* Initialize gdb ports. */
@@ -1268,6 +1516,7 @@ Return #t if the object is a memory port." },
"\
Return the memory range of the port as (start end)." },
+#if !PORTS_V22
{ "memory-port-read-buffer-size", 1, 0, 0,
as_a_scm_t_subr (gdbscm_memory_port_read_buffer_size),
"\
@@ -1293,6 +1542,7 @@ Set the size of the write buffer for the memory port.\
\n\
Arguments: port integer\n\
Returns: unspecified." },
+#endif
END_FUNCTIONS
};
@@ -1365,9 +1615,11 @@ gdbscm_initialize_ports (void)
start_keyword = scm_from_latin1_keyword ("start");
size_keyword = scm_from_latin1_keyword ("size");
+#if !PORTS_V22
/* Error message text for "out of range" memory port buffer sizes. */
out_of_range_buf_size = xstrprintf ("size not between %u - %u",
min_memory_port_buf_size,
max_memory_port_buf_size);
+#endif
}
|