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.

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