30.01.2013 Views

TotalView Users Guide - CI Wiki

TotalView Users Guide - CI Wiki

TotalView Users Guide - CI Wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Automatically Setting Breakpoints<br />

Automatically Setting Breakpoints<br />

In many cases, your knowledge of what a program is doing lets you make<br />

predictions as to where problems occurs. The following CLI macro parses<br />

comments that you can include in a source file and, depending on the<br />

comment’s text, sets a breakpoint or an eval point.<br />

Following this macro is an excerpt from a program that uses it.<br />

# make_actions: Parse a source file, and insert<br />

# evaluation and breakpoints according to comments.<br />

#<br />

proc make_actions {{filename ""}} {<br />

if {$filename == ""} {<br />

puts "You need to specify a filename"<br />

error "No filename"<br />

}<br />

# Open the program’s source file and initialize a<br />

# few variables.<br />

set fname [set filename]<br />

set fsource [open $fname r]<br />

set lineno 0<br />

set incomment 0<br />

# Look for "signals" that indicate the type of<br />

# action point; they are buried in the comments.<br />

while {[gets $fsource line] != –1} {<br />

incr lineno<br />

set bpline $lineno<br />

# Look for a one-line eval point. The<br />

# format is ... /* EVAL: some_text */.<br />

# The text after EVAL and before the "*/" in<br />

# the comment is assigned to "code".<br />

if [regexp "/\\* EVAL: *(.*)\\*/" $line all code] {<br />

dbreak $fname\#$bpline –e $code<br />

continue<br />

}<br />

# Look for a multiline eval point.<br />

if [regexp "/\\* EVAL: *(.*)" $line all code] {<br />

# Append lines to "code".<br />

while {[gets $fsource interiorline] != –1} {<br />

incr lineno<br />

# Tabs will confuse dbreak.<br />

regsub –all \t $interiorline \<br />

" " interiorline<br />

218 Chapter 11: Seeing the CLI at Work

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

Saved successfully!

Ooh no, something went wrong!