From 58064a7cab9d39ff9b58c94e76e441dc238343b9 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sat, 18 Aug 2012 17:03:32 +1000 Subject: [PATCH] pprof: make it work on windows again - pprof is a perl script, so go command should invoke perl instead of trying to run pprof directly; - pprof should use "go tool nm" unconditionally on windows, no one else can extract symbols from Go program; - pprof should use "go tool nm" instead of "6nm". Fixes #3879. R=golang-dev, r CC=golang-dev https://golang.org/cl/6445082 --- misc/pprof | 16 +++++++--------- src/cmd/go/tool.go | 12 +++++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/misc/pprof b/misc/pprof index 92009a1ce8..2f386c3fab 100755 --- a/misc/pprof +++ b/misc/pprof @@ -4599,6 +4599,7 @@ sub ConfigureObjTools { # in the same directory as pprof. $obj_tool_map{"nm_pdb"} = "nm-pdb"; $obj_tool_map{"addr2line_pdb"} = "addr2line-pdb"; + $obj_tool_map{"is_windows"} = "true"; } if ($file_type =~ /Mach-O/) { @@ -4806,16 +4807,13 @@ sub GetProcedureBoundaries { " $image 2>/dev/null $cppfilt_flag", "$nm -D -n $flatten_flag $demangle_flag" . " $image 2>/dev/null $cppfilt_flag", - # 6nm is for Go binaries - "6nm $image 2>/dev/null | sort"); + # go tool nm is for Go binaries + "go tool nm $image 2>/dev/null | sort"); - # If the executable is an MS Windows PDB-format executable, we'll - # have set up obj_tool_map("nm_pdb"). In this case, we actually - # want to use both unix nm and windows-specific nm_pdb, since - # PDB-format executables can apparently include dwarf .o files. - if (exists $obj_tool_map{"nm_pdb"}) { - my $nm_pdb = $obj_tool_map{"nm_pdb"}; - push(@nm_commands, "$nm_pdb --demangle $image 2>/dev/null"); + # If the executable is an MS Windows Go executable, we'll + # have set up obj_tool_map("is_windows"). + if (exists $obj_tool_map{"is_windows"}) { + @nm_commands = ("go tool nm $image 2>/dev/null | sort"); } foreach my $nm_command (@nm_commands) { diff --git a/src/cmd/go/tool.go b/src/cmd/go/tool.go index cb463a2e71..01e8ff6bb8 100644 --- a/src/cmd/go/tool.go +++ b/src/cmd/go/tool.go @@ -47,7 +47,7 @@ const toolWindowsExtension = ".exe" func tool(name string) string { p := filepath.Join(toolDir, name) - if toolIsWindows { + if toolIsWindows && name != "pprof" { p += toolWindowsExtension } return p @@ -76,6 +76,16 @@ func runTool(cmd *Command, args []string) { setExitStatus(3) return } + if toolIsWindows && toolName == "pprof" { + args = append([]string{"perl", toolPath}, args[1:]...) + var err error + toolPath, err = exec.LookPath("perl") + if err != nil { + fmt.Fprintf(os.Stderr, "go tool: perl not found\n") + setExitStatus(3) + return + } + } if toolN { fmt.Printf("%s %s\n", toolPath, strings.Join(args[1:], " "))