⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-debugger7.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<dd><pre class="Code3"><b><a name="85518"></b><tt class="output">    evaluate: </tt><b><i class="textVariable">expression</i> </a></b></pre></dl><dd><div class="Indent"><a name="85519"> </a>If an expression does not evaluate to an object that can be cast to pointer type, an error message is printed, and <b class="tclProc">gdbEvalScalar</b> signals a Tcl error, which unwinds the Tcl stack if not caught (see <a href="x-tclsumm2.html#84341"><i class="title">B.2.9&nbsp;Tcl Error Handling</i></a> for information about unwinding).</div><br></dl><dd><div class="Item"><a name="85524"> </a><b class="tclProc">gdbFileAddrInfo</b> <i class="textVariable">fileName</i> </div><dl class="margin"><dd><div class="Indent"><a name="85525"> </a>Returns a Tcl list with four elements: the first source line number of <i class="textVariable">fileName</i> that corresponds to generated object code, the last such line number, the lowest object-code address from <i class="textVariable">fileName</i> in the target, and the highest object-code address from <i class="textVariable">fileName</i> in the target. The argument <i class="textVariable">fileName</i> must be the source file (<b class="file">.c</b>, not <b class="file">.o</b>) corresponding to code loaded in the target and in the debugger.</div><br><dd><div class="Indent"><a name="92589"> </a>For example:</div><br><dl class="margin"><dd><pre class="Code3"><b><a name="92590">    </b><tt class="output">(gdb) </tt><b>tcl gdbFileAddrInfo vxColor.c </b><tt class="output">    {239 1058 0x39e2d0 0x39fbfc}</tt><b></a></b></pre></dl></dl><dd><div class="Item"><a name="92592"> </a><b class="tclProc">gdbFileLineInfo</b> <i class="textVariable">fileName</i> </div><dl class="margin"><dd><div class="Indent"><a name="85530"> </a>Returns a Tcl list with as many elements as there are source lines of <i class="textVariable">fileName</i> that correspond to generated object code. Each element of the list is itself a list with three elements: the source-file line number, the beginning address of object code for that line, and the ending address of object code for that line. The argument <i class="textVariable">fileName</i> must be the source file (<b class="file">.c</b>, not <b class="file">.o</b>) of a file corresponding to code loaded in the target and in the debugger.</div><br><dd><div class="Indent"><a name="85531"> </a>For example:</div><br><dl class="margin"><dd><pre class="Code3"><b><a name="85532"></b><tt class="output">    (gdb) </tt><b>tcl gdbFileLineInfo vxColor.c  </b><tt class="output">    {239 0x39e2d0 0x39e2d4} {244 0x39e2d4 0x39e2ec} ...</tt><b></a></b></pre></dl></dl><dd><div class="Item"><a name="85534"> </a><b class="tclProc">gdbIORedirect </b><i class="textVariable">inFile</i><b class="tclProc"> </b><i class="textVariable">outFile</i> [ <i class="textVariable">taskId</i> ] </div><dl class="margin"><dd><div class="Indent"><a name="85535"> </a>Redirects target input to file or device <i class="textVariable">inFile</i>, and target output and error streams to file or device <i class="textVariable">outFile</i>. If <i class="textVariable">taskId</i> is specified, redirect input and output only for that task; otherwise, redirect global input and output. To leave either input or output unchanged, specify the corresponding argument as a dash (<b class="operator">-</b>). Input may only be redirected to target files or devices; output may be redirected either to host files or to target files or devices. Ordinary path names indicate host files; arguments with an <b class="operator">@</b> prefix indicate target files or devices. For target files, you may specify either a path name or a numeric file descriptor.</div><br><dd><div class="Indent"><a name="85536"> </a>For example, the following command redirects all target output (including <b class="symbol_lc">stderr</b>) to host file <b class="file">grab.it</b>:</div><br><dl class="margin"><dd><pre class="Code3"><b><a name="85537"></b><tt class="output">    (gdb) </tt><b>tcl gdbIORedirect - grab.it</a></b></pre></dl></dl><dd><div class="Item"><a name="85539"> </a><b class="tclProc">gdbIOClose</b> </div><dl class="margin"><dd><div class="Indent"><a name="87869"> </a>Closes all file descriptors opened on the host by the most recent <b class="tclProc">gdbIoRedirect</b> call.</div><br></dl><dd><div class="Item"><a name="87871"> </a><b class="tclProc">gdbLocalsTags</b> </div><dl class="margin"><dd><div class="Indent"><a name="86155"> </a>Returns a list of names of local symbols for the current stack frame.</div><br></dl><dd><div class="Item"><a name="85543"> </a><b class="tclProc">gdbStackFrameTags</b> </div><dl class="margin"><dd><div class="Indent"><a name="85544"> </a>Returns a list of names of the routines currently on the stack.</div><br></dl><dd><div class="Item"><a name="85547"> </a><b class="tclProc">gdbSymbol</b> <i class="textVariable">integer</i> </div><dl class="margin"><dd><div class="Indent"><a name="86160"> </a>Translates <i class="textVariable">integer</i>, interpreted as a target address, into an offset from the nearest target symbol. The display has the following format:</div><br><dl class="margin"><dd><pre class="Code3"><b><a name="85549">    <i class="textVariable">symbolName</i> [ <i class="i">+</i> <i class="textVariable">Offset</i> ]</a></b></pre></dl><dd><div class="Indent"><a name="85550"> </a><i class="textVariable">Offset</i> is a decimal integer. If <i class="textVariable">Offset</i> is zero, it is not printed. For example:</div><br><dl class="margin"><dd><pre class="Code3"><b><a name="85551"></b><tt class="output">    (gdb) </tt><b>tcl puts stdout [gdbSymbol 0x20000] </b><tt class="output">    floatInit+2276</tt><b></a></b></pre></dl><dd><div class="Indent"><a name="85552"> </a>If Tcl debugging is on, <b class="tclProc">gdbSymbol</b> prints the following message:</div><br><dl class="margin"><dd><pre class="Code3"><b><a name="85553">    </b><tt class="output">symbol:</tt><b> <i class="textVariable">value</i> </a></b></pre></dl></dl><dd><div class="Item"><a name="85555"> </a><b class="tclProc">gdbSymbolExists</b> <i class="textVariable">symbolName</i>  </div><dl class="margin"><dd><div class="Indent"><a name="85556"> </a>Returns 1 if the specified symbol exists in any loaded symbol table, or 0 if not. You can use this command to test for the presence of a symbol without generating error messages from GDB if the symbol does not exist. This procedure cannot signal a Tcl error.</div><br><dd><div class="Indent"><a name="85557"> </a>When Tcl debugging is on, <b class="tclProc">gdbSymbolExists</b> prints a message like the following:</div><br><dl class="margin"><dd><pre class="Code3"><b><a name="85560"></b><tt class="output">    symbol exists:</tt><b> <i class="textVariable">symbolName</i> </a></b></pre></dl></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85561">8.7.4  &nbsp;&nbsp;Tcl: A Linked-List Traversal Macro Example</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85563"> </a>This section shows a Tcl procedure to traverse a linked list, printing information about each node.<sup><a href="#foot"><b class="FootnoteMarker">2</b></a></sup> The example is tailored to a list where each node has the following structure:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85573">    struct node         {         int data;         struct node *next;         }</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85574"> </a>A common method of list traversal in C is a <b class="keyword">for</b> loop like the following:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85575">    for (pNode = pHead; pNode; pNode = pNode-&gt;next)     ...</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85576"> </a>We imitate this code in Tcl, with the important difference that all Tcl data is in strings, not pointers.</p><dd><p class="Body"><a name="85577"> </a>The argument to the Tcl procedure will be an expression (called <b class="symbol_lc">head</b> in our procedure) representing the first node of the list. </p><dd><p class="Body"><a name="85578"> </a>Use <b class="tclProc">gdbEvalScalar</b> to convert the GDB expression for a pointer into a Tcl string:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85579">    set pNode [gdbEvalScalar "$head"]</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85580"> </a>To get the pointer to the next element in the list:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85581">    set pNode [gdbEvalScalar "( (struct node *) $pNode)-&gt;next"]</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85582"> </a>Putting these lines together into a Tcl <b class="tclProc">for</b> loop, the procedure (in a form suitable for a Tcl script file) looks like the following:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85583">    proc traverse head {          for {set pNode [gdbEvalScalar "$head"] }&nbsp;&nbsp;\             {$pNode}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\             {set pNode [gdbEvalScalar "( (struct node *)$pNode)-&gt;next"]}&nbsp;&nbsp;&nbsp;\                 {puts stdout $pNode}      }</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85584"> </a>In the body of the loop, the Tcl command <b class="tclProc">puts</b> prints the address of the node. </p><dd><p class="Body"><a name="85585"> </a>To type the procedure directly into the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Debugger</font></b> window would require prefacing the text above with the <b class="command">tcl</b> command, and would require a backslash at the end of every line. </p><dd><p class="Body"><a name="85586"> </a>If <b class="symbol_lc">pList</b> is a variable of type <b class="keyword">(struct *node)</b>, you can execute:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85587"></b><tt class="output">(gdb)</tt><b> tcl traverse pList</a></b></pre></dl><dd><p class="Body"><a name="85588"> </a>The procedure displays the address of each node in the list. For a list with two elements, the output would look something like the following:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85589"></b><tt class="output">0xffeb00 0xffea2c</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85590"> </a>It might be more useful to redefine the procedure body to print out the integer member <b class="symbol_lc">data</b>, instead. For example, replace the last line with the following:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85591">    {puts stdout [format "data = %d"&nbsp;&nbsp;\         [gdbEvalScalar "((struct node *) $pNode)-&gt;data"]]}</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85592"> </a>You can bind a new GDB command to this Tcl procedure by using <b class="command">tclproc</b> (typically, in the same Tcl script file as the procedure definition):</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85593">    tclproc traverse traverse</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85594"> </a>The <b class="command">traverse</b> command can be abbreviated, like any GDB command. With these definitions, you can type the following command:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85595"></b><tt class="output">(gdb) </tt><b>trav pList</a></b></pre></dl><dd><p class="Body"><a name="85596"> </a>The output now exhibits the contents of each node in the list:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85597"></b><tt class="output">data = 1 data = 2</tt><b></a></b></pre></dl></dl></dl><a name="foot"><hr></a><p class="FootnoteNumberMarker">1:&nbsp;<span class="Footnote"><a name="85516"> </a>A more restricted form of this command, called <b>gdbEvalAddress</b>, can only evaluate a single expression (constructed by concatenating all its arguments). <b>gdbEvalAddress</b> is only supported to provide compatibility with Tcl debugger extensions written for an older debugger, VxGDB. Use the more general <b>gdbEvalScalar</b> in new Tcl extensions.</span><p class="FootnoteNumberMarker">2:&nbsp;<span class="Footnote"><a name="85566"> </a>Keep in mind that for interactive exploration of a list the window (<a href="c-debugger3.html#91728">Figure&nbsp;8-14</a>) described in <a href="c-debugger3.html#94052"><i class="title">Watch Window</i></a> is probably more convenient.</span><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-debugger.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-debugger6.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-debugger8.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc.    conversion tool:  Quadralay WebWorks Publisher 4.0.11    template:         CSS Template, Jan 1998 - Jefro --->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -