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-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Context management</title> 18 19<meta name="description" content="Debugging with GDB: Context management"> 20<meta name="keywords" content="Debugging with GDB: Context management"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="GDB_002fMI-General-Design.html#GDB_002fMI-General-Design" rel="up" title="GDB/MI General Design"> 29<link href="Asynchronous-and-non_002dstop-modes.html#Asynchronous-and-non_002dstop-modes" rel="next" title="Asynchronous and non-stop modes"> 30<link href="GDB_002fMI-General-Design.html#GDB_002fMI-General-Design" rel="previous" title="GDB/MI General Design"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Context-management"></a> 65<div class="header"> 66<p> 67Next: <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> [<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> 68</div> 69<hr> 70<a name="Context-Management"></a> 71<h4 class="subsection">27.1.1 Context Management</h4> 72 73<a name="Threads-and-Frames"></a> 74<h4 class="subsubsection">27.1.1.1 Threads and Frames</h4> 75 76<p>In most cases when <small>GDB</small> accesses the target, this access is 77done in context of a specific thread and frame (see <a href="Frames.html#Frames">Frames</a>). 78Often, even when accessing global data, the target requires that a thread 79be specified. The CLI interface maintains the selected thread and frame, 80and supplies them to target on each command. This is convenient, 81because a command line user would not want to specify that information 82explicitly on each command, and because user interacts with 83<small>GDB</small> via a single terminal, so no confusion is possible as 84to what thread and frame are the current ones. 85</p> 86<p>In the case of MI, the concept of selected thread and frame is less 87useful. First, a frontend can easily remember this information 88itself. Second, a graphical frontend can have more than one window, 89each one used for debugging a different thread, and the frontend might 90want to access additional threads for internal purposes. This 91increases the risk that by relying on implicitly selected thread, the 92frontend may be operating on a wrong one. Therefore, each MI command 93should explicitly specify which thread and frame to operate on. To 94make it possible, each MI command accepts the ‘<samp>--thread</samp>’ and 95‘<samp>--frame</samp>’ options, the value to each is <small>GDB</small> global 96identifier for thread and frame to operate on. 97</p> 98<p>Usually, each top-level window in a frontend allows the user to select 99a thread and a frame, and remembers the user selection for further 100operations. However, in some cases <small>GDB</small> may suggest that the 101current thread or frame be changed. For example, when stopping on a 102breakpoint it is reasonable to switch to the thread where breakpoint is 103hit. For another example, if the user issues the CLI ‘<samp>thread</samp>’ or 104‘<samp>frame</samp>’ commands via the frontend, it is desirable to change the 105frontend’s selection to the one specified by user. <small>GDB</small> 106communicates the suggestion to change current thread and frame using the 107‘<samp>=thread-selected</samp>’ notification. 108</p> 109<p>Note that historically, MI shares the selected thread with CLI, so 110frontends used the <code>-thread-select</code> to execute commands in the 111right context. However, getting this to work right is cumbersome. The 112simplest way is for frontend to emit <code>-thread-select</code> command 113before every command. This doubles the number of commands that need 114to be sent. The alternative approach is to suppress <code>-thread-select</code> 115if the selected thread in <small>GDB</small> is supposed to be identical to the 116thread the frontend wants to operate on. However, getting this 117optimization right can be tricky. In particular, if the frontend 118sends several commands to <small>GDB</small>, and one of the commands changes the 119selected thread, then the behaviour of subsequent commands will 120change. So, a frontend should either wait for response from such 121problematic commands, or explicitly add <code>-thread-select</code> for 122all subsequent commands. No frontend is known to do this exactly 123right, so it is suggested to just always pass the ‘<samp>--thread</samp>’ and 124‘<samp>--frame</samp>’ options. 125</p> 126<a name="Language"></a> 127<h4 class="subsubsection">27.1.1.2 Language</h4> 128 129<p>The execution of several commands depends on which language is selected. 130By default, the current language (see <a href="Show.html#show-language">show language</a>) is used. 131But for commands known to be language-sensitive, it is recommended 132to use the ‘<samp>--language</samp>’ option. This option takes one argument, 133which is the name of the language to use while executing the command. 134For instance: 135</p> 136<div class="smallexample"> 137<pre class="smallexample">-data-evaluate-expression --language c "sizeof (void*)" 138^done,value="4" 139(gdb) 140</pre></div> 141 142<p>The valid language names are the same names accepted by the 143‘<samp>set language</samp>’ command (see <a href="Manually.html#Manually">Manually</a>), excluding ‘<samp>auto</samp>’, 144‘<samp>local</samp>’ or ‘<samp>unknown</samp>’. 145</p> 146<hr> 147<div class="header"> 148<p> 149Next: <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> [<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> 150</div> 151 152 153 154</body> 155</html> 156