summaryrefslogtreecommitdiffstats
path: root/src/build/tools/gensyms
blob: f69e64d37e8c07d0534ff45762612e32a7cddcdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/perl

use strict;

sub add_image_subdir
{
    my $image = shift;
    if (!($image =~ m/\/img/)) { $image = "./img/".$image };
    return $image;
}

my $image_offset = $ENV{"HAL_IMAGE_OFFSET"};
if (not $image_offset) { $image_offset = "0x0"; };
$image_offset = hex $image_offset;

my $image;
my $all_modules = 0;
my @modules = ();

if ($#ARGV == -1)
{
    die "gensyms <image> [modules]\n";
}
if ($#ARGV == 0)
{
    $all_modules = 1;
}
else
{
    @modules = @ARGV[1..$#ARGV];
}

$image = add_image_subdir($ARGV[0]);

my %module_offsets = ();
open MODINFO, "< $image.modinfo";

while (my $modline = <MODINFO>)
{
    chomp $modline;
    my @splitline = split /,/, $modline;
    $module_offsets{@splitline[0]} = (hex @splitline[1]) + $image_offset;
    if ($all_modules)
    {
	push @modules, @splitline[0];
    }
}

my %output = ();
foreach my $module (@modules)
{
    open OBJDUMP, ("ppc64-mcp6-objdump --syms -C ".add_image_subdir($module)."|");
    while (my $line = <OBJDUMP>)
    {
	if (($line =~ m/\*ABS\*/) || ($line =~ m/\*UND\*/))
	{
	    next;
	}
	if ("d" eq substr($line, 22, 1))
	{
	    next;
	}
	if (!($line =~ m/^[0-9a-f]{16}/))
	{
	    next;
	}

	$line =~ s/[\s]*$//;
	
	my $address = (hex substr($line, 0, 16)) + $module_offsets{$module};
	my $is_function = ("F" eq substr($line, 23, 1));
        my $size = (hex substr($line, 32, 16));
	my $name = substr($line, 48);
	my $code_loc = 0;
	if ($is_function)
	{
	    open XXD, ("/usr/bin/xxd -p -s ".($address - $image_offset)." -l 8 -g 8 ".add_image_subdir($image)."|");
	    $code_loc = (hex <XXD>) + $image_offset;
	    close XXD;
	    
	    my $tmp = $code_loc; $code_loc = $address; $address = $tmp;
	}
	my $outstring = "";
	$outstring = sprintf "%s,%08x,%08x,%08x,%s\n", ($is_function?"F":"V"),$address,$code_loc,$size,$name;

	$output{$outstring} = $outstring;
    }
    close OBJDUMP;
}

foreach my $outstring (sort { substr($a,2,8) cmp substr($b,2,8) } keys %output)
{
    print $outstring;
}
OpenPOWER on IntegriCloud