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

📄 c-shell3.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="85124"> </a></div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="85126"> </a></div></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="85128"> </a></div></td><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p> </p><dd><p class="Body"><a name="85144"> </a>The shell assigns the same precedence to the operators as the C compiler. However, unlike the C compiler, the shell always evaluates both sub-expressions of the logical binary operators <b class="operator">||</b> and <b class="operator">&amp;&amp;</b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85146">Function Calls</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85148"> </a>Shell expressions may contain calls to C functions (or C-compatible functions) whose names have been entered in the system symbol table; they may also contain function calls to WindSh commands that execute on the host.</p><dd><p class="Body"><a name="85149"> </a>The shell executes such function calls in tasks spawned for the purpose, with the specified arguments and default task parameters; if the task parameters make a difference, you can call <b class="routine"><i class="routine">taskSpawn</i></b><b>(&nbsp;)</b> instead of calling functions from the shell directly. The value of a function call is the 4-byte integer value returned by the function. The shell assumes that all functions return integers. If a function returns a value other than an integer, the shell must know the data type being returned before the function is invoked. This requires a slightly unusual syntax because you must cast the function, not its return value. For example:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85151"></b><tt class="output">-&gt; </tt><b>floatVar = ( float ()) funcThatReturnsAFloat (x,y)</a></b></pre></dl><dd><p class="Body"><a name="85153"> </a>The shell can pass up to ten arguments to a function. In fact, the shell always passes exactly ten arguments to every function called, passing values of zero for any arguments not specified. This is harmless because the C function-call protocol handles passing of variable numbers of arguments. However, it allows you to omit trailing arguments of value zero from function calls in shell expressions.</p><dd><p class="Body"><a name="85155"> </a>Function calls can be nested. That is, a function call can be an argument to another function call. In the following example, <b class="routine"><i class="routine">myFunc</i></b><b>(</b>&nbsp;<b>)</b> takes two arguments: the return value from <b class="routine"><i class="routine">yourFunc</i></b><b>(</b>&nbsp;<b>)</b> and <b class="symbol_lc">myVal</b>. The shell displays the value of the overall expression, which in this case is the value returned from <b class="routine"><i class="routine">myFunc</i></b><b>(</b>&nbsp;<b>)</b>.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85156">myFunc (yourFunc (yourVal), myVal);</a></b></pre></dl><dd><p class="Body"><a name="85157"> </a>Shell expressions can also contain references to function addresses instead of function invocations. As in C, this is indicated by the absence of parentheses after the function name. Thus the following expression evaluates to the result returned by the function <b class="routine"><i class="routine">myFunc2</i></b><b>(</b>&nbsp;<b>)</b> plus 4:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85158">4 + myFunc2 ( )</a></b></pre></dl><dd><p class="Body"><a name="85159"> </a>However, the following expression evaluates to the address of <b class="routine"><i class="routine">myFunc2</i></b><b>(</b>&nbsp;<b>)</b> plus 4:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85160">4 + myFunc2</a></b></pre></dl><dd><p class="Body"><a name="85161"> </a>An important exception to this occurs when the function name is the very first item encountered in a statement. This is discussed in <a href="c-shell3.html#85171"><i class="title">Arguments to Commands</i></a>.</p><dd><p class="Body"><a name="85165"> </a>Shell expressions can also contain calls to functions that do not have a symbolic name in the symbol table, but whose addresses are known to you. To do this, simply supply the address in place of the function name. Thus the following expression calls a parameterless function whose entry point is at address 10000 hex:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85166">0x10000 ()</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85167">Subroutines as Commands</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85168"> </a>Both VxWorks and the Tornado shell itself provide routines that are meant to be called from the shell interactively. You can think of these routines as <i class="term">commands</i>, rather than as <i class="term">subroutines</i>, even though they can also be called with the same syntax as C subroutines (and those that run on the target are in fact subroutines). All the commands discussed in this chapter fall in this category. When you see the word <i class="term">command</i>, you can read <i class="term">subroutine</i>, or vice versa, since their meaning here is identical.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85171">Arguments to Commands</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="101466"> </a>In practice, most statements input to the shell are function calls, often to invoke VxWorks facilities. To simplify this use of the shell, an important exception is allowed to the standard expression syntax required by C. When a function name is the very first item encountered in a shell statement, the parentheses surrounding the function's arguments may be omitted. Thus the following shell statements are synonymous:</p><dl class="margin"><dd><pre class="Code2"><b><a name="101467"></b><tt class="output">-&gt;</tt><b> rename ("oldname", "newname")</a></b><dd> <b><a name="101468"></b><tt class="output">-&gt;</tt><b> rename "oldname", "newname"</a></b></pre></dl><dd><p class="Body"><a name="85176"> </a>as are:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85177"></b><tt class="output">-&gt;</tt><b> evtBufferAddress ( )</a></b><dd> <b><a name="85178"></b><tt class="output">-&gt;</tt><b> evtBufferAddress</a></b></pre></dl><dd><p class="Body"><a name="85179"> </a>However, note that if you wish to assign the result to a variable, the function call cannot be the first item in the shell statement--thus, the syntactic exception above does not apply. The following captures the address, not the return value, of <b class="routine"><i class="routine">evtBufferAddress</i></b><b>(&nbsp;)</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85182"></b><tt class="output">-&gt; </tt><b>value = evtBufferAddress </a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85184">Task References</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85186"> </a>Most VxWorks routines that take an argument representing a task require a task ID. However, when invoking routines interactively, specifying a task ID can be cumbersome since the ID is an arbitrary and possibly lengthy number.</p><dd><p class="Body"><a name="85187"> </a>To accommodate interactive use, shell expressions can reference a task by either task ID or task name. The shell attempts to resolve a task argument to a task ID as follows: if no match is found in the symbol table for a task argument, the shell searches for the argument in the list of active tasks. When it finds a match, it substitutes the task name with its matching task ID. In symbol lookup, symbol names take precedence over task names. </p><dd><p class="Body"><a name="85188"> </a>By convention, task names are prefixed with a <i class="term">u</i> for tasks started from the Tornado shell, and with a <i class="term">t</i> for VxWorks tasks started from the target itself. In addition, tasks started from a shell are prefixed by <i class="term">s1</i>, <i class="term">s2</i>, and so on to indicate which shell they were started from. This avoids name conflicts with entries in the symbol table. The names of system tasks and the default task names assigned when tasks are spawned use this convention. For example, tasks spawned with the shell command <b class="routine"><i class="routine">sp</i></b><b>(</b>&nbsp;<b>)</b> in the first shell opened are given names such as <b class="task">s1u0</b> and <b class="task">s1u1</b>. Tasks spawned with the second shell opened have names such as <b class="task">s2u0</b> and <b class="task">s2u1</b>. You are urged to adopt a similar convention for tasks named in your applications.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="92081">6.3.4  &nbsp;&nbsp;The "Current" Task and Address</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85252"> </a>A number of commands--<b class="routine"><i class="routine">c</i></b><b>(&nbsp;)</b>, <b class="routine"><i class="routine">s</i></b><b>(&nbsp;)</b>, <b class="routine"><i class="routine">ti</i></b><b>(&nbsp;)</b>--take a task parameter that can be omitted.  If omitted, the <i class="term">current task</i> is used. The<b class="routine"><i class="routine"></i></b> <b class="routine"><i class="routine">l</i></b><b>(&nbsp;)</b> and <b class="routine"><i class="routine">d</i></b><b>(&nbsp;)</b> commands use the <i class="term">current address</i> if no address is specified. The current task and address are set when:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85259"> </a>A task hits a breakpoint or an exception trap. The current address is the address of the instruction that caused the break or exception.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85260"> </a>A task is single-stepped. The current address is the address of the <i class="emphasis">next</i> instruction to be executed.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="85261"> </a>Any of the commands that use the current task or address are executed with a specific task parameter. The current address will be the address of the byte <i class="emphasis">following</i> the last byte that was displayed or disassembled.</li></ul></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85262">6.3.5  &nbsp;&nbsp;Assignments</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85264"> </a>The shell C interpreter accepts assignment statements in the form:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85265"><i class="textVariable">addressExpression</i> = <i class="textVariable">expression</i></a></b></pre></dl><dd><p class="Body"><a name="85266"> </a>The left side of an expression must evaluate to an addressable entity; that is, a legal C value. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="92082">Typing and Assignment</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="92083"> </a>The data type of the left side is determined by the type of the right side. If the right side does not contain any floating-point constants or noninteger type-casts, then the type of the left side will be an integer. The value of the right side of the assignment is put at the address provided by the left side. For example, the following assignment sets the 4-byte integer variable <b class="symbol_lc">x</b> to 0x1000:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85267"></b><tt class="output">-&gt;</tt><b> x = 0x1000</a></b></pre></dl><dd><p class="Body"><a name="85268"> </a>The following assignment sets the 4-byte integer value at memory address 0x1000 to the current value of <b class="symbol_lc">x</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85269"></b><tt class="output">-&gt;</tt><b> *0x1000 = x</a></b></pre></dl><dd><p class="Body"><a name="85270"> </a>The following compound assignment adds 300 to the 4-byte integer variable <b class="symbol_lc">x</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85271"></b><tt class="output">-&gt;</tt><b> x += 300</a></b></pre></dl><dd><p class="Body"><a name="85272"> </a>The following adds 300 to the 4-byte integer at address 0x1000:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85273"></b><tt class="output">-&gt;</tt><b> *0x1000 += 300</a></b></pre></dl><dd><p class="Body"><a name="85274"> </a>The compound assignment operator <b class="operator">-=</b>, as well as the increment and decrement operators <b class="operator">++</b> and <b class="operator">--</b>, are also available.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85275">Automatic Creation of New Variables</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85277"> </a>New variables can be created automatically by assigning a value to an undefined identifier (one not already in the symbol table) with an assignment statement.</p><dd><p class="Body"><a name="85278"> </a>When the shell encounters such an assignment, it allocates space for the variable and enters the new identifier in the symbol table along with the address of the newly allocated variable. The new variable is set to the value and type of the right-side expression of the assignment statement. The shell prints a message indicating that a new variable has been allocated and assigned the specified value.</p><dd><p class="Body"><a name="85279"> </a>For example, if the identifier <b class="symbol_lc">fd</b> is not currently in the symbol table, the following statement creates a new variable named <b class="symbol_lc">fd</b> and assigns to it the result of the function call:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85281"></b><tt class="output">-&gt;</tt><b> fd = open ("file", 0) </a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85282">6.3.6  &nbsp;&nbsp;Comments</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85284"> </a>The shell allows two kinds of comments. First, comments of the form <b class="operator">/*</b>  <b class="operator">*/</b> can be included anywhere on a shell input line. These comments are simply discarded, and the rest of the input line evaluated as usual. Second, any line whose first nonblank character is <b class="operator">#</b> is ignored completely. Comments are particularly useful for Tornado shell scripts. See the section <a href="c-shell3.html#86307"><i class="title">Scripts: Redirecting Shell I/O</i></a> below.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85289">6.3.7  &nbsp;&nbsp;Strings</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85291"> </a>When the shell encounters a string literal ("") in an expression, it allocates space for the string including the null-byte string terminator. The value of the literal is the address of the string in the newly allocated storage. For instance, the following expression allocates 12 bytes from the target-agent memory pool, enters the string in those 12 bytes (including the null terminator), and assigns the address of the string to <b class="symbol_lc">x</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85292"></b><tt class="output">-&gt;</tt><b> x = "hello there"</a></b></pre></dl><dd><p class="Body"><a name="85293"> </a>Furthermore, even when a string literal is not assigned to a symbol, memory is still permanently allocated for it. For example, the following uses 12 bytes of memory that are never freed:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85294"></b><tt class="output">-&gt;</tt><b> printf ("hello there")</a></b></pre></dl><dd><p class="Body"><a name="85295"> </a>If strings were only temporarily allocated, and a string literal were passed to a routine being spawned as a task, then by the time the task executed and attempted to access the string, the shell would have already released--possibly even reused--the temporary storage where the string was held.</p><dd><p class="Body"><a name="85296"> </a>This memory, like other memory used by the Tornado tools, comes from the target-agent memory pool; it does not reduce the amount of memory available for application execution (the VxWorks memory pool). The amount of target memory allocated for each of the two memory pools is defined at configuration time; see <a href="c-builder6.html#99241"><i class="title">Scaling the Target Agent</i></a>. </p><dd><p class="Body"><a name="85300"> </a>After extended development sessions in Tornado shells, the cumulative memory used for strings may be noticeable. If this becomes a problem, restart your target server.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85303">6.3.8  &nbsp;&nbsp;Strings and Path Names</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85304"> </a>In VxWorks, the directory and file segments of path names (for target-resident files and devices) are separated with the slash character (<b class="operator">/</b>). This presents no difficulty when subroutines require a path-name argument, because the <b class="operator">/</b> character has no special meaning in C strings. </p><dd><p class="Body"><a name="85305"> </a>However, you can also refer from the shell to files that reside on your Windows host. For host path names, you can use either a slash for consistency with the VxWorks convention, or a backslash (<b class="operator">\</b>) for consistency with the Windows convention.</p><dd><p class="Body"><a name="85306"> </a>Because the backslash character is an escape character in C strings, you must double any backslashes that you use in path names as strings. This applies only to path names in C strings. No special syntax is required for path names that are interpreted directly by the shell.</p><dd><p class="Body"><a name="85315"> </a>The shell's <b class="routine"><i class="routine">ld</i></b><b>(&nbsp;)</b> command (<a href="c-shell2.html#90759"><i class="title">System Modification and Debugging</i></a>) can be used with all of these variations of path names. The following <b class="routine"><i class="routine">ld</i></b><b>(&nbsp;)</b> invocations are all correct and equivalent:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85317"></b><tt class="output">-&gt; </tt><b>ld &lt; c:\fred\tests\zap.o</a></b><dd> <b><a name="85318"></b><tt class="output">-&gt; </tt><b>ld &lt; c:/fred/tests/zap.o</a></b><dd> <b><a name="85319"></b><tt class="output">-&gt; </tt><b>ld 1,0,"c:\\fred\\tests\\zap.o"</a></b><dd> <b><a name="85321"></b><tt class="output">-&gt; </tt><b>ld 1,0,"c:/fred/tests/zap.o"</a></b></pre>

⌨️ 快捷键说明

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