Context-management.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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-2019 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.2, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Context management</title>
  16. <meta name="description" content="Debugging with GDB: Context management">
  17. <meta name="keywords" content="Debugging with GDB: Context management">
  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="GDB_002fMI-General-Design.html#GDB_002fMI-General-Design" rel="up" title="GDB/MI General Design">
  26. <link href="Asynchronous-and-non_002dstop-modes.html#Asynchronous-and-non_002dstop-modes" rel="next" title="Asynchronous and non-stop modes">
  27. <link href="GDB_002fMI-General-Design.html#GDB_002fMI-General-Design" rel="prev" title="GDB/MI General Design">
  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="Context-management"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Asynchronous-and-non_002dstop-modes.html#Asynchronous-and-non_002dstop-modes" accesskey="n" rel="next">Asynchronous and non-stop modes</a>, Up: <a href="GDB_002fMI-General-Design.html#GDB_002fMI-General-Design" accesskey="u" rel="up">GDB/MI General Design</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="Context-management-1"></a>
  65. <h4 class="subsection">27.1.1 Context management</h4>
  66. <a name="Threads-and-Frames"></a>
  67. <h4 class="subsubsection">27.1.1.1 Threads and Frames</h4>
  68. <p>In most cases when <small>GDB</small> accesses the target, this access is
  69. done in context of a specific thread and frame (see <a href="Frames.html#Frames">Frames</a>).
  70. Often, even when accessing global data, the target requires that a thread
  71. be specified. The CLI interface maintains the selected thread and frame,
  72. and supplies them to target on each command. This is convenient,
  73. because a command line user would not want to specify that information
  74. explicitly on each command, and because user interacts with
  75. <small>GDB</small> via a single terminal, so no confusion is possible as
  76. to what thread and frame are the current ones.
  77. </p>
  78. <p>In the case of MI, the concept of selected thread and frame is less
  79. useful. First, a frontend can easily remember this information
  80. itself. Second, a graphical frontend can have more than one window,
  81. each one used for debugging a different thread, and the frontend might
  82. want to access additional threads for internal purposes. This
  83. increases the risk that by relying on implicitly selected thread, the
  84. frontend may be operating on a wrong one. Therefore, each MI command
  85. should explicitly specify which thread and frame to operate on. To
  86. make it possible, each MI command accepts the &lsquo;<samp>--thread</samp>&rsquo; and
  87. &lsquo;<samp>--frame</samp>&rsquo; options, the value to each is <small>GDB</small> global
  88. identifier for thread and frame to operate on.
  89. </p>
  90. <p>Usually, each top-level window in a frontend allows the user to select
  91. a thread and a frame, and remembers the user selection for further
  92. operations. However, in some cases <small>GDB</small> may suggest that the
  93. current thread or frame be changed. For example, when stopping on a
  94. breakpoint it is reasonable to switch to the thread where breakpoint is
  95. hit. For another example, if the user issues the CLI &lsquo;<samp>thread</samp>&rsquo; or
  96. &lsquo;<samp>frame</samp>&rsquo; commands via the frontend, it is desirable to change the
  97. frontend&rsquo;s selection to the one specified by user. <small>GDB</small>
  98. communicates the suggestion to change current thread and frame using the
  99. &lsquo;<samp>=thread-selected</samp>&rsquo; notification.
  100. </p>
  101. <p>Note that historically, MI shares the selected thread with CLI, so
  102. frontends used the <code>-thread-select</code> to execute commands in the
  103. right context. However, getting this to work right is cumbersome. The
  104. simplest way is for frontend to emit <code>-thread-select</code> command
  105. before every command. This doubles the number of commands that need
  106. to be sent. The alternative approach is to suppress <code>-thread-select</code>
  107. if the selected thread in <small>GDB</small> is supposed to be identical to the
  108. thread the frontend wants to operate on. However, getting this
  109. optimization right can be tricky. In particular, if the frontend
  110. sends several commands to <small>GDB</small>, and one of the commands changes the
  111. selected thread, then the behaviour of subsequent commands will
  112. change. So, a frontend should either wait for response from such
  113. problematic commands, or explicitly add <code>-thread-select</code> for
  114. all subsequent commands. No frontend is known to do this exactly
  115. right, so it is suggested to just always pass the &lsquo;<samp>--thread</samp>&rsquo; and
  116. &lsquo;<samp>--frame</samp>&rsquo; options.
  117. </p>
  118. <a name="Language"></a>
  119. <h4 class="subsubsection">27.1.1.2 Language</h4>
  120. <p>The execution of several commands depends on which language is selected.
  121. By default, the current language (see <a href="Show.html#show-language">show language</a>) is used.
  122. But for commands known to be language-sensitive, it is recommended
  123. to use the &lsquo;<samp>--language</samp>&rsquo; option. This option takes one argument,
  124. which is the name of the language to use while executing the command.
  125. For instance:
  126. </p>
  127. <div class="smallexample">
  128. <pre class="smallexample">-data-evaluate-expression --language c &quot;sizeof (void*)&quot;
  129. ^done,value=&quot;4&quot;
  130. (gdb)
  131. </pre></div>
  132. <p>The valid language names are the same names accepted by the
  133. &lsquo;<samp>set language</samp>&rsquo; command (see <a href="Manually.html#Manually">Manually</a>), excluding &lsquo;<samp>auto</samp>&rsquo;,
  134. &lsquo;<samp>local</samp>&rsquo; or &lsquo;<samp>unknown</samp>&rsquo;.
  135. </p>
  136. <hr>
  137. <div class="header">
  138. <p>
  139. Next: <a href="Asynchronous-and-non_002dstop-modes.html#Asynchronous-and-non_002dstop-modes" accesskey="n" rel="next">Asynchronous and non-stop modes</a>, Up: <a href="GDB_002fMI-General-Design.html#GDB_002fMI-General-Design" accesskey="u" rel="up">GDB/MI General Design</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>
  140. </div>
  141. </body>
  142. </html>