| <html lang="en"> |
| <head> |
| <title>Memory Ports in Guile - Debugging with GDB</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="Debugging with GDB"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Guile-API.html#Guile-API" title="Guile API"> |
| <link rel="prev" href="I_002fO-Ports-in-Guile.html#I_002fO-Ports-in-Guile" title="I/O Ports in Guile"> |
| <link rel="next" href="Iterators-In-Guile.html#Iterators-In-Guile" title="Iterators In Guile"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| Copyright (C) 1988-2019 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Free Software'' and ``Free Software Needs |
| Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' |
| and with the Back-Cover Texts as in (a) below. |
| |
| (a) The FSF's Back-Cover Text is: ``You are free to copy and modify |
| this GNU Manual. Buying copies from GNU Press supports the FSF in |
| developing GNU and promoting software freedom.'' |
| --> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Memory-Ports-in-Guile"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="Iterators-In-Guile.html#Iterators-In-Guile">Iterators In Guile</a>, |
| Previous: <a rel="previous" accesskey="p" href="I_002fO-Ports-in-Guile.html#I_002fO-Ports-in-Guile">I/O Ports in Guile</a>, |
| Up: <a rel="up" accesskey="u" href="Guile-API.html#Guile-API">Guile API</a> |
| <hr> |
| </div> |
| |
| <h5 class="subsubsection">23.3.3.24 Memory Ports in Guile</h5> |
| |
| <p><span class="sc">gdb</span> provides a <code>port</code> interface to target memory. |
| This allows Guile code to read/write target memory using Guile's port and |
| bytevector functionality. The main routine is <code>open-memory</code> which |
| returns a port object. One can then read/write memory using that object. |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>open-memory</b> <span class="roman">[</span><var>#:mode mode</var>] <span class="roman">[</span><var>#:start address</var>] <span class="roman">[</span><var>#:size size</var>]<var><a name="index-open_002dmemory-2848"></a></var><br> |
| <blockquote><p>Return a port object that can be used for reading and writing memory. |
| The port will be open according to <var>mode</var>, which is the standard |
| mode argument to Guile port open routines, except that the ‘<samp><span class="samp">"a"</span></samp>’ |
| and ‘<samp><span class="samp">"l"</span></samp>’ modes are not supported. |
| See <a href="../guile/File-Ports.html#File-Ports">File Ports</a>. |
| The ‘<samp><span class="samp">"b"</span></samp>’ (binary) character may be present, but is ignored: |
| memory ports are binary only. If ‘<samp><span class="samp">"0"</span></samp>’ is appended then |
| the port is marked as unbuffered. |
| The default is ‘<samp><span class="samp">"r"</span></samp>’, read-only and buffered. |
| |
| <p>The chunk of memory that can be accessed can be bounded. |
| If both <var>start</var> and <var>size</var> are unspecified, all of memory can be |
| accessed. If only <var>start</var> is specified, all of memory from that point |
| on can be accessed. If only <var>size</var> if specified, all memory in the |
| range [0,<var>size</var>) can be accessed. If both are specified, all memory |
| in the rane [<var>start</var>,<var>start</var>+<var>size</var>) can be accessed. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>memory-port?</b><var><a name="index-memory_002dport_003f-2849"></a></var><br> |
| <blockquote><p>Return <code>#t</code> if <var>object</var> is an object of type <code><gdb:memory-port></code>. |
| Otherwise return <code>#f</code>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>memory-port-range</b><var> memory-port<a name="index-memory_002dport_002drange-2850"></a></var><br> |
| <blockquote><p>Return the range of <code><gdb:memory-port></code> <var>memory-port</var> as a list |
| of two elements: <code>(start end)</code>. The range is <var>start</var> to <var>end</var> |
| inclusive. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>memory-port-read-buffer-size</b><var> memory-port<a name="index-memory_002dport_002dread_002dbuffer_002dsize-2851"></a></var><br> |
| <blockquote><p>Return the size of the read buffer of <code><gdb:memory-port></code> |
| <var>memory-port</var>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>set-memory-port-read-buffer-size!</b><var> memory-port size<a name="index-set_002dmemory_002dport_002dread_002dbuffer_002dsize_0021-2852"></a></var><br> |
| <blockquote><p>Set the size of the read buffer of <code><gdb:memory-port></code> |
| <var>memory-port</var> to <var>size</var>. The result is unspecified. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>memory-port-write-buffer-size</b><var> memory-port<a name="index-memory_002dport_002dwrite_002dbuffer_002dsize-2853"></a></var><br> |
| <blockquote><p>Return the size of the write buffer of <code><gdb:memory-port></code> |
| <var>memory-port</var>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>set-memory-port-write-buffer-size!</b><var> memory-port size<a name="index-set_002dmemory_002dport_002dwrite_002dbuffer_002dsize_0021-2854"></a></var><br> |
| <blockquote><p>Set the size of the write buffer of <code><gdb:memory-port></code> |
| <var>memory-port</var> to <var>size</var>. The result is unspecified. |
| </p></blockquote></div> |
| |
| <p>A memory port is closed like any other port, with <code>close-port</code>. |
| |
| <p>Combined with Guile's <code>bytevectors</code>, memory ports provide a lot |
| of utility. For example, to fill a buffer of 10 integers in memory, |
| one can do something like the following. |
| |
| <pre class="smallexample"> ;; In the program: int buffer[10]; |
| (use-modules (rnrs bytevectors)) |
| (use-modules (rnrs io ports)) |
| (define addr (parse-and-eval "buffer")) |
| (define n 10) |
| (define byte-size (* n 4)) |
| (define mem-port (open-memory #:mode "r+" #:start |
| (value->integer addr) #:size byte-size)) |
| (define byte-vec (make-bytevector byte-size)) |
| (do ((i 0 (+ i 1))) |
| ((>= i n)) |
| (bytevector-s32-native-set! byte-vec (* i 4) (* i 42))) |
| (put-bytevector mem-port byte-vec) |
| (close-port mem-port) |
| </pre> |
| </body></html> |
| |