Factor out print_trace_line from print_trace
Use BOOST_FOREACH where possible