5 # A tool for post-processing the debug output generated by Asio-based programs
6 # to print the tree of handlers that resulted in some specified handler ids.
7 # Programs write this output to the standard error stream when compiled with
8 # the define `BOOST_ASIO_ENABLE_HANDLER_TRACKING'.
10 # Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
12 # Distributed under the Boost Software License, Version 1.0. (See accompanying
13 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
18 my %target_handlers = ();
19 my @cached_output = ();
20 my %outstanding_handlers = ();
21 my %running_handlers = ();
23 #-------------------------------------------------------------------------------
24 # Build the initial list of target handlers from the command line arguments.
26 sub build_initial_target_handlers
()
28 for my $handler (@ARGV)
30 $target_handlers{$handler} = 1;
34 #-------------------------------------------------------------------------------
35 # Parse the debugging output and cache the handler tracking lines.
37 sub parse_debug_output
()
39 while (my $line = <STDIN
>)
43 if ($line =~ /\@asio\|([^|]*)\|([^|]*)\|(.*)$/)
45 push(@cached_output, $line);
50 #-------------------------------------------------------------------------------
51 # Iterate over the cached output in revese and build a hash of all target
52 # handlers' ancestors.
54 sub build_target_handler_tree
()
56 my $i = scalar(@cached_output) - 1;
59 my $line = $cached_output[$i];
61 if ($line =~ /\@asio\|([^|]*)\|([^|]*)\|(.*)$/)
66 if ($action =~ /^([0-9]+)\*([0-9]+)$/)
68 if ($1 ne "0" and exists($target_handlers{$2}))
70 $target_handlers{$1} = 1;
79 #-------------------------------------------------------------------------------
80 # Print out all handler tracking records associated with the target handlers.
82 sub print_target_handler_records
()
84 for my $line (@cached_output)
86 if ($line =~ /\@asio\|([^|]*)\|([^|]*)\|(.*)$/)
91 if ($action =~ /^([0-9]+)\^([0-9]+)$/)
93 print("$line\n") if ($1 eq "0" or exists($target_handlers{$1})) and exists($target_handlers{$2});
97 if ($action =~ /^([0-9]+)\*([0-9]+)$/)
99 print("$1, $2, $line\n") if ($1 eq "0" or exists($target_handlers{$1})) and exists($target_handlers{$2});
102 # Begin handler invocation.
103 elsif ($action =~ /^>([0-9]+)$/)
105 print("$line\n") if (exists($target_handlers{$1}));
108 # End handler invocation.
109 elsif ($action =~ /^<([0-9]+)$/)
111 print("$line\n") if (exists($target_handlers{$1}));
114 # Handler threw exception.
115 elsif ($action =~ /^!([0-9]+)$/)
117 print("$line\n") if (exists($target_handlers{$1}));
120 # Handler was destroyed without being invoked.
121 elsif ($action =~ /^~([0-9]+)$/)
123 print("$line\n") if (exists($target_handlers{$1}));
126 # Operation associated with a handler.
127 elsif ($action =~ /^\.([0-9]+)$/)
129 print("$line\n") if (exists($target_handlers{$1}));
135 #-------------------------------------------------------------------------------
137 build_initial_target_handlers
();
138 parse_debug_output
();
139 build_target_handler_tree
();
140 print_target_handler_records
();