Created
November 15, 2013 15:57
-
-
Save leifwalsh/7486665 to your computer and use it in GitHub Desktop.
eliminate duplicate thread stacks from gdb "thread apply all bt"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use Digest::MD5 qw(md5_hex); | |
my @threads; | |
my $curr_thd = undef; | |
$\ = "\n"; | |
LINE: | |
while (<>) { | |
chomp; | |
if (/^Thread ([0-9]+) \(Thread 0x[0-9a-f]+ \(LWP [0-9]+\)\):$/) { | |
if (defined $curr_thd) { | |
$curr_thd->{md5} = md5_hex @{$curr_thd->{frames}}; | |
push @threads, $curr_thd; | |
} | |
$curr_thd = {tid => $1, frames => [], text => [$_]}; | |
next LINE; | |
} | |
if (/^#[0-9]+\s+(0x[0-9a-f]+ in (void )?)?([a-zA-Z_?:@<>.,*]([a-zA-Z0-9_?:@<>.,*]|\s??)*)\s?\(/) { | |
push @{$curr_thd->{text}}, $_; | |
push @{$curr_thd->{frames}}, $3; | |
} | |
} | |
$curr_thd->{md5} = md5_hex @{$curr_thd->{frames}}; | |
push @threads, $curr_thd; | |
my $printed = {}; | |
for my $thread (@threads) { | |
if (exists $printed->{$thread->{md5}}) { | |
$printed->{$thread->{md5}}++; | |
} else { | |
print for (@{$thread->{text}}); | |
$printed->{$thread->{md5}} = 1; | |
print ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment