|
Packit |
345191 |
#!/usr/bin/perl
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
# Copyright (C) 2015 - 2016 Intel Corporation.
|
|
Packit |
345191 |
# All rights reserved.
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
# Redistribution and use in source and binary forms, with or without
|
|
Packit |
345191 |
# modification, are permitted provided that the following conditions are met:
|
|
Packit |
345191 |
# 1. Redistributions of source code must retain the above copyright notice(s),
|
|
Packit |
345191 |
# this list of conditions and the following disclaimer.
|
|
Packit |
345191 |
# 2. Redistributions in binary form must reproduce the above copyright notice(s),
|
|
Packit |
345191 |
# this list of conditions and the following disclaimer in the documentation
|
|
Packit |
345191 |
# and/or other materials provided with the distribution.
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
|
|
Packit |
345191 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
Packit |
345191 |
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
Packit |
345191 |
# EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit |
345191 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit |
345191 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
Packit |
345191 |
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
Packit |
345191 |
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
Packit |
345191 |
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
Packit |
345191 |
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
|
|
Packit |
345191 |
use strict;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
my $usage = "Usage: get_autohbw_srclines.pl output_log_of_AutoHBW executable";
|
|
Packit |
345191 |
|
|
Packit |
345191 |
# Check for 2 arguments
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
if (@ARGV != 2) {
|
|
Packit |
345191 |
print $usage, "\n";
|
|
Packit |
345191 |
exit;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
# Read the command line arguments
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
my $LogF = shift @ARGV;
|
|
Packit |
345191 |
my $BinaryF = shift @ARGV;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
&main();
|
|
Packit |
345191 |
|
|
Packit |
345191 |
sub main {
|
|
Packit |
345191 |
|
|
Packit |
345191 |
|
|
Packit |
345191 |
print("Info: Reading AutoHBW log from: $LogF\n");
|
|
Packit |
345191 |
print("Info: Binary file: $BinaryF\n");
|
|
Packit |
345191 |
|
|
Packit |
345191 |
# open the log file produced by AutoHBM and look at lines starting
|
|
Packit |
345191 |
# with Log
|
|
Packit |
345191 |
open LOGF, "grep Log $LogF |" or die "Can't open log file $LogF";
|
|
Packit |
345191 |
|
|
Packit |
345191 |
my $line;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
# Read each log line
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
while ($line = <LOGF>) {
|
|
Packit |
345191 |
|
|
Packit |
345191 |
# if the line contain 3 backtrace addresses, try to find the source
|
|
Packit |
345191 |
# lines for them
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
if ($line =~ /^(Log:.*)Backtrace:.*0x([0-9a-f]+).*0x([0-9a-f]+).*0x([0-9a-f]+)/ ) {
|
|
Packit |
345191 |
|
|
Packit |
345191 |
# Read the pointers
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
my @ptrs;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
my $pre = $1;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
$ptrs[0] = $2;
|
|
Packit |
345191 |
$ptrs[1] = $3;
|
|
Packit |
345191 |
$ptrs[2] = $4;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
# prints the first portion of the line
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
print $pre, "\n";
|
|
Packit |
345191 |
|
|
Packit |
345191 |
# for each of the pointers, lookup its source line using
|
|
Packit |
345191 |
# addr2line and print the src line(s) if found
|
|
Packit |
345191 |
#
|
|
Packit |
345191 |
my $i=0;
|
|
Packit |
345191 |
for ($i=0; $i < @ptrs; $i++) {
|
|
Packit |
345191 |
|
|
Packit |
345191 |
my $addr = $ptrs[$i];
|
|
Packit |
345191 |
|
|
Packit |
345191 |
open SRCL, "addr2line -e $BinaryF 0x$addr |"
|
|
Packit |
345191 |
or die "addr2line fail";
|
|
Packit |
345191 |
|
|
Packit |
345191 |
|
|
Packit |
345191 |
my $srcl = <SRCL>;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
if ($srcl =~ /^\?/) {
|
|
Packit |
345191 |
|
|
Packit |
345191 |
} else {
|
|
Packit |
345191 |
|
|
Packit |
345191 |
print "\t- Src: $srcl";
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
}
|