i386.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: i386</title>
  16. <meta name="description" content="Debugging with GDB: i386">
  17. <meta name="keywords" content="Debugging with GDB: i386">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="Architectures.html#Architectures" rel="up" title="Architectures">
  26. <link href="Alpha.html#Alpha" rel="next" title="Alpha">
  27. <link href="AArch64.html#AArch64" rel="previous" title="AArch64">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="i386"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Alpha.html#Alpha" accesskey="n" rel="next">Alpha</a>, Previous: <a href="AArch64.html#AArch64" accesskey="p" rel="previous">AArch64</a>, Up: <a href="Architectures.html#Architectures" accesskey="u" rel="up">Architectures</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>
  62. </div>
  63. <hr>
  64. <a name="x86-Architecture_002dspecific-Issues"></a>
  65. <h4 class="subsection">21.4.2 x86 Architecture-specific Issues</h4>
  66. <dl compact="compact">
  67. <dt><code>set struct-convention <var>mode</var></code></dt>
  68. <dd><a name="index-set-struct_002dconvention"></a>
  69. <a name="index-struct-return-convention"></a>
  70. <a name="index-struct_002funion-returned-in-registers"></a>
  71. <p>Set the convention used by the inferior to return <code>struct</code>s and
  72. <code>union</code>s from functions to <var>mode</var>. Possible values of
  73. <var>mode</var> are <code>&quot;pcc&quot;</code>, <code>&quot;reg&quot;</code>, and <code>&quot;default&quot;</code> (the
  74. default). <code>&quot;default&quot;</code> or <code>&quot;pcc&quot;</code> means that <code>struct</code>s
  75. are returned on the stack, while <code>&quot;reg&quot;</code> means that a
  76. <code>struct</code> or a <code>union</code> whose size is 1, 2, 4, or 8 bytes will
  77. be returned in a register.
  78. </p>
  79. </dd>
  80. <dt><code>show struct-convention</code></dt>
  81. <dd><a name="index-show-struct_002dconvention"></a>
  82. <p>Show the current setting of the convention to return <code>struct</code>s
  83. from functions.
  84. </p></dd>
  85. </dl>
  86. <a name="Intel-Memory-Protection-Extensions-_0028MPX_0029_002e"></a>
  87. <h4 class="subsubsection">21.4.2.1 Intel <em>Memory Protection Extensions</em> (MPX).</h4>
  88. <a name="index-Intel-Memory-Protection-Extensions-_0028MPX_0029_002e"></a>
  89. <p>Memory Protection Extension (MPX) adds the bound registers &lsquo;<samp>BND0</samp>&rsquo;
  90. <a name="DOCF17" href="#FOOT17"><sup>17</sup></a> through &lsquo;<samp>BND3</samp>&rsquo;. Bound registers store a pair of 64-bit values
  91. which are the lower bound and upper bound. Bounds are effective addresses or
  92. memory locations. The upper bounds are architecturally represented in 1&rsquo;s
  93. complement form. A bound having lower bound = 0, and upper bound = 0
  94. (1&rsquo;s complement of all bits set) will allow access to the entire address space.
  95. </p>
  96. <p>&lsquo;<samp>BND0</samp>&rsquo; through &lsquo;<samp>BND3</samp>&rsquo; are represented in <small>GDB</small> as &lsquo;<samp>bnd0raw</samp>&rsquo;
  97. through &lsquo;<samp>bnd3raw</samp>&rsquo;. Pseudo registers &lsquo;<samp>bnd0</samp>&rsquo; through &lsquo;<samp>bnd3</samp>&rsquo;
  98. display the upper bound performing the complement of one operation on the
  99. upper bound value, i.e.&nbsp;when upper bound in &lsquo;<samp>bnd0raw</samp>&rsquo; is 0 in the
  100. <small>GDB</small> &lsquo;<samp>bnd0</samp>&rsquo; it will be <code>0xfff&hellip;</code>. In this sense it
  101. can also be noted that the upper bounds are inclusive.
  102. </p>
  103. <p>As an example, assume that the register BND0 holds bounds for a pointer having
  104. access allowed for the range between 0x32 and 0x71. The values present on
  105. bnd0raw and bnd registers are presented as follows:
  106. </p>
  107. <div class="smallexample">
  108. <pre class="smallexample"> bnd0raw = {0x32, 0xffffffff8e}
  109. bnd0 = {lbound = 0x32, ubound = 0x71} : size 64
  110. </pre></div>
  111. <p>This way the raw value can be accessed via bnd0raw&hellip;bnd3raw. Any
  112. change on bnd0&hellip;bnd3 or bnd0raw&hellip;bnd3raw is reflect on its
  113. counterpart. When the bnd0&hellip;bnd3 registers are displayed via
  114. Python, the display includes the memory size, in bits, accessible to
  115. the pointer.
  116. </p>
  117. <p>Bounds can also be stored in bounds tables, which are stored in
  118. application memory. These tables store bounds for pointers by specifying
  119. the bounds pointer&rsquo;s value along with its bounds. Evaluating and changing
  120. bounds located in bound tables is therefore interesting while investigating
  121. bugs on MPX context. <small>GDB</small> provides commands for this purpose:
  122. </p>
  123. <dl compact="compact">
  124. <dt><code>show mpx bound <var>pointer</var></code></dt>
  125. <dd><a name="index-show-mpx-bound"></a>
  126. <p>Display bounds of the given <var>pointer</var>.
  127. </p>
  128. </dd>
  129. <dt><code>set mpx bound <var>pointer</var>, <var>lbound</var>, <var>ubound</var></code></dt>
  130. <dd><a name="index-set-mpx-bound"></a>
  131. <p>Set the bounds of a pointer in the bound table.
  132. This command takes three parameters: <var>pointer</var> is the pointers
  133. whose bounds are to be changed, <var>lbound</var> and <var>ubound</var> are new values
  134. for lower and upper bounds respectively.
  135. </p></dd>
  136. </dl>
  137. <p>When you call an inferior function on an Intel MPX enabled program,
  138. GDB sets the inferior&rsquo;s bound registers to the init (disabled) state
  139. before calling the function. As a consequence, bounds checks for the
  140. pointer arguments passed to the function will always pass.
  141. </p>
  142. <p>This is necessary because when you call an inferior function, the
  143. program is usually in the middle of the execution of other function.
  144. Since at that point bound registers are in an arbitrary state, not
  145. clearing them would lead to random bound violations in the called
  146. function.
  147. </p>
  148. <p>You can still examine the influence of the bound registers on the
  149. execution of the called function by stopping the execution of the
  150. called function at its prologue, setting bound registers, and
  151. continuing the execution. For example:
  152. </p>
  153. <div class="smallexample">
  154. <pre class="smallexample"> $ break *upper
  155. Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
  156. $ print upper (a, b, c, d, 1)
  157. Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
  158. $ print $bnd0
  159. {lbound = 0x0, ubound = ffffffff} : size -1
  160. </pre></div>
  161. <p>At this last step the value of bnd0 can be changed for investigation of bound
  162. violations caused along the execution of the call. In order to know how to
  163. set the bound registers or bound table for the call consult the ABI.
  164. </p>
  165. <div class="footnote">
  166. <hr>
  167. <h4 class="footnotes-heading">Footnotes</h4>
  168. <h3><a name="FOOT17" href="#DOCF17">(17)</a></h3>
  169. <p>The register named with capital letters represent the architecture
  170. registers.</p>
  171. </div>
  172. <hr>
  173. <div class="header">
  174. <p>
  175. Next: <a href="Alpha.html#Alpha" accesskey="n" rel="next">Alpha</a>, Previous: <a href="AArch64.html#AArch64" accesskey="p" rel="previous">AArch64</a>, Up: <a href="Architectures.html#Architectures" accesskey="u" rel="up">Architectures</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>
  176. </div>
  177. </body>
  178. </html>