ldmdot
pedro_alves@portugalmail.pt
pedro_alves@portugalmail.pt
Mon Apr 10 19:18:00 GMT 2006
Hi guys,
Shaun Jackman wrote:
> A quick postscript. I found the dependency tree above using the linker
> map produced `ld -M' and a short filter to convert this output to a
> form graphviz's dotty could plot. The result is very pleasing. If
> anyone's interested I'll post it. In fact, I'll post it anyways. The
> usual 'this is ugly ugly one-off Perl code' caveat applies. Please
> wear sunglasses.
>
> Cheers,
> Shaun
>
> ========== ldmdot ==========
> #!/usr/bin/perl -w
> use strict;
>
> print "digraph ldmap {\n";
>
> while (<>) {
> chomp;
> last if $_ eq '';
> }
>
> my $member;
> while (<>) {
> chomp;
> last if $_ eq '';
> if (!/^ /) {
> s/^.*\(([^)]*)\).*$/$1/;
> y/-./__/;
> $member = $_;
> } else {
> my $symbol = $_;
> $symbol =~ s/^.*\(([^)]*)\).*$/$1/;
> my $file = $_;
> if (/\) /) {
> $file =~ s/^.*\(([^)]*)\) .*$/$1/;
> } else {
> $file =~ s/^.*(\/| )([^ ]*) .*$/$2/;
> }
> $file =~ y/-./__/;
> print "$file -> $symbol -> $member;\n";
> }
> }
>
> print "}\n";
>
While searching the archives for something totally unrelated, I stumbled on
this great little gem from Shaun.
[http://sourceware.org/ml/newlib/2005/msg00817.html]
It saved my day, so I want to give something back.
Here is my version. No need to replace dots and slashes if we quote the vars.
#!/usr/bin/perl -w
use strict;
print "digraph ldmap {\n";
my $member;
my $limiter = 'Allocating common symbols';
my $index;
while (<>) {
chomp;
last if $_ eq '';
last if index ($_, $limiter) != -1;
if (!/^ /) {
s/^.*\(([^)]*)\).*$/$1/;
$member = '"' . $_ . '"'
} else {
my $symbol = $_;
$symbol =~ s/^.*\(([^)]*)\).*$/$1/;
my $file = $_;
if (/\) /) {
$file =~ s/^.*\(([^)]*)\) .*$/$1/;
} else {
$file =~ s/^.*(\/| )([^ ]*) .*$/$2/;
}
if ($file eq '') {
$file = 'COMMANDLINE';
}
else {
$file = '"' . $file . '"'
}
$index = index ($symbol, ",");
if ($index == -1) {
print "$file -> $symbol -> $member;\n";
}
else {
# printf "map with strange symbol..."
# exit 1
# print "error!: " . $index;
# print "$file -> $symbol -> $member;\n";
}
}
}
print "}\n";
Thanks Shaun!
Cheers,
Pedro Alves
__________________________________________________________
Email gratuito com 2 000 MB
Espaço para guardar as memórias de uma vida
http://www.portugalmail.pt/2000mb
More information about the Newlib
mailing list