From f14bbacae00dd0086c4d58d75bdc82a2131ebddb Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 26 Nov 2025 12:45:38 -0500 Subject: [PATCH] gdb/guile: remove support for Guile < 2.2 I propose to remove the code in guile/scm-ports.c supporting Guile < 2.2. The rationale is: - The code within USING_GUILE_BEFORE_2_2 amounts to about half of the file, it makes it much more complicated than it would be otherwise. I'm trying to investigate PR 29825 [1] and this is getting in the way. - Guile 2.2, which would now be the baseline for what we require, is now 8 years old. Guile 2.2 is legacy (the current stable branch is 3.0), but it is still actively packaged [2][3]. - The Guile support code doesn't receive as much contribution, testing and love as the Python support code, for instance. We don't have cycles to spare to support an obsolete version of Guile. This patch removes the USING_GUILE_BEFORE_2_2 define and all the portions of code within `#if USING_GUILE_BEFORE_2_2`. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=29825 [2] https://packages.debian.org/sid/guile-2.2-dev [3] https://archlinux.org/packages/extra/x86_64/guile2.2/ Change-Id: I926e79cde9835567eb3b7e3d22db402c841b79d7 Reviewed-by: Thiago Jung Bauermann --- gdb/guile/scm-ports.c | 768 ------------------------------------------ 1 file changed, 768 deletions(-) diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c index f3e3ec871b5..de0cf800084 100644 --- a/gdb/guile/scm-ports.c +++ b/gdb/guile/scm-ports.c @@ -35,12 +35,6 @@ #endif #endif -/* Whether we're using Guile < 2.2 and its clumsy port API. */ - -#define USING_GUILE_BEFORE_2_2 \ - (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION == 0) - - /* A ui-file for sending output to Guile. */ class ioscm_file_port : public ui_file @@ -70,15 +64,6 @@ struct ioscm_memory_port /* Think of this as the lseek value maintained by the kernel. This value is always in the range [0, size]. */ ULONGEST current; - -#if USING_GUILE_BEFORE_2_2 - /* 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 }; /* Copies of the original system input/output/error ports. @@ -88,11 +73,7 @@ static SCM orig_output_port_scm; static SCM orig_error_port_scm; /* This is the stdio port descriptor, scm_ptob_descriptor. */ -#if USING_GUILE_BEFORE_2_2 -static scm_t_bits stdio_port_desc; -#else static scm_t_port_type *stdio_port_desc; -#endif /* Note: scm_make_port_type takes a char * instead of a const char *. */ static /*const*/ char stdio_port_desc_name[] = "gdb:stdio-port"; @@ -113,40 +94,14 @@ static SCM error_port_scm; enum oport { GDB_STDOUT, GDB_STDERR }; /* This is the memory port descriptor, scm_ptob_descriptor. */ -#if USING_GUILE_BEFORE_2_2 -static scm_t_bits memory_port_desc; -#else static scm_t_port_type *memory_port_desc; -#endif /* Note: scm_make_port_type takes a char * instead of a const char *. */ static /*const*/ char memory_port_desc_name[] = "gdb:memory-port"; -#if USING_GUILE_BEFORE_2_2 - -/* 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, - which over a remote link can be important. To compensate we augment the - port API with a new function that let's the user specify how much the next - read request should fetch. This is the initial value for each new port. */ -static const unsigned default_read_buf_size = 16; -static const unsigned default_write_buf_size = 16; - -/* Arbitrarily limit memory port buffers to 1 byte to 4K. */ -static const unsigned min_memory_port_buf_size = 1; -static const unsigned max_memory_port_buf_size = 4096; - -/* "out of range" error message for buf sizes. */ -static gdb::unique_xmalloc_ptr out_of_range_buf_size; - -#else - /* The maximum values to use for get_natural_buffer_sizes. */ static const unsigned natural_buf_size = 16; -#endif - /* Keywords used by open-memory. */ static SCM mode_keyword; static SCM start_keyword; @@ -154,39 +109,12 @@ static SCM size_keyword; /* Helper to do the low level work of opening a port. */ -#if USING_GUILE_BEFORE_2_2 - -static SCM -ioscm_open_port (scm_t_bits port_type, long mode_bits, scm_t_bits stream) -{ - SCM port; - -#if 0 /* TODO: Guile doesn't export this. What to do? */ - scm_i_scm_pthread_mutex_lock (&scm_i_port_table_mutex); -#endif - - port = scm_new_port_table_entry (port_type); - - SCM_SET_CELL_TYPE (port, port_type | mode_bits); - SCM_SETSTREAM (port, stream); - -#if 0 /* TODO: Guile doesn't export this. What to do? */ - scm_i_pthread_mutex_unlock (&scm_i_port_table_mutex); -#endif - - return port; -} - -#else - static SCM ioscm_open_port (scm_t_port_type *port_type, long mode_bits, scm_t_bits stream) { return scm_c_make_port (port_type, mode_bits, stream); } -#endif - /* Support for connecting Guile's stdio ports to GDB's stdio ports. */ @@ -207,148 +135,6 @@ fputsn_filtered (const char *s, size_t size, struct ui_file *stream) } } -#if USING_GUILE_BEFORE_2_2 - -/* The scm_t_ptob_descriptor.input_waiting "method". - Return a lower bound on the number of bytes available for input. */ - -static int -ioscm_input_waiting (SCM port) -{ - int fdes = 0; - - if (! scm_is_eq (port, input_port_scm)) - return 0; - -#ifdef HAVE_POLL - { - /* This is copied from libguile/fports.c. */ - struct pollfd pollfd = { fdes, POLLIN, 0 }; - static int use_poll = -1; - - if (use_poll < 0) - { - /* This is copied from event-loop.c: poll cannot be used for stdin on - m68k-motorola-sysv. */ - struct pollfd test_pollfd = { fdes, POLLIN, 0 }; - - if (poll (&test_pollfd, 1, 0) == 1 && (test_pollfd.revents & POLLNVAL)) - use_poll = 0; - else - use_poll = 1; - } - - if (use_poll) - { - /* Guile doesn't export SIGINT hooks like Python does. - For now pass EINTR to scm_syserror, that's what fports.c does. */ - if (poll (&pollfd, 1, 0) < 0) - scm_syserror (FUNC_NAME); - - return pollfd.revents & POLLIN ? 1 : 0; - } - } - /* Fall through. */ -#endif - - { - struct timeval timeout; - fd_set input_fds; - int num_fds = fdes + 1; - int num_found; - - memset (&timeout, 0, sizeof (timeout)); - FD_ZERO (&input_fds); - FD_SET (fdes, &input_fds); - - num_found = interruptible_select (num_fds, - &input_fds, NULL, NULL, - &timeout); - if (num_found < 0) - { - /* Guile doesn't export SIGINT hooks like Python does. - For now pass EINTR to scm_syserror, that's what fports.c does. */ - scm_syserror (FUNC_NAME); - } - return num_found > 0 && FD_ISSET (fdes, &input_fds); - } -} - -/* The scm_t_ptob_descriptor.fill_input "method". */ - -static int -ioscm_fill_input (SCM port) -{ - /* Borrowed from libguile/fports.c. */ - long count; - scm_t_port *pt = SCM_PTAB_ENTRY (port); - - /* If we're called on stdout,stderr, punt. */ - if (! scm_is_eq (port, input_port_scm)) - return (scm_t_wchar) EOF; /* Set errno and return -1? */ - - gdb_flush (gdb_stdout); - gdb_flush (gdb_stderr); - - count = gdb_stdin->read ((char *) pt->read_buf, pt->read_buf_size); - if (count == -1) - scm_syserror (FUNC_NAME); - if (count == 0) - return (scm_t_wchar) EOF; - - pt->read_pos = pt->read_buf; - pt->read_end = pt->read_buf + count; - return *pt->read_buf; -} - -/* Write to gdb's stdout or stderr. */ - -static void -ioscm_write (SCM port, const void *data, size_t size) -{ - - /* If we're called on stdin, punt. */ - if (scm_is_eq (port, input_port_scm)) - return; - - gdbscm_gdb_exception exc {}; - try - { - if (scm_is_eq (port, error_port_scm)) - fputsn_filtered ((const char *) data, size, gdb_stderr); - else - fputsn_filtered ((const char *) data, size, gdb_stdout); - } - catch (const gdb_exception &except) - { - exc = unpack (except); - } - GDBSCM_HANDLE_GDB_EXCEPTION (exc); -} - -/* Flush gdb's stdout or stderr. */ - -static void -ioscm_flush (SCM port) -{ - /* If we're called on stdin, punt. */ - if (scm_is_eq (port, input_port_scm)) - return; - - if (scm_is_eq (port, error_port_scm)) - { - if (gdb_stderr != nullptr) - gdb_flush (gdb_stderr); - } - else - { - if (gdb_stdout != nullptr) - gdb_flush (gdb_stdout); - } -} - -#else /* !USING_GUILE_BEFORE_2_2 */ - /* Read up to COUNT bytes into bytevector DST at offset START. Return the number of bytes read, zero for the end of file. */ @@ -401,8 +187,6 @@ ioscm_write (SCM port, SCM src, size_t start, size_t count) return count; } -#endif /* !USING_GUILE_BEFORE_2_2 */ - /* Initialize the gdb stdio port type. N.B. isatty? will fail on these ports, it is only supported for file @@ -412,68 +196,14 @@ static void ioscm_init_gdb_stdio_port (void) { stdio_port_desc = scm_make_port_type (stdio_port_desc_name, -#if USING_GUILE_BEFORE_2_2 - ioscm_fill_input, -#else ioscm_read_from_port, -#endif ioscm_write); -#if USING_GUILE_BEFORE_2_2 - scm_set_port_input_waiting (stdio_port_desc, ioscm_input_waiting); - scm_set_port_flush (stdio_port_desc, ioscm_flush); -#else scm_set_port_read_wait_fd (stdio_port_desc, STDIN_FILENO); -#endif } #define GDB_STDIO_BUFFER_DEFAULT_SIZE 1024 -#if USING_GUILE_BEFORE_2_2 - -/* 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. */ - -static void -ioscm_init_stdio_buffers (SCM port, long mode_bits) -{ - scm_t_port *pt = SCM_PTAB_ENTRY (port); - int size = mode_bits & SCM_BUF0 ? 0 : GDB_STDIO_BUFFER_DEFAULT_SIZE; - int writing = (mode_bits & SCM_WRTNG) != 0; - - /* This is heavily copied from scm_fport_buffer_add. */ - - if (!writing && size > 0) - { - pt->read_buf - = (unsigned char *) scm_gc_malloc_pointerless (size, "port buffer"); - pt->read_pos = pt->read_end = pt->read_buf; - pt->read_buf_size = size; - } - else - { - pt->read_pos = pt->read_buf = pt->read_end = &pt->shortbuf; - pt->read_buf_size = 1; - } - - if (writing && size > 0) - { - pt->write_buf - = (unsigned char *) scm_gc_malloc_pointerless (size, "port buffer"); - pt->write_pos = pt->write_buf; - pt->write_buf_size = size; - } - else - { - pt->write_buf = pt->write_pos = &pt->shortbuf; - pt->write_buf_size = 1; - } - pt->write_end = pt->write_buf + pt->write_buf_size; -} - -#else - static void ioscm_init_stdio_buffers (SCM port, long mode_bits) { @@ -484,8 +214,6 @@ ioscm_init_stdio_buffers (SCM port, long mode_bits) scm_from_size_t (GDB_STDIO_BUFFER_DEFAULT_SIZE)); } -#endif - /* Create a gdb stdio port. */ static SCM @@ -530,14 +258,8 @@ ioscm_make_gdb_stdio_port (int fd) static SCM gdbscm_stdio_port_p (SCM scm) { -#if USING_GUILE_BEFORE_2_2 - /* This is copied from SCM_FPORTP. */ - return scm_from_bool (!SCM_IMP (scm) - && (SCM_TYP16 (scm) == stdio_port_desc)); -#else return scm_from_bool (SCM_PORTP (scm) && (SCM_PORT_TYPE (scm) == stdio_port_desc)); -#endif } /* GDB's ports are accessed via functions to keep them read-only. */ @@ -699,358 +421,6 @@ ioscm_lseek_address (ioscm_memory_port *iomem, LONGEST offset, int whence) return 1; } -#if USING_GUILE_BEFORE_2_2 - -/* "fill_input" method for memory ports. */ - -static int -gdbscm_memory_port_fill_input (SCM port) -{ - scm_t_port *pt = SCM_PTAB_ENTRY (port); - 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 EOF; - - /* Don't read outside the allowed memory range. */ - to_read = pt->read_buf_size; - if (to_read > iomem->size - iomem->current) - to_read = iomem->size - iomem->current; - - if (target_read_memory (iomem->start + iomem->current, pt->read_buf, - to_read) != 0) - gdbscm_memory_error (FUNC_NAME, _("error reading memory"), SCM_EOL); - - iomem->current += to_read; - pt->read_pos = pt->read_buf; - pt->read_end = pt->read_buf + to_read; - return *pt->read_buf; -} - -/* "end_input" method for memory ports. - Clear the read buffer and adjust the file position for unread bytes. */ - -static void -gdbscm_memory_port_end_input (SCM port, int offset) -{ - scm_t_port *pt = SCM_PTAB_ENTRY (port); - ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port); - size_t remaining = pt->read_end - pt->read_pos; - - /* Note: Use of "int offset" is specified by Guile ports API. */ - if ((offset < 0 && remaining + offset > remaining) - || (offset > 0 && remaining + offset < remaining)) - { - gdbscm_out_of_range_error (FUNC_NAME, 0, scm_from_int (offset), - _("overflow in offset calculation")); - } - offset += remaining; - - if (offset > 0) - { - pt->read_pos = pt->read_end; - /* Throw error if unread-char used at beginning of file - then attempting to write. Seems correct. */ - if (!ioscm_lseek_address (iomem, -offset, SEEK_CUR)) - { - gdbscm_out_of_range_error (FUNC_NAME, 0, scm_from_int (offset), - _("bad offset")); - } - } - - pt->rw_active = SCM_PORT_NEITHER; -} - -/* "flush" method for memory ports. */ - -static void -gdbscm_memory_port_flush (SCM port) -{ - scm_t_port *pt = SCM_PTAB_ENTRY (port); - ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port); - size_t to_write = pt->write_pos - pt->write_buf; - - if (to_write == 0) - return; - - /* 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 (to_write > iomem->size - iomem->current) - { - gdbscm_out_of_range_error (FUNC_NAME, 0, - gdbscm_scm_from_ulongest (to_write), - _("writing beyond end of memory range")); - } - - if (target_write_memory (iomem->start + iomem->current, pt->write_buf, - to_write) != 0) - gdbscm_memory_error (FUNC_NAME, _("error writing memory"), SCM_EOL); - - iomem->current += to_write; - pt->write_pos = pt->write_buf; - pt->rw_active = SCM_PORT_NEITHER; -} - -/* "seek" method for memory ports. */ - -static scm_t_off -gdbscm_memory_port_seek (SCM port, scm_t_off offset, int whence) -{ - scm_t_port *pt = SCM_PTAB_ENTRY (port); - ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port); - CORE_ADDR result; - int rc; - - if (pt->rw_active == SCM_PORT_WRITE) - { - if (offset != 0 || whence != SEEK_CUR) - { - gdbscm_memory_port_flush (port); - rc = ioscm_lseek_address (iomem, offset, whence); - result = iomem->current; - } - else - { - /* Read current position without disturbing the buffer, - but flag an error if what's in the buffer goes outside the - allowed range. */ - CORE_ADDR current = iomem->current; - size_t delta = pt->write_pos - pt->write_buf; - - if (current + delta < current - || current + delta > iomem->size) - rc = 0; - else - { - result = current + delta; - rc = 1; - } - } - } - else if (pt->rw_active == SCM_PORT_READ) - { - if (offset != 0 || whence != SEEK_CUR) - { - scm_end_input (port); - rc = ioscm_lseek_address (iomem, offset, whence); - result = iomem->current; - } - else - { - /* Read current position without disturbing the buffer - (particularly the unread-char buffer). */ - CORE_ADDR current = iomem->current; - size_t remaining = pt->read_end - pt->read_pos; - - if (current - remaining > current - || current - remaining < iomem->start) - rc = 0; - else - { - result = current - remaining; - rc = 1; - } - - if (rc != 0 && pt->read_buf == pt->putback_buf) - { - size_t saved_remaining = pt->saved_read_end - pt->saved_read_pos; - - if (result - saved_remaining > result - || result - saved_remaining < iomem->start) - rc = 0; - else - result -= saved_remaining; - } - } - } - else /* SCM_PORT_NEITHER */ - { - rc = ioscm_lseek_address (iomem, offset, whence); - result = iomem->current; - } - - if (rc == 0) - { - gdbscm_out_of_range_error (FUNC_NAME, 0, - gdbscm_scm_from_longest (offset), - _("bad seek")); - } - - /* TODO: The Guile API doesn't support 32x64. We can't fix that here, - and there's no need to throw an error if the new address can't be - represented in a scm_t_off. But we could return something less - clumsy. */ - return result; -} - -/* "write" method for memory ports. */ - -static void -gdbscm_memory_port_write (SCM port, const void *void_data, size_t size) -{ - scm_t_port *pt = SCM_PTAB_ENTRY (port); - ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port); - const gdb_byte *data = (const gdb_byte *) void_data; - - /* 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 (size > iomem->size - iomem->current) - { - gdbscm_out_of_range_error (FUNC_NAME, 0, gdbscm_scm_from_ulongest (size), - _("writing beyond end of memory range")); - } - - if (pt->write_buf == &pt->shortbuf) - { - /* Unbuffered port. */ - if (target_write_memory (iomem->start + iomem->current, data, size) != 0) - gdbscm_memory_error (FUNC_NAME, _("error writing memory"), SCM_EOL); - iomem->current += size; - return; - } - - /* Note: The edge case of what to do when the buffer exactly fills is - debatable. Guile flushes when the buffer exactly fills up, so we - do too. It's counter-intuitive to my mind, but in case there's a - subtlety somewhere that depends on this, we do the same. */ - - { - size_t space = pt->write_end - pt->write_pos; - - if (size < space) - { - /* Data fits in buffer, and does not fill it. */ - memcpy (pt->write_pos, data, size); - pt->write_pos += size; - } - else - { - memcpy (pt->write_pos, data, space); - pt->write_pos = pt->write_end; - gdbscm_memory_port_flush (port); - { - const gdb_byte *ptr = data + space; - size_t remaining = size - space; - - if (remaining >= pt->write_buf_size) - { - if (target_write_memory (iomem->start + iomem->current, ptr, - remaining) != 0) - gdbscm_memory_error (FUNC_NAME, _("error writing memory"), - SCM_EOL); - iomem->current += remaining; - } - else - { - memcpy (pt->write_pos, ptr, remaining); - pt->write_pos += remaining; - } - } - } - } -} - -/* "close" method for memory ports. */ - -static int -gdbscm_memory_port_close (SCM port) -{ - scm_t_port *pt = SCM_PTAB_ENTRY (port); - ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port); - - gdbscm_memory_port_flush (port); - - if (pt->read_buf == pt->putback_buf) - pt->read_buf = pt->saved_read_buf; - if (pt->read_buf != &pt->shortbuf) - xfree (pt->read_buf); - if (pt->write_buf != &pt->shortbuf) - xfree (pt->write_buf); - scm_gc_free (iomem, sizeof (*iomem), "memory port"); - - return 0; -} - -/* "free" method for memory ports. */ - -static size_t -gdbscm_memory_port_free (SCM port) -{ - gdbscm_memory_port_close (port); - - return 0; -} - -/* Re-initialize a memory port, updating its read/write buffer sizes. - An exception is thrown if the port is unbuffered. - TODO: Allow switching buffered/unbuffered. - An exception is also thrown if data is still buffered, except in the case - where the buffer size isn't changing (since that's just a nop). */ - -static void -ioscm_reinit_memory_port (SCM port, size_t read_buf_size, - size_t write_buf_size, const char *func_name) -{ - scm_t_port *pt = SCM_PTAB_ENTRY (port); - ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port); - - gdb_assert (read_buf_size >= min_memory_port_buf_size - && read_buf_size <= max_memory_port_buf_size); - gdb_assert (write_buf_size >= min_memory_port_buf_size - && write_buf_size <= max_memory_port_buf_size); - - /* First check if the port is unbuffered. */ - - if (pt->read_buf == &pt->shortbuf) - { - gdb_assert (pt->write_buf == &pt->shortbuf); - scm_misc_error (func_name, _("port is unbuffered: ~a"), - scm_list_1 (port)); - } - - /* Next check if anything is buffered. */ - - if (read_buf_size != pt->read_buf_size - && pt->read_end != pt->read_buf) - { - scm_misc_error (func_name, _("read buffer not empty: ~a"), - scm_list_1 (port)); - } - - if (write_buf_size != pt->write_buf_size - && pt->write_pos != pt->write_buf) - { - scm_misc_error (func_name, _("write buffer not empty: ~a"), - scm_list_1 (port)); - } - - /* Now we can update the buffer sizes, but only if the size has changed. */ - - if (read_buf_size != pt->read_buf_size) - { - iomem->read_buf_size = read_buf_size; - pt->read_buf_size = read_buf_size; - xfree (pt->read_buf); - pt->read_buf = (unsigned char *) xmalloc (pt->read_buf_size); - pt->read_pos = pt->read_end = pt->read_buf; - } - - if (write_buf_size != pt->write_buf_size) - { - iomem->write_buf_size = write_buf_size; - pt->write_buf_size = write_buf_size; - xfree (pt->write_buf); - pt->write_buf = (unsigned char *) xmalloc (pt->write_buf_size); - pt->write_pos = pt->write_buf; - pt->write_end = pt->write_buf + pt->write_buf_size; - } -} - -#else /* !USING_GUILE_BEFORE_2_2 */ - /* The semantics get weird if the buffer size is larger than the port range, so provide a better default buffer size. */ @@ -1143,8 +513,6 @@ gdbscm_memory_port_close (SCM port) SCM_SETSTREAM (port, NULL); } -#endif /* !USING_GUILE_BEFORE_2_2 */ - /* "print" method for memory ports. */ static int @@ -1167,21 +535,11 @@ static void ioscm_init_memory_port_type (void) { memory_port_desc = scm_make_port_type (memory_port_desc_name, -#if USING_GUILE_BEFORE_2_2 - gdbscm_memory_port_fill_input, -#else gdbscm_memory_port_read, -#endif gdbscm_memory_port_write); -#if USING_GUILE_BEFORE_2_2 - 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_free (memory_port_desc, gdbscm_memory_port_free); -#else scm_set_port_get_natural_buffer_sizes (memory_port_desc, gdbscm_get_natural_buffer_sizes); -#endif 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_print (memory_port_desc, gdbscm_memory_port_print); @@ -1245,53 +603,6 @@ ioscm_init_memory_port_stream (CORE_ADDR start, CORE_ADDR end) return iomem; } -#if USING_GUILE_BEFORE_2_2 - -/* 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) -{ - ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port); - - int buffered = (SCM_CELL_WORD_0 (port) & SCM_BUF0) == 0; - if (buffered) - { - iomem->read_buf_size = default_read_buf_size; - iomem->write_buf_size = default_write_buf_size; - } - else - { - iomem->read_buf_size = 1; - iomem->write_buf_size = 1; - } - - scm_t_port *pt = SCM_PTAB_ENTRY (port); - /* Match the expectation of `binary-port?'. */ - pt->encoding = NULL; - pt->rw_random = 1; - pt->read_buf_size = iomem->read_buf_size; - pt->write_buf_size = iomem->write_buf_size; - if (buffered) - { - pt->read_buf = (unsigned char *) xmalloc (pt->read_buf_size); - pt->write_buf = (unsigned char *) xmalloc (pt->write_buf_size); - } - else - { - pt->read_buf = &pt->shortbuf; - pt->write_buf = &pt->shortbuf; - } - 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; -} - -#endif - /* (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+". @@ -1369,10 +680,6 @@ gdbscm_open_memory (SCM rest) port = ioscm_open_port (memory_port_desc, mode_bits, (scm_t_bits) stream); -#if USING_GUILE_BEFORE_2_2 - ioscm_init_memory_port_buffers (port); -#endif - scm_dynwind_end (); /* TODO: Set the file name as "memory-start-end"? */ @@ -1384,11 +691,7 @@ gdbscm_open_memory (SCM rest) static int gdbscm_is_memory_port (SCM obj) { -#if USING_GUILE_BEFORE_2_2 - return !SCM_IMP (obj) && (SCM_TYP16 (obj) == memory_port_desc); -#else return SCM_PORTP (obj) && (SCM_PORT_TYPE (obj) == memory_port_desc); -#endif } /* (memory-port? obj) -> boolean */ @@ -1419,17 +722,7 @@ gdbscm_memory_port_range (SCM port) static SCM gdbscm_memory_port_read_buffer_size (SCM port) { -#if USING_GUILE_BEFORE_2_2 - ioscm_memory_port *iomem; - - SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME, - memory_port_desc_name); - - iomem = (ioscm_memory_port *) SCM_STREAM (port); - return scm_from_uint (iomem->read_buf_size); -#else return scm_from_uint (0); -#endif } /* (set-memory-port-read-buffer-size! port size) -> unspecified @@ -1439,29 +732,7 @@ gdbscm_memory_port_read_buffer_size (SCM port) static SCM gdbscm_set_memory_port_read_buffer_size_x (SCM port, SCM size) { -#if USING_GUILE_BEFORE_2_2 - ioscm_memory_port *iomem; - - SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME, - memory_port_desc_name); - SCM_ASSERT_TYPE (scm_is_integer (size), size, SCM_ARG2, FUNC_NAME, - _("integer")); - - if (!scm_is_unsigned_integer (size, min_memory_port_buf_size, - max_memory_port_buf_size)) - { - gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG2, size, - out_of_range_buf_size.get ()); - } - - iomem = (ioscm_memory_port *) SCM_STREAM (port); - ioscm_reinit_memory_port (port, scm_to_uint (size), iomem->write_buf_size, - FUNC_NAME); - - return SCM_UNSPECIFIED; -#else return scm_setvbuf (port, scm_from_utf8_symbol ("block"), size); -#endif } /* (memory-port-write-buffer-size port) -> integer */ @@ -1469,17 +740,7 @@ gdbscm_set_memory_port_read_buffer_size_x (SCM port, SCM size) static SCM gdbscm_memory_port_write_buffer_size (SCM port) { -#if USING_GUILE_BEFORE_2_2 - ioscm_memory_port *iomem; - - SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME, - memory_port_desc_name); - - iomem = (ioscm_memory_port *) SCM_STREAM (port); - return scm_from_uint (iomem->write_buf_size); -#else return scm_from_uint (0); -#endif } /* (set-memory-port-write-buffer-size! port size) -> unspecified @@ -1489,29 +750,7 @@ gdbscm_memory_port_write_buffer_size (SCM port) static SCM gdbscm_set_memory_port_write_buffer_size_x (SCM port, SCM size) { -#if USING_GUILE_BEFORE_2_2 - ioscm_memory_port *iomem; - - SCM_ASSERT_TYPE (gdbscm_is_memory_port (port), port, SCM_ARG1, FUNC_NAME, - memory_port_desc_name); - SCM_ASSERT_TYPE (scm_is_integer (size), size, SCM_ARG2, FUNC_NAME, - _("integer")); - - if (!scm_is_unsigned_integer (size, min_memory_port_buf_size, - max_memory_port_buf_size)) - { - gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG2, size, - out_of_range_buf_size.get ()); - } - - iomem = (ioscm_memory_port *) SCM_STREAM (port); - ioscm_reinit_memory_port (port, iomem->read_buf_size, scm_to_uint (size), - FUNC_NAME); - - return SCM_UNSPECIFIED; -#else return scm_setvbuf (port, scm_from_utf8_symbol ("block"), size); -#endif } /* Initialize gdb ports. */ @@ -1646,11 +885,4 @@ gdbscm_initialize_ports (void) start_keyword = scm_from_latin1_keyword ("start"); size_keyword = scm_from_latin1_keyword ("size"); -#if USING_GUILE_BEFORE_2_2 - /* 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 } -- 2.47.3