You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
9.1KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Memory Ports in Guile (Debugging with GDB)</title>
  17. <meta name="description" content="Memory Ports in Guile (Debugging with GDB)">
  18. <meta name="keywords" content="Memory Ports in Guile (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Guile-API.html#Guile-API" rel="up" title="Guile API">
  26. <link href="Iterators-In-Guile.html#Iterators-In-Guile" rel="next" title="Iterators In Guile">
  27. <link href="I_002fO-Ports-in-Guile.html#I_002fO-Ports-in-Guile" rel="prev" title="I/O Ports in Guile">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style: oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Memory-Ports-in-Guile"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Iterators-In-Guile.html#Iterators-In-Guile" accesskey="n" rel="next">Iterators In Guile</a>, Previous: <a href="I_002fO-Ports-in-Guile.html#I_002fO-Ports-in-Guile" accesskey="p" rel="prev">I/O Ports in Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="Memory-Ports-in-Guile-1"></a>
  64. <h4 class="subsubsection">23.3.3.24 Memory Ports in Guile</h4>
  65. <p><small>GDB</small> provides a <code>port</code> interface to target memory.
  66. This allows Guile code to read/write target memory using Guile&rsquo;s port and
  67. bytevector functionality. The main routine is <code>open-memory</code> which
  68. returns a port object. One can then read/write memory using that object.
  69. </p>
  70. <dl>
  71. <dt><a name="index-open_002dmemory"></a>Scheme Procedure: <strong>open-memory</strong> <em><span class="roman">[</span>#:mode mode] <span class="roman">[</span>#:start address] <span class="roman">[</span>#:size size]</em></dt>
  72. <dd><p>Return a port object that can be used for reading and writing memory.
  73. The port will be open according to <var>mode</var>, which is the standard
  74. mode argument to Guile port open routines, except that the &lsquo;<samp>&quot;a&quot;</samp>&rsquo;
  75. and &lsquo;<samp>&quot;l&quot;</samp>&rsquo; modes are not supported.
  76. See <a href="http://www.gnu.org/software/guile/manual/html_node/File-Ports.html#File-Ports">File Ports</a> in <cite>GNU Guile Reference Manual</cite>.
  77. The &lsquo;<samp>&quot;b&quot;</samp>&rsquo; (binary) character may be present, but is ignored:
  78. memory ports are binary only. If &lsquo;<samp>&quot;0&quot;</samp>&rsquo; is appended then
  79. the port is marked as unbuffered.
  80. The default is &lsquo;<samp>&quot;r&quot;</samp>&rsquo;, read-only and buffered.
  81. </p>
  82. <p>The chunk of memory that can be accessed can be bounded.
  83. If both <var>start</var> and <var>size</var> are unspecified, all of memory can be
  84. accessed. If only <var>start</var> is specified, all of memory from that point
  85. on can be accessed. If only <var>size</var> if specified, all memory in the
  86. range [0,<var>size</var>) can be accessed. If both are specified, all memory
  87. in the rane [<var>start</var>,<var>start</var>+<var>size</var>) can be accessed.
  88. </p></dd></dl>
  89. <dl>
  90. <dt><a name="index-memory_002dport_003f"></a>Scheme Procedure: <strong>memory-port?</strong></dt>
  91. <dd><p>Return <code>#t</code> if <var>object</var> is an object of type <code>&lt;gdb:memory-port&gt;</code>.
  92. Otherwise return <code>#f</code>.
  93. </p></dd></dl>
  94. <dl>
  95. <dt><a name="index-memory_002dport_002drange"></a>Scheme Procedure: <strong>memory-port-range</strong> <em>memory-port</em></dt>
  96. <dd><p>Return the range of <code>&lt;gdb:memory-port&gt;</code> <var>memory-port</var> as a list
  97. of two elements: <code>(start end)</code>. The range is <var>start</var> to <var>end</var>
  98. inclusive.
  99. </p></dd></dl>
  100. <dl>
  101. <dt><a name="index-memory_002dport_002dread_002dbuffer_002dsize"></a>Scheme Procedure: <strong>memory-port-read-buffer-size</strong> <em>memory-port</em></dt>
  102. <dd><p>Return the size of the read buffer of <code>&lt;gdb:memory-port&gt;</code>
  103. <var>memory-port</var>.
  104. </p>
  105. <p>This procedure is deprecated and will be removed in <small>GDB</small> 11.
  106. It returns 0 when using Guile 2.2 or later.
  107. </p></dd></dl>
  108. <dl>
  109. <dt><a name="index-set_002dmemory_002dport_002dread_002dbuffer_002dsize_0021"></a>Scheme Procedure: <strong>set-memory-port-read-buffer-size!</strong> <em>memory-port size</em></dt>
  110. <dd><p>Set the size of the read buffer of <code>&lt;gdb:memory-port&gt;</code>
  111. <var>memory-port</var> to <var>size</var>. The result is unspecified.
  112. </p>
  113. <p>This procedure is deprecated and will be removed in <small>GDB</small> 11.
  114. When <small>GDB</small> is built with Guile 2.2 or later, you can call
  115. <code>setvbuf</code> instead (see <a href="http://www.gnu.org/software/guile/manual/html_node/Buffering.html#Buffering"><code>setvbuf</code></a> in <cite>GNU
  116. Guile Reference Manual</cite>).
  117. </p></dd></dl>
  118. <dl>
  119. <dt><a name="index-memory_002dport_002dwrite_002dbuffer_002dsize"></a>Scheme Procedure: <strong>memory-port-write-buffer-size</strong> <em>memory-port</em></dt>
  120. <dd><p>Return the size of the write buffer of <code>&lt;gdb:memory-port&gt;</code>
  121. <var>memory-port</var>.
  122. </p>
  123. <p>This procedure is deprecated and will be removed in <small>GDB</small> 11.
  124. It returns 0 when <small>GDB</small> is built with Guile 2.2 or later.
  125. </p></dd></dl>
  126. <dl>
  127. <dt><a name="index-set_002dmemory_002dport_002dwrite_002dbuffer_002dsize_0021"></a>Scheme Procedure: <strong>set-memory-port-write-buffer-size!</strong> <em>memory-port size</em></dt>
  128. <dd><p>Set the size of the write buffer of <code>&lt;gdb:memory-port&gt;</code>
  129. <var>memory-port</var> to <var>size</var>. The result is unspecified.
  130. </p>
  131. <p>This procedure is deprecated and will be removed in <small>GDB</small> 11.
  132. When <small>GDB</small> is built with Guile 2.2 or later, you can call
  133. <code>setvbuf</code> instead.
  134. </p></dd></dl>
  135. <p>A memory port is closed like any other port, with <code>close-port</code>.
  136. </p>
  137. <p>Combined with Guile&rsquo;s <code>bytevectors</code>, memory ports provide a lot
  138. of utility. For example, to fill a buffer of 10 integers in memory,
  139. one can do something like the following.
  140. </p>
  141. <div class="smallexample">
  142. <pre class="smallexample">;; In the program: int buffer[10];
  143. (use-modules (rnrs bytevectors))
  144. (use-modules (rnrs io ports))
  145. (define addr (parse-and-eval &quot;buffer&quot;))
  146. (define n 10)
  147. (define byte-size (* n 4))
  148. (define mem-port (open-memory #:mode &quot;r+&quot; #:start
  149. (value-&gt;integer addr) #:size byte-size))
  150. (define byte-vec (make-bytevector byte-size))
  151. (do ((i 0 (+ i 1)))
  152. ((&gt;= i n))
  153. (bytevector-s32-native-set! byte-vec (* i 4) (* i 42)))
  154. (put-bytevector mem-port byte-vec)
  155. (close-port mem-port)
  156. </pre></div>
  157. <hr>
  158. <div class="header">
  159. <p>
  160. Next: <a href="Iterators-In-Guile.html#Iterators-In-Guile" accesskey="n" rel="next">Iterators In Guile</a>, Previous: <a href="I_002fO-Ports-in-Guile.html#I_002fO-Ports-in-Guile" accesskey="p" rel="prev">I/O Ports in Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  161. </div>
  162. </body>
  163. </html>