aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile/scm-ports.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/guile/scm-ports.c')
-rw-r--r--gdb/guile/scm-ports.c213
1 files changed, 96 insertions, 117 deletions
diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
index 48b6075..94f7226 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -29,24 +29,24 @@
#include "gdbsupport/gdb_optional.h"
#ifdef HAVE_POLL
-#if defined (HAVE_POLL_H)
+#if defined(HAVE_POLL_H)
#include <poll.h>
-#elif defined (HAVE_SYS_POLL_H)
+#elif defined(HAVE_SYS_POLL_H)
#include <sys/poll.h>
#endif
#endif
/* Whether we're using Guile < 2.2 and its clumsy port API. */
-#define USING_GUILE_BEFORE_2_2 \
+#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
{
public:
+
/* Return a ui_file that writes to PORT. */
explicit ioscm_file_port (SCM port);
@@ -54,6 +54,7 @@ public:
void write (const char *buf, long length_buf) override;
private:
+
SCM m_port;
};
@@ -111,7 +112,11 @@ static SCM output_port_scm;
static SCM error_port_scm;
/* Internal enum for specifying output port. */
-enum oport { GDB_STDOUT, GDB_STDERR };
+enum oport
+{
+ GDB_STDOUT,
+ GDB_STDERR
+};
/* This is the memory port descriptor, scm_ptob_descriptor. */
#if USING_GUILE_BEFORE_2_2
@@ -152,7 +157,7 @@ static const unsigned natural_buf_size = 16;
static SCM mode_keyword;
static SCM start_keyword;
static SCM size_keyword;
-
+
/* Helper to do the low level work of opening a port. */
#if USING_GUILE_BEFORE_2_2
@@ -188,7 +193,6 @@ ioscm_open_port (scm_t_port_type *port_type, long mode_bits, scm_t_bits stream)
#endif
-
/* Support for connecting Guile's stdio ports to GDB's stdio ports. */
/* Print a string S, length SIZE, but don't escape characters, except
@@ -218,7 +222,7 @@ ioscm_input_waiting (SCM port)
{
int fdes = 0;
- if (! scm_is_eq (port, input_port_scm))
+ if (!scm_is_eq (port, input_port_scm))
return 0;
#ifdef HAVE_POLL
@@ -262,9 +266,8 @@ ioscm_input_waiting (SCM port)
FD_ZERO (&input_fds);
FD_SET (fdes, &input_fds);
- num_found = interruptible_select (num_fds,
- &input_fds, NULL, NULL,
- &timeout);
+ num_found
+ = interruptible_select (num_fds, &input_fds, NULL, NULL, &timeout);
if (num_found < 0)
{
/* Guile doesn't export SIGINT hooks like Python does.
@@ -285,7 +288,7 @@ ioscm_fill_input (SCM port)
scm_t_port *pt = SCM_PTAB_ENTRY (port);
/* If we're called on stdout,stderr, punt. */
- if (! scm_is_eq (port, input_port_scm))
+ if (!scm_is_eq (port, input_port_scm))
return (scm_t_wchar) EOF; /* Set errno and return -1? */
gdb_flush (gdb_stdout);
@@ -307,7 +310,6 @@ ioscm_fill_input (SCM port)
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;
@@ -354,7 +356,7 @@ ioscm_read_from_port (SCM port, SCM dst, size_t start, size_t count)
char *read_buf;
/* If we're called on stdout,stderr, punt. */
- if (! scm_is_eq (port, input_port_scm))
+ if (!scm_is_eq (port, input_port_scm))
return 0;
gdb_flush (gdb_stdout);
@@ -534,7 +536,7 @@ gdbscm_stdio_port_p (SCM scm)
&& (SCM_PORT_TYPE (scm) == stdio_port_desc));
#endif
}
-
+
/* GDB's ports are accessed via functions to keep them read-only. */
/* (input-port) -> port */
@@ -560,12 +562,13 @@ gdbscm_error_port (void)
{
return error_port_scm;
}
-
+
/* Support for sending GDB I/O to Guile ports. */
ioscm_file_port::ioscm_file_port (SCM port)
: m_port (port)
-{}
+{
+}
void
ioscm_file_port::flush ()
@@ -578,7 +581,6 @@ ioscm_file_port::write (const char *buffer, long length_buffer)
scm_c_write (m_port, buffer, length_buffer);
}
-
/* Helper routine for with-{output,error}-to-port. */
static SCM
@@ -587,10 +589,10 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
{
SCM result;
- SCM_ASSERT_TYPE (gdbscm_is_true (scm_output_port_p (port)), port,
- SCM_ARG1, func_name, _("output port"));
- SCM_ASSERT_TYPE (gdbscm_is_true (scm_thunk_p (thunk)), thunk,
- SCM_ARG2, func_name, _("thunk"));
+ SCM_ASSERT_TYPE (gdbscm_is_true (scm_output_port_p (port)), port, SCM_ARG1,
+ func_name, _ ("output port"));
+ SCM_ASSERT_TYPE (gdbscm_is_true (scm_thunk_p (thunk)), thunk, SCM_ARG2,
+ func_name, _ ("thunk"));
set_batch_flag_and_restore_page_info save_page_info;
@@ -598,8 +600,8 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
ui_file_up port_file (new ioscm_file_port (port));
- scoped_restore save_file = make_scoped_restore (oport == GDB_STDERR
- ? &gdb_stderr : &gdb_stdout);
+ scoped_restore save_file
+ = make_scoped_restore (oport == GDB_STDERR ? &gdb_stderr : &gdb_stdout);
{
gdb::optional<ui_out_redirect_pop> redirect_popper;
@@ -650,7 +652,7 @@ gdbscm_percent_with_gdb_error_to_port (SCM port, SCM thunk)
{
return ioscm_with_output_to_port_worker (port, thunk, GDB_STDERR, FUNC_NAME);
}
-
+
/* Support for r/w memory via ports. */
/* Perform an "lseek" to OFFSET,WHENCE on memory port IOMEM.
@@ -715,9 +717,9 @@ gdbscm_memory_port_fill_input (SCM port)
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);
+ 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;
@@ -740,7 +742,7 @@ gdbscm_memory_port_end_input (SCM port, int offset)
|| (offset > 0 && remaining + offset < remaining))
{
gdbscm_out_of_range_error (FUNC_NAME, 0, scm_from_int (offset),
- _("overflow in offset calculation"));
+ _ ("overflow in offset calculation"));
}
offset += remaining;
@@ -752,7 +754,7 @@ gdbscm_memory_port_end_input (SCM port, int offset)
if (!ioscm_lseek_address (iomem, -offset, SEEK_CUR))
{
gdbscm_out_of_range_error (FUNC_NAME, 0, scm_from_int (offset),
- _("bad offset"));
+ _ ("bad offset"));
}
}
@@ -777,12 +779,13 @@ gdbscm_memory_port_flush (SCM port)
{
gdbscm_out_of_range_error (FUNC_NAME, 0,
gdbscm_scm_from_ulongest (to_write),
- _("writing beyond end of memory range"));
+ _ ("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);
+ to_write)
+ != 0)
+ gdbscm_memory_error (FUNC_NAME, _ ("error writing memory"), SCM_EOL);
iomem->current += to_write;
pt->write_pos = pt->write_buf;
@@ -815,8 +818,7 @@ gdbscm_memory_port_seek (SCM port, scm_t_off offset, int whence)
CORE_ADDR current = iomem->current;
size_t delta = pt->write_pos - pt->write_buf;
- if (current + delta < current
- || current + delta > iomem->size)
+ if (current + delta < current || current + delta > iomem->size)
rc = 0;
else
{
@@ -871,7 +873,7 @@ gdbscm_memory_port_seek (SCM port, scm_t_off offset, int whence)
{
gdbscm_out_of_range_error (FUNC_NAME, 0,
gdbscm_scm_from_longest (offset),
- _("bad seek"));
+ _ ("bad seek"));
}
/* TODO: The Guile API doesn't support 32x64. We can't fix that here,
@@ -895,14 +897,14 @@ gdbscm_memory_port_write (SCM port, const void *void_data, size_t size)
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"));
+ _ ("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);
+ gdbscm_memory_error (FUNC_NAME, _ ("error writing memory"), SCM_EOL);
iomem->current += size;
return;
}
@@ -933,8 +935,9 @@ gdbscm_memory_port_write (SCM port, const void *void_data, size_t size)
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"),
+ remaining)
+ != 0)
+ gdbscm_memory_error (FUNC_NAME, _ ("error writing memory"),
SCM_EOL);
iomem->current += remaining;
}
@@ -1002,23 +1005,21 @@ ioscm_reinit_memory_port (SCM port, size_t read_buf_size,
if (pt->read_buf == &pt->shortbuf)
{
gdb_assert (pt->write_buf == &pt->shortbuf);
- scm_misc_error (func_name, _("port is unbuffered: ~a"),
+ 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)
+ 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_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)
+ 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_misc_error (func_name, _ ("write buffer not empty: ~a"),
scm_list_1 (port));
}
@@ -1080,9 +1081,8 @@ gdbscm_memory_port_read (SCM port, SCM dst, size_t start, size_t count)
count = iomem->size - iomem->current;
read_buf = (gdb_byte *) SCM_BYTEVECTOR_CONTENTS (dst) + start;
- if (target_read_memory (iomem->start + iomem->current, read_buf,
- count) != 0)
- gdbscm_memory_error (FUNC_NAME, _("error reading memory"), SCM_EOL);
+ if (target_read_memory (iomem->start + iomem->current, read_buf, count) != 0)
+ gdbscm_memory_error (FUNC_NAME, _ ("error reading memory"), SCM_EOL);
iomem->current += count;
return count;
@@ -1092,19 +1092,17 @@ static size_t
gdbscm_memory_port_write (SCM port, SCM src, size_t start, size_t count)
{
ioscm_memory_port *iomem = (ioscm_memory_port *) SCM_STREAM (port);
- const gdb_byte *data =
- (const gdb_byte *) SCM_BYTEVECTOR_CONTENTS (src) + start;
+ const gdb_byte *data
+ = (const gdb_byte *) SCM_BYTEVECTOR_CONTENTS (src) + start;
/* 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, scm_from_size_t (count),
- _("writing beyond end of memory range"));
+ _ ("writing beyond end of memory range"));
- if (target_write_memory (iomem->start + iomem->current, data,
- count) != 0)
- gdbscm_memory_error (FUNC_NAME, _("error writing memory"),
- SCM_EOL);
+ if (target_write_memory (iomem->start + iomem->current, data, count) != 0)
+ gdbscm_memory_error (FUNC_NAME, _ ("error writing memory"), SCM_EOL);
iomem->current += count;
@@ -1119,9 +1117,8 @@ gdbscm_memory_port_seek (SCM port, scm_t_off offset, int whence)
rc = ioscm_lseek_address (iomem, offset, whence);
if (rc == 0)
- gdbscm_out_of_range_error (FUNC_NAME, 0,
- gdbscm_scm_from_longest (offset),
- _("bad seek"));
+ 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
@@ -1193,9 +1190,8 @@ ioscm_parse_mode_bits (const char *func_name, const char *mode)
if (*mode != 'r' && *mode != 'w')
{
- gdbscm_out_of_range_error (func_name, 0,
- gdbscm_scm_from_c_string (mode),
- _("bad mode string"));
+ gdbscm_out_of_range_error (func_name, 0, gdbscm_scm_from_c_string (mode),
+ _ ("bad mode string"));
}
for (p = mode + 1; *p != '\0'; ++p)
{
@@ -1208,7 +1204,7 @@ ioscm_parse_mode_bits (const char *func_name, const char *mode)
default:
gdbscm_out_of_range_error (func_name, 0,
gdbscm_scm_from_c_string (mode),
- _("bad mode string"));
+ _ ("bad mode string"));
}
}
@@ -1314,9 +1310,8 @@ ioscm_init_memory_port_buffers (SCM port)
static SCM
gdbscm_open_memory (SCM rest)
{
- const SCM keywords[] = {
- mode_keyword, start_keyword, size_keyword, SCM_BOOL_F
- };
+ const SCM keywords[]
+ = { mode_keyword, start_keyword, size_keyword, SCM_BOOL_F };
char *mode = NULL;
CORE_ADDR start = 0;
CORE_ADDR end;
@@ -1326,8 +1321,7 @@ gdbscm_open_memory (SCM rest)
long mode_bits;
gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "#sUU", rest,
- &mode_arg_pos, &mode,
- &start_arg_pos, &start,
+ &mode_arg_pos, &mode, &start_arg_pos, &start,
&size_arg_pos, &size);
scm_dynwind_begin ((scm_t_dynwind_flags) 0);
@@ -1342,10 +1336,11 @@ gdbscm_open_memory (SCM rest)
a nuisance we can relax things later. */
if (start + size < start)
{
- gdbscm_out_of_range_error (FUNC_NAME, 0,
- scm_list_2 (gdbscm_scm_from_ulongest (start),
- gdbscm_scm_from_ulongest (size)),
- _("start+size overflows"));
+ gdbscm_out_of_range_error (
+ FUNC_NAME, 0,
+ scm_list_2 (gdbscm_scm_from_ulongest (start),
+ gdbscm_scm_from_ulongest (size)),
+ _ ("start+size overflows"));
}
end = start + size;
}
@@ -1361,8 +1356,7 @@ gdbscm_open_memory (SCM rest)
mode_bits |= SCM_BUF0;
auto stream = ioscm_init_memory_port_stream (start, end);
- port = ioscm_open_port (memory_port_desc, mode_bits,
- (scm_t_bits) stream);
+ 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);
@@ -1440,7 +1434,7 @@ gdbscm_set_memory_port_read_buffer_size_x (SCM port, SCM size)
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"));
+ _ ("integer"));
if (!scm_is_unsigned_integer (size, min_memory_port_buf_size,
max_memory_port_buf_size))
@@ -1490,7 +1484,7 @@ gdbscm_set_memory_port_write_buffer_size_x (SCM port, SCM size)
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"));
+ _ ("integer"));
if (!scm_is_unsigned_integer (size, min_memory_port_buf_size,
max_memory_port_buf_size))
@@ -1508,73 +1502,60 @@ gdbscm_set_memory_port_write_buffer_size_x (SCM port, SCM size)
return scm_setvbuf (port, scm_from_utf8_symbol ("block"), size);
#endif
}
-
+
/* Initialize gdb ports. */
-static const scheme_function port_functions[] =
-{
- { "input-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_input_port),
- "\
+static const scheme_function port_functions[]
+ = { { "input-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_input_port), "\
Return gdb's input port." },
- { "output-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_output_port),
- "\
+ { "output-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_output_port), "\
Return gdb's output port." },
- { "error-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_error_port),
- "\
+ { "error-port", 0, 0, 0, as_a_scm_t_subr (gdbscm_error_port), "\
Return gdb's error port." },
- { "stdio-port?", 1, 0, 0, as_a_scm_t_subr (gdbscm_stdio_port_p),
- "\
+ { "stdio-port?", 1, 0, 0, as_a_scm_t_subr (gdbscm_stdio_port_p), "\
Return #t if the object is a gdb:stdio-port." },
- { "open-memory", 0, 0, 1, as_a_scm_t_subr (gdbscm_open_memory),
- "\
+ { "open-memory", 0, 0, 1, as_a_scm_t_subr (gdbscm_open_memory), "\
Return a port that can be used for reading/writing inferior memory.\n\
\n\
Arguments: [#:mode string] [#:start address] [#:size integer]\n\
Returns: A port object." },
- { "memory-port?", 1, 0, 0, as_a_scm_t_subr (gdbscm_memory_port_p),
- "\
+ { "memory-port?", 1, 0, 0, as_a_scm_t_subr (gdbscm_memory_port_p), "\
Return #t if the object is a memory port." },
- { "memory-port-range", 1, 0, 0, as_a_scm_t_subr (gdbscm_memory_port_range),
- "\
+ { "memory-port-range", 1, 0, 0,
+ as_a_scm_t_subr (gdbscm_memory_port_range), "\
Return the memory range of the port as (start end)." },
- { "memory-port-read-buffer-size", 1, 0, 0,
- as_a_scm_t_subr (gdbscm_memory_port_read_buffer_size),
- "\
+ { "memory-port-read-buffer-size", 1, 0, 0,
+ as_a_scm_t_subr (gdbscm_memory_port_read_buffer_size), "\
Return the size of the read buffer for the memory port." },
- { "set-memory-port-read-buffer-size!", 2, 0, 0,
- as_a_scm_t_subr (gdbscm_set_memory_port_read_buffer_size_x),
- "\
+ { "set-memory-port-read-buffer-size!", 2, 0, 0,
+ as_a_scm_t_subr (gdbscm_set_memory_port_read_buffer_size_x), "\
Set the size of the read buffer for the memory port.\n\
\n\
Arguments: port integer\n\
Returns: unspecified." },
- { "memory-port-write-buffer-size", 1, 0, 0,
- as_a_scm_t_subr (gdbscm_memory_port_write_buffer_size),
- "\
+ { "memory-port-write-buffer-size", 1, 0, 0,
+ as_a_scm_t_subr (gdbscm_memory_port_write_buffer_size), "\
Return the size of the write buffer for the memory port." },
- { "set-memory-port-write-buffer-size!", 2, 0, 0,
- as_a_scm_t_subr (gdbscm_set_memory_port_write_buffer_size_x),
- "\
+ { "set-memory-port-write-buffer-size!", 2, 0, 0,
+ as_a_scm_t_subr (gdbscm_set_memory_port_write_buffer_size_x), "\
Set the size of the write buffer for the memory port.\n\
\n\
Arguments: port integer\n\
Returns: unspecified." },
- END_FUNCTIONS
-};
+ END_FUNCTIONS };
-static const scheme_function private_port_functions[] =
-{
+static const scheme_function private_port_functions[] = {
#if 0 /* TODO */
{ "%with-gdb-input-from-port", 2, 0, 0,
as_a_scm_t_subr (gdbscm_percent_with_gdb_input_from_port),
@@ -1588,8 +1569,7 @@ This procedure is experimental." },
#endif
{ "%with-gdb-output-to-port", 2, 0, 0,
- as_a_scm_t_subr (gdbscm_percent_with_gdb_output_to_port),
- "\
+ as_a_scm_t_subr (gdbscm_percent_with_gdb_output_to_port), "\
Temporarily set GDB's output port to PORT and then invoke THUNK.\n\
\n\
Arguments: port thunk\n\
@@ -1598,8 +1578,7 @@ Temporarily set GDB's output port to PORT and then invoke THUNK.\n\
This procedure is experimental." },
{ "%with-gdb-error-to-port", 2, 0, 0,
- as_a_scm_t_subr (gdbscm_percent_with_gdb_error_to_port),
- "\
+ as_a_scm_t_subr (gdbscm_percent_with_gdb_error_to_port), "\
Temporarily set GDB's error port to PORT and then invoke THUNK.\n\
\n\
Arguments: port thunk\n\
@@ -1644,8 +1623,8 @@ gdbscm_initialize_ports (void)
#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);
+ out_of_range_buf_size
+ = xstrprintf ("size not between %u - %u", min_memory_port_buf_size,
+ max_memory_port_buf_size);
#endif
}