📄 c-wtx4.html
字号:
<font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85365">4.4.8 Working with Object Modules</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85367"> </a>The WTX Tcl API provides complete access to the target server's dynamic loading capabilities. The fundamental command is <b class="tclProc">wtxObjModuleLoad</b>, which works like the <b class="routine"><i class="routine">ld</i></b><b>( )</b> command in the Tornado shell. It takes a path to an object module and downloads the module to the target. This command returns a module ID, followed by the addresses of the sections of the relocated module. You can load a module and save the ID in a variable:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85369"></b><tt class="output">wtxtcl> </tt><b>set modId [lindex [wtxObjModuleLoad /<i class="textVariable">work</i>/<i class="textVariable">dir</i>/mod.o] 0]</a></b></pre></dl><dd><p class="Body"><a name="85370"> </a>If the module contains unresolvable symbols, a list of them is returned with the module ID:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85371"></b><tt class="output">wtxtcl> </tt><b>wtxObjModuleLoad /<i class="textVariable">work</i>/<i class="textVariable">dir</i>/umod.o </b><tt class="output">0x624ef8 0x36c540 0x36d5a8 0x36d5d8 _missingVar _missingFunc</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85375"> </a>There are also routines for obtaining information about object modules. <b class="tclProc">wtxObjModuleList</b> returns a list of loaded object modules. This list can be directed to input for <b class="tclProc">wtxObjModuleInfo</b>, which takes the list as an argument and returns information about all listed modules.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85378"></b><tt class="output">wtxtcl> </tt><b>foreach mod [wtxObjModuleList] { puts stdout [wtxObjModuleInfo $mod] } </b><tt class="output">0x71db0 vxWorks a.out 0 0x64 {0 0x2000 0x957e8} {0 0x977e8 0x10f50} {0 0xa8738 0x87b0} 0x1324b0 mod.o a.out 0x1 0x4 {0 0x39e9e8 0x1048} {0 0x39fa30 0x30} {0 0x39fa60 0xa8} 0x132760 umod.o a.out 0x2 0x4 {0 0x39d530 0x1068} {0 0x39e598 0x30} {0 0x39e5c8 0xa8}</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="87391">4.4.9 Working with Tasks</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85387"> </a>If the target server is connected to a target running VxWorks, you can create and manipulate VxWorks tasks interactively with Tcl commands. Creating a task interactively from <b class="command">wtxtcl</b> is less efficient than using the Tornado shell. The Tornado shell uses Tcl procedures to automate many tasks, including task creation. This chapter treats only those features available directly from <b class="command">wtxtcl</b>.</p><dd><p class="Body"><a name="85388"> </a>The first step is to spawn a task named <b class="task">uMyTask</b> at priority 100 with VxWorks options 0x3 (<b class="symbol_UC">VX_UNBREAKABLE | VX_SUPERVISOR_MODE</b>). The entry point is the <b class="routine"><i class="routine">taskDelay</i></b><b>( )</b>routine, whose address comes from <b class="tclProc">symbol</b>, which you created in <a href="c-wtx4.html#90668"><i class="title">4.4.7 Working with the Symbol Table</i></a>. The argument 10000 causes the task to delay for 10,000 ticks before exiting. (For more information on command parameters, see the online reference material under <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado API Guide>WTX Tcl Library</font></b>.)</p><dl class="margin"><dd><pre class="Code2"><b><a name="85395"></b><tt class="output">wtxtcl> </tt><b>wtxContextCreate 1 uMyTask 100 0x3 0 5000 \ [symbol taskDelay] 0 0 10000 </b><tt class="output">0x3b6870</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85398"> </a>The output, 0x3b6780, is the ID of the new task. If you are running a Tornado shell, you can use <b class="routine"><i class="routine">i</i></b><b>( )</b> to check that it has been created. The task has not begun running yet; it is created in the suspended state, and must be resumed before it executes:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85399"></b><tt class="output">wtxtcl> </tt><b>wtxContextResume CONTEXT_TASK 0x3b6870</b><tt class="output"> 0</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85401"> </a>Now the task runs, and vanishes after the task delay has expired. To find out what other commands operate on contexts, see the online reference material under <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado API Guide>WTX Tcl Library</font></b>. To see a list of these commands, type:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85405"></b><tt class="output">wtxtcl> </tt><b>info commands wtxContext* </b><tt class="output">wtxContextResume wtxContextKill wtxContextStep wtxContextSuspend wtxContextCreate wtxContextCont</tt><b></a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85407">4.4.10 Working with Events</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85409"> </a>The target server receives event strings from the target and from attached tools and directs them to appropriate queues. For a discussion of the WTX event facility, see <a href="c-wtx3.html#84699"><i class="title">4.3.10 Event Management</i></a>. By default, when tools first attach, they receive no event strings. It is up to each tool to register for the events it is interested in and to check its queue periodically.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85413">Registering for Events</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85415"> </a>Your <b class="command">wtxtcl</b> session is not yet registered for any events. In order to receive event strings, you must call <b class="tclProc">wtxRegisterForEvent</b>. The argument to this command is a regular expression that serves as the target server filter for assigning events to your tool queue. The following example registers for all events:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85417"></b><tt class="output">wtxtcl> </tt><b>wtxRegisterForEvent .* </b><tt class="output">0</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85419"> </a>The return value 0 indicates that you have successfully registered for all events.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85420">Unregistering for Events</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85422"> </a>Your <b class="command">wtxtcl</b> session is registered for all events. If you don't want to receive some types of events, you must call <b class="tclProc">wtxUnregisterForEvent</b>. The argument to this command is a regular expression that serves the target server as a filter for assigning events to your tool queue. The following example unregisters for tool- related events (<b class="symbol_UC">TOOL_ATTACH</b> and <b class="symbol_UC">TOOL_DETACH)</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85424"></b><tt class="output">wtxtcl> </tt><b>wtxUnregisterForEvent TOOL.*</b><tt class="output"> 0</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85426"> </a>The return value 0 indicates that you have successfully unregistered for tool related events.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85429">Checking the Event Queue</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85431"> </a>One way to confirm that your <b class="command">wtxtcl</b> session is registered for all events is to call <b class="tclProc">wtxEventGet</b> to query the target server for events. It returns an event string if any events are queued. The first word in the string is the event type, and the rest are event-specific parameters. <a href="c-wtx3.html#84717">Table 4-1</a> contains a detailed list of the events and their parameters. The reference entry for <b class="tclProc">wtxEventGet</b> details their Tcl representation. If the queue is empty, <b class="tclProc">wtxEventGet</b> returns the empty string. </p><dd><p class="Body"><a name="85437"> </a>Some environments generate many events. In other cases, you may have to query the queue many times before an event is returned. Within the Tornado shell Tcl interpreter, a routine <b class="tclProc">wtxEventPoll</b> is available to check the queue regularly. You can use the same building blocks in <b class="command">wtxtcl</b> to create a polling routine. The WTX primitive <b class="tclProc">wtxEventGet</b>, which asks for one event if it is available, can be combined with the Tcl procedure <b class="tclProc">msleep</b>, which puts the invoking process to sleep for a specified number of milliseconds. The following Tcl procedure polls for events with the specified delay. Define this procedure (<b class="tclProc">eventPoll</b>) to the interpreter as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85440"></b><tt class="output">wtxtcl> </tt><b>proc eventPoll {intvl} { while {[set event [wtxEventGet]] == ""} { msleep $intvl } return $event }</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85447">Generating and Retrieving Events</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85449"> </a>The example in this section stimulates two events on the target and captures them. The first step is to create a task with entry point <b class="routine"><i class="routine">tickGet</i></b><b>( )</b>. Then set two eventpoints on <b class="routine"><i class="routine">tickGet</i></b><b>( )</b> and resume the task. When the task hits the first eventpoint it generates an event, which you can retrieve from the queue. When it completes, it generates a second event.</p><dd><p class="Body"><a name="85454"> </a>To create the task, use the technique from <a href="c-wtx4.html#87391"><i class="title">4.4.9 Working with Tasks</i></a>, without setting the <b class="symbol_UC">VX_UNBREAKABLE</b> bit in the task options:</p><dl class="margin"><dd><pre class="Code2"><b><a name="90351"></b><tt class="output">wtxtcl> </tt><b>set ctxId [wtxContextCreate CONTEXT_TASK tick 100 0x1 \ 0 2000 [symbol tickGet] 0 0] </b><tt class="output">0x4aeec90</tt><b></a></b></pre></dl><dd><p class="Body"><a name="85457"> </a>You can use the shell to verify that the task has appeared. The task is in the suspended state, and its ID has been saved in the variable <b class="symbol_lc">ctxId</b>. </p><dd><p class="Body"><a name="85459"> </a>To add an eventpoint to <b class="routine"><i class="routine">tickGet</i></b><b>( )</b>, use <b class="tclProc">wtxEventpointAdd</b>. The eventpoint stops the task, which generates an event when it resumes. The parameters of <b class="tclProc">wtxEventpointAdd</b> include three WTX enumerated constant types: <b class="symbol_UC">EVENT_TYPE</b>, <b class="symbol_UC">CONTEXT_TYPE,</b> and <b class="symbol_UC">ACTION_TYPE</b>. (For information on specifying these arguments in numeric form, see the online reference material under <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Tornado API Guide>WTX Protocol</font></b>). In Tcl you can specify the parameters symbolically. Use <b class="tclProc">wtxEnumList</b> to obtain a list of constant types. Then give <b class="tclProc">wtxEnumInfo</b> any of these constants as a parameter to obtain a list of all events of a given type which can be passed to a Tcl command, as in the following example:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85464"></b><tt class="output">wtxtcl> </tt><b>wtxEnumList </b><tt class="output">ACTION_TYPE CONTEXT_TYPE EVENT_TYPE REG_SET_TYPE LOAD_FLAG VIO_CTL_REQUEST AGENT_MODE TASK_OPTION OBJ_KILL_REQUEST OPEN_FLAG CONTEXT_STATUS wtxtcl> </tt><b>wtxEnumInfo EVENT_TYPE </b><tt class="output">WTX_EVENT_NONE 0x0 WTX_EVENT_CTX_START 0x1 WTX_EVENT_CTX_EXIT 0x2 WTX_EVENT_TEXT_ACCESS 0x3 WTX_EVENT_DATA_ACCESS 0x4 WTX_EVENT_EXCEPTION 0x5 WTX_EVENT_VIO_WRITE 0x6 WTX_EVENT_HW_BP 0x7 WTX_EVENT_CALL_RETURN 0x8</tt><b></a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85471"> </a>Since it is difficult to type these long names at the keyboard, you can query for abbreviations by giving the <b class="command">-abbrev</b> flag to <b class="tclProc">wtxEnumInfo</b> along with the constant:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85472"></b><tt class="output">wtxtcl> </tt><b>wtxEnumInfo -abbrev EVENT_TYPE </b><tt class="output">WTX_EVENT_NONE WTX_EVENT_NONE NONE none 0x0 WTX_EVENT_CTX_START WTX_EVENT_CTX_START CTX_START cstart 0x1 WTX_EVENT_CTX_EXIT WTX_EVENT_CTX_EXIT CTX_EXIT cexit 0x2 WTX_EVENT_TEXT_ACCESS WTX_EVENT_TEXT_ACCESS TEXT_ACCESS tacc 0x3 WTX_EVENT_DATA_ACCESS WTX_EVENT_DATA_ACCESS DATA_ACCESS dacc 0x4 WTX_EVENT_EXCEPTION WTX_EVENT_EXCEPTION EXCEPTION exc 0x5 WTX_EVENT_VIO_WRITE WTX_EVENT_VIO_WRITE VIO_WRITE viow 0x6 WTX_EVENT_HW_BP WTX_EVENT_HW_BP HW_BP hwbp 0x7 WTX_EVENT_CALL_RETURN WTX_EVENT_CALL_RETURN CALL_RETURN cret 0x8</tt><b></a></b></pre></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/caution.gif"></td><td><hr><div class="CalloutCell"><a name="90719"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">CAUTION: </font></b></a>The abbreviations are handy for typing but, if you are writing scripts, it is better practice to use the complete name.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="85487"> </a><b class="symbol_UC">WTX_EVENT_TEXT_ACCESS</b> is an appropriate event type for a traditional code breakpoint. In the list of event type abbreviations, <b class="symbol_UC">WTX_EVENT_TEXT_ACCESS</b> can be abbreviated <b class="symbol_lc">tacc</b>. <b class="symbol_UC">WTX_EVENT_CTX_EXIT</b> generates an event when the task exits, and can be abbreviated <b class="symbol_lc">cexit</b>. </p><dd><p class="Body"><a name="85491"> </a>Calling <b class="tclProc">wtxEnumInfo </b>with the<b class="tclProc"> </b><b class="command">-abbrev</b> flag for <b class="symbol_UC">CONTEXT_TYPE</b> and <b class="symbol_UC">ACTION_TYPE</b> shows that you can use <b class="symbol_lc">task</b> and <b class="symbol_lc">notify</b> to abbreviate <b class="symbol_UC">CONTEXT_TASK</b> and <b class="symbol_UC">ACTION_NOTIFY</b>. </p><dd><p class="Body"><a name="85492"> </a>Now you have all the information you need to add two eventpoints to the <b class="routine"><i class="routine">tickGet</i></b><b>( )</b> routine, as shown in the following example:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85493"></b><tt class="output">wtxtcl> </tt><b>wtxEventpointAdd tacc [symbol tickGet] task $ctxId \ notify|stop 0 0 0</b><tt class="output"> 0x1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -