From 8c42907cb46940cf2889163b83c881ff26800511 Mon Sep 17 00:00:00 2001 From: Raphael Moreira Zinsly Date: Mon, 17 Mar 2014 14:21:41 -0300 Subject: Fixed the use of addr2line to discover the separator symbol. In systems where addr2line has a version greater than 2.22 pprof fails in discover the separator symbol (_fini). This patch identifies if addr2line can find the symbol, otherwise pprof uses objdump to recover a address that addr2line's newer versions can recognize as the separator function. --- src/pprof | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/pprof b/src/pprof index f9298a1..720a431 100755 --- a/src/pprof +++ b/src/pprof @@ -4987,6 +4987,7 @@ sub error { sub GetProcedureBoundariesViaNm { my $escaped_nm_command = shift; # shell-escaped my $regexp = shift; + my $image = shift; my $symbol_table = {}; open(NM, "$escaped_nm_command |") || error("$escaped_nm_command: $!\n"); @@ -5056,6 +5057,37 @@ sub GetProcedureBoundariesViaNm { $symbol_table->{$routine} = [HexExtend($last_start), HexExtend($last_start)]; } + + # Verify if addr2line can find the $sep_symbol. If not, we use objdump + # to find the address for the $sep_symbol on code section which addr2line + # can find. + if (defined($sep_address)){ + my $start_val = $sep_address; + my $addr2line = $obj_tool_map{"addr2line"}; + my $cmd = ShellEscape($addr2line, "-f", "-C", "-e", $image, "-i"); + open(FINI, "echo $start_val | $cmd |") + || error("echo $start_val | $cmd: $!\n"); + $_ = ; + s/\r?\n$//g; + my $fini = $_; + close(FINI); + if ($fini ne $sep_symbol){ + my $objdump = $obj_tool_map{"objdump"}; + $cmd = ShellEscape($objdump, "-d", $image); + my $grep = ShellEscape("grep", $sep_symbol); + my $tail = ShellEscape("tail", "-n", "1"); + open(FINI, "$cmd | $grep | $tail |") + || error("$cmd | $grep | $tail: $!\n"); + s/\r//g; # turn windows-looking lines into unix-looking lines + my $data = ; + if (defined($data)){ + ($start_val, $fini) = split(/