1
0
mirror of https://github.com/golang/go synced 2024-11-22 19:44:57 -07:00

cmd/pprof: never use c++filt

The copy of c++filt shipped on OS X is six years old,
and in our case it does far more mangling than it
does demangling. People on non-OS X systems will
have a working nm --demangle, so this won't affect them.

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.8.2
BuildVersion:	12C2034
$ c++filt --version
GNU c++filt 070207 20070207
Copyright 2005 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
$

$ go tool nm -n revcomp | grep quoteWith
   4f560 T strconv.quoteWith
$ go tool nm -n revcomp | grep quoteWith  | c++filt
   f560 T strconv.quoteWith
$

$ nm -n revcomp | grep quoteWith
000000000004f560 t _strconv.quoteWith
$ nm -n revcomp | grep quoteWith | c++filt
000000000004f560 unsigned short _strconv.quoteWith
$

Fixes #4818.

R=golang-dev, r, bradfitz
CC=golang-dev
https://golang.org/cl/7729043
This commit is contained in:
Russ Cox 2013-03-11 18:15:23 -04:00
parent d2be8f2948
commit a25c403b3a

View File

@ -81,6 +81,11 @@ use Getopt::Long;
my $PPROF_VERSION = "1.5"; my $PPROF_VERSION = "1.5";
# NOTE: All mentions of c++filt have been expunged from this script
# because (1) we don't use C++, and (2) the copy of c++filt that ships
# on OS X is from 2007 and destroys nm output by "demangling" the
# first two columns (address and symbol type).
# These are the object tools we use which can come from a # These are the object tools we use which can come from a
# user-specified location using --tools, from the PPROF_TOOLS # user-specified location using --tools, from the PPROF_TOOLS
# environment variable, or from the environment. # environment variable, or from the environment.
@ -88,7 +93,6 @@ my %obj_tool_map = (
"objdump" => "objdump", "objdump" => "objdump",
"nm" => "nm", "nm" => "nm",
"addr2line" => "addr2line", "addr2line" => "addr2line",
"c++filt" => "c++filt",
## ConfigureObjTools may add architecture-specific entries: ## ConfigureObjTools may add architecture-specific entries:
#"nm_pdb" => "nm-pdb", # for reading windows (PDB-format) executables #"nm_pdb" => "nm-pdb", # for reading windows (PDB-format) executables
#"addr2line_pdb" => "addr2line-pdb", # ditto #"addr2line_pdb" => "addr2line-pdb", # ditto
@ -3093,9 +3097,7 @@ sub FetchSymbols {
my $url = SymbolPageURL(); my $url = SymbolPageURL();
$url = ResolveRedirectionForCurl($url); $url = ResolveRedirectionForCurl($url);
my $command_line = "$CURL -sd '\@$main::tmpfile_sym' '$url'"; my $command_line = "$CURL -sd '\@$main::tmpfile_sym' '$url'";
# We use c++filt in case $SYMBOL_PAGE gives us mangled symbols. open(SYMBOL, "$command_line |") or error($command_line);
my $cppfilt = $obj_tool_map{"c++filt"};
open(SYMBOL, "$command_line | $cppfilt |") or error($command_line);
ReadSymbols(*SYMBOL{IO}, $symbol_map); ReadSymbols(*SYMBOL{IO}, $symbol_map);
close(SYMBOL); close(SYMBOL);
} }
@ -4790,7 +4792,6 @@ sub GetProcedureBoundaries {
} }
my $nm = $obj_tool_map{"nm"}; my $nm = $obj_tool_map{"nm"};
my $cppfilt = $obj_tool_map{"c++filt"};
# nm can fail for two reasons: 1) $image isn't a debug library; 2) nm # nm can fail for two reasons: 1) $image isn't a debug library; 2) nm
# binary doesn't support --demangle. In addition, for OS X we need # binary doesn't support --demangle. In addition, for OS X we need
@ -4799,27 +4800,21 @@ sub GetProcedureBoundaries {
# in an incompatible way. So first we test whether our nm supports # in an incompatible way. So first we test whether our nm supports
# --demangle and -f. # --demangle and -f.
my $demangle_flag = ""; my $demangle_flag = "";
my $cppfilt_flag = "";
if (system("$nm --demangle $image >/dev/null 2>&1") == 0) { if (system("$nm --demangle $image >/dev/null 2>&1") == 0) {
# In this mode, we do "nm --demangle <foo>" # In this mode, we do "nm --demangle <foo>"
$demangle_flag = "--demangle"; $demangle_flag = "--demangle";
$cppfilt_flag = ""; }
} elsif (system("$cppfilt $image >/dev/null 2>&1") == 0) {
# In this mode, we do "nm <foo> | c++filt"
$cppfilt_flag = " | $cppfilt";
};
my $flatten_flag = ""; my $flatten_flag = "";
if (system("$nm -f $image >/dev/null 2>&1") == 0) { if (system("$nm -f $image >/dev/null 2>&1") == 0) {
$flatten_flag = "-f"; $flatten_flag = "-f";
} }
# Finally, in the case $imagie isn't a debug library, we try again with # Finally, in the case $image isn't a debug library, we try again with
# -D to at least get *exported* symbols. If we can't use --demangle, # -D to at least get *exported* symbols. If we can't use --demangle, too bad.
# we use c++filt instead, if it exists on this system.
my @nm_commands = ("$nm -n $flatten_flag $demangle_flag" . my @nm_commands = ("$nm -n $flatten_flag $demangle_flag" .
" $image 2>/dev/null $cppfilt_flag", " $image 2>/dev/null",
"$nm -D -n $flatten_flag $demangle_flag" . "$nm -D -n $flatten_flag $demangle_flag" .
" $image 2>/dev/null $cppfilt_flag", " $image 2>/dev/null",
# go tool nm is for Go binaries # go tool nm is for Go binaries
"go tool nm $image 2>/dev/null | sort"); "go tool nm $image 2>/dev/null | sort");