-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwhich_stub_from_addr.pl
executable file
·61 lines (52 loc) · 1.5 KB
/
which_stub_from_addr.pl
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
#!/usr/bin/perl
use strict;
use warnings;
# Script to determine which stub/builtin a given address is in.
# Generate a v8 output trace with:
# d8 --print_code_stubs --print_all_code > stub_output.txt
# Run this script:
# which_stub_from_addr.pl 0xaddr stub_output.txt
if ($#ARGV != 1) {
print STDERR "Invalid parameters [$#ARGV] : <pc> <file>";
exit 1;
}
my $addr = $ARGV[0];
# Trim any leading 0x chars
$addr =~ s/^0x//;
# Trim leading zeros.
$addr =~ s/^[0]+//;
# Convert to lowercase
$addr = lc $addr;
my $input_file = $ARGV[1];
open (my $trace_file, "<", $input_file) || die "Can't open $input_file: $!\n";
my %stub_hash = ();
my %function_hash = ();
my $stub_name = '';
my $invoke_count = 1;
while (my $line = readline($trace_file)) {
my $print_line = 1;
# Found STUB/BUILTIN name
if ($line =~ m/^name = (\w+)/) {
$stub_name = $1;
# We may compile stubs multiple times, so increment counter
# and track them.
if (defined $function_hash{$stub_name}) {
chomp($line);
my $orig_stub_name = $stub_name;
$line .= "_".$function_hash{$orig_stub_name}."\n";
$stub_name .= "_".$function_hash{$orig_stub_name};
$function_hash{$orig_stub_name}++;
} else {
$function_hash{$stub_name} = 2;
}
} elsif ($line =~ m/^(0x)?([0-9A-Fa-f]+) +([0-9]+) +/) {
$stub_hash{lc $2} = "<$stub_name+$3>";
}
}
if (defined $stub_hash{$addr}) {
print "0x$addr - $stub_hash{$addr}\n";
exit 0;
} else {
print STDERR "Address 0x$addr not found.\n";
exit 1;
}