From 229e28b33b27b92d14d8ed8784d1e4760486d143 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Sat, 22 Aug 2020 09:50:42 +0200 Subject: [PATCH] +dwarfredundant --- dwarfredundant | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 dwarfredundant diff --git a/dwarfredundant b/dwarfredundant new file mode 100755 index 0000000..5302c08 --- /dev/null +++ b/dwarfredundant @@ -0,0 +1,72 @@ +#! /usr/bin/perl +use strict; +use warnings; +$|=1; +my $quiet=shift @ARGV if ($ARGV[0]||"") eq "-q"; +for my $argv (@ARGV) { + local *F; + open F,"llvm-dwarfdump --color=0 --verbose --debug-info '$argv'|" or die; + my $redundant; + my $redundant_text; + my $redundant_addr; + my $redundant_children; + my $die_addr; + my $die_text; + my $saved_total=0; + my $emptyline; + sub null($) { + my($addr)=@_; + die if !$redundant; + my $saved=eval($addr)+1-eval($redundant_addr); + $saved_total+=$saved; + print "saved=$saved:\n$redundant_text\nsaved_total=$saved_total\n" if !$quiet; + $redundant=0; + } + while () { + if (/^\s*$/s) { + $emptyline=1; + next; + } + my($addr,$spaces,$rest)=(/^(0x[0-9a-f]{8}:| {11})( +)(.*)$/) or do { + next; + }; + if ($addr ne " "x11) { + $addr=~s/:$// or die; + } else { + $addr=0; + } + if ($addr) { + if ($emptyline&&$redundant&&!$redundant_children) { + null($addr); + } + $die_addr=$addr; + $die_text=$_; + } else { + $die_text.=$_; + } + $emptyline=0; + if ($redundant) { + $redundant_text.=$_ if !$quiet; + } + my $spacesl=length $spaces or die; + if ($rest=~/DW_FORM_addr.*0x0000000000000000/) { + next if $redundant; + $redundant=$spacesl; + $redundant_text=$die_text if !$quiet; + $redundant_children=($die_text=~/^.* [*]\n/); + $redundant_addr=$die_addr or die; + next; + } + if ($rest=~/DW_AT_stmt_list/) { + $redundant=0; + next; + } + if ($rest eq "NULL") { + next if !$redundant; + next if $spacesl>$redundant; + null($addr); + } + } + close F or die; + print "$saved_total\n"; +} -- 1.8.3.1