2 # $Id: tracemunch,v 1.12 2017/06/29 09:23:58 tom Exp $
3 ##############################################################################
4 # Copyright (c) 1998-2005,2017 Free Software Foundation, Inc. #
6 # Permission is hereby granted, free of charge, to any person obtaining a #
7 # copy of this software and associated documentation files (the "Software"), #
8 # to deal in the Software without restriction, including without limitation #
9 # the rights to use, copy, modify, merge, publish, distribute, distribute #
10 # with modifications, sublicense, and/or sell copies of the Software, and to #
11 # permit persons to whom the Software is furnished to do so, subject to the #
12 # following conditions: #
14 # The above copyright notice and this permission notice shall be included in #
15 # all copies or substantial portions of the Software. #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
20 # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
23 # DEALINGS IN THE SOFTWARE. #
25 # Except as contained in this notice, the name(s) of the above copyright #
26 # holders shall not be used in advertising or otherwise to promote the sale, #
27 # use or other dealings in this Software without prior written #
29 ##############################################################################
30 # tracemunch -- compactify ncurses trace logs
32 # The error logs produced by ncurses with tracing enabled can be very tedious
33 # to wade through. This script helps by compacting runs of log lines that
34 # can be conveniently expressed as higher-level operations.
40 "PutAttrChar\\({{ '(.)' = 0[0-7]+ }}\\) at \\(([0-9]+), ([0-9]+)\\)";
42 "waddnstr\\(0x([[:xdigit:]]+),\"([^\"]+)\",[0-9]+\\) called {A_NORMAL}";
60 $arg =~ s/\b$curscr\b/curscr/g if ($curscr);
61 $arg =~ s/\b$newscr\b/newscr/g if ($newscr);
62 $arg =~ s/\b$stdscr\b/stdscr/g if ($stdscr);
63 foreach my $addr ( keys %scr_addr ) {
64 $n = $scr_addr{$addr};
65 $arg =~ s/\b$addr\b/screen$n/g;
67 foreach my $addr ( keys %thr_addr ) {
68 $n = $thr_addr{$addr};
69 $arg =~ s/\b$addr\b/thread$n/g;
71 foreach my $addr ( keys %try_addr ) {
72 $n = $try_addr{$addr};
73 $arg =~ s/\b$addr\b/tries_$n/g;
75 foreach my $addr ( keys %win_addr ) {
76 $n = $win_addr{$addr};
77 $arg =~ s/\b$addr\b/window$n/g;
91 if ( $_ =~ /^(0x[[:xdigit:]]+):/ ) {
92 $thr_addr{$1} = ++$thr_nums unless defined $thr_addr{$1};
93 $thread = "thread" . $thr_addr{$1} . ":";
97 # Transform window pointer addresses so it's easier to compare logs
98 $awaiting = "curscr" if ( $_ =~ /creating curscr/ );
99 $awaiting = "newscr" if ( $_ =~ /creating newscr/ );
100 $awaiting = "stdscr" if ( $_ =~ /creating stdscr/ );
101 $awaiting = "screen" if ( $_ =~ /^(\+ )*called {new_prescr\(\)/ );
102 if ( $_ =~ /^create :window 0x([[:xdigit:]]+)/ ) {
104 if ( $awaiting eq "curscr" ) {
107 elsif ( $awaiting eq "newscr" ) {
110 elsif ( $awaiting eq "stdscr" ) {
114 $win_addr{$addr} = $win_nums++;
118 elsif ( $_ =~ /^(\+ )*called {_nc_add_to_try\((0x[[:xdigit:]]+),/ ) {
119 $try_addr{$2} = ++$try_nums unless defined $try_addr{$2};
121 elsif ( $_ =~ /^(\+ )*_nc_alloc_screen_sp 0x([[:xdigit:]]+)/ ) {
123 $scr_addr{$addr} = ++$scr_nums unless ( $scr_addr{$addr} );
126 elsif ( $_ =~ /^(\+ )*return }0x([[:xdigit:]]+)/ ) {
128 if ( $awaiting eq "screen" ) {
129 $scr_addr{$addr} = ++$scr_nums unless ( $scr_addr{$addr} );
132 elsif ( $_ =~ /^\.\.\.deleted win=0x([[:xdigit:]]+)/ ) {
135 if ( $addr eq $curscr ) {
138 elsif ( $addr eq $newscr ) {
141 elsif ( $addr eq $stdscr ) {
145 undef $win_addr{$addr};
149 # Compactify runs of PutAttrChar calls (TR_CHARPUT)
150 if ( $_ =~ /$putattr/ ) {
151 my $putattr_chars = $1;
155 if ( $_ =~ /$putattr/ ) {
156 $putattr_chars .= $1;
163 "RUN of PutAttrChar()s: \"$putattr_chars\" from ${starty}, ${startx}\n";
167 # Compactify runs of waddnstr calls (TR_CALLS)
168 if ( $_ =~ /$waddnstr/ ) {
169 my $waddnstr_chars = $2;
172 if ( $_ =~ /$waddnstr/ && $1 eq $winaddr ) {
173 $waddnstr_chars .= $2;
179 my $winaddstr = &transaddr($winaddr);
180 print "RUN of waddnstr()s: $winaddr, \"$waddnstr_chars\"\n";
184 # More transformations can go here
186 # Repeated runs of anything
187 my $anyline = &transaddr($_);
190 if ( &transaddr($_) eq $anyline ) {
197 if ( $repeatcount > 1 ) {
198 print "${repeatcount} REPEATS OF $anyline";
201 print $thread . $anyline;
208 # tracemunch ends here