02.03.2014 Views

Tornado

Tornado

Tornado

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Tornado</strong> 2.0<br />

User’s Guide<br />

proc traverse head {<br />

for {set pNode [gdbEvalScalar "$head"] }\<br />

{$pNode} \<br />

{set pNode [gdbEvalScalar "( (struct node *)$pNode)->next"]} \<br />

{puts stdout $pNode}<br />

}<br />

In the body of the loop, the Tcl command puts prints the address of the node.<br />

To type the procedure directly into the command panel would require prefacing<br />

the text above with the tcl command, and would require additional backslashes<br />

(one at the end of every line).<br />

If pList is a variable of type (struct *node), you can execute:<br />

(gdb) tcl traverse pList<br />

The procedure displays the address of each node in the list. For a list with two<br />

elements, the output would look something like the following:<br />

0xffeb00<br />

0xffea2c<br />

It might be more useful to redefine the procedure body to print out the integer<br />

member data, instead. For example, replace the last line with the following:<br />

{puts stdout [format "data = %d" \<br />

[gdbEvalScalar "((struct node *) $pNode)->data"]]}<br />

You can bind a new GDB command to this Tcl procedure by using tclproc<br />

(typically, in the same Tcl script file as the procedure definition):<br />

tclproc traverse traverse<br />

The traverse command can be abbreviated, like any GDB command. With these<br />

definitions, you can type the following command:<br />

(gdb) trav pList<br />

The output now exhibits the contents of each node in the list:<br />

data = 1<br />

data = 2<br />

272

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!