Debian Codegraph @

internal/symbolizer/symbolizer.go

raw symbols SCIP
1 // Copyright 2014 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Package symbolizer provides a routine to populate a profile with
16 // symbol, file and line number information. It relies on the
17 // addr2liner and demangle packages to do the actual work.
18 package symbolizerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/
19
20 import (
21 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
22 "ioscip-go gomod github.com/golang/go/src go1.24.0 io/"
23 "net/httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/"
24 "net/urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/"
25 "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/"
26 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
27
28 "github.com/google/pprof/internal/binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/"
29 "github.com/google/pprof/internal/pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/"
30 "github.com/google/pprof/internal/symbolzscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolz`/"
31 "github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/"
32 "github.com/ianlancetaylor/demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/"
33 )
34
35 // Symbolizer implements the plugin.Symbolize interface.
36 type Symbolizerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer# struct {
37 Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#Obj. pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool#
38 UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#UI. pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#
39 Transportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#Transport. httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.RoundTripperscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/RoundTripper#
40 }
41
42 // test taps for dependency injection
43 var symbolzSymbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/symbolzSymbolize. = symbolzscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolz`/.Symbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolz`/Symbolize().
44 var localSymbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/localSymbolize. = doLocalSymbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/doLocalSymbolize().
45 var demangleFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/demangleFunction. = Demanglescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Demangle().
46
47 // Symbolize attempts to symbolize profile p. First uses binutils on
48 // local binaries; if the source is a URL it attempts to get any
49 // missed entries using symbolz.
50 func (s *Symbolizerscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#) Symbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#Symbolize().(mode string, sources pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.MappingSourcesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/MappingSources#, p *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) error {
51 remote, local, fast, force, demanglerMode := true, true, false, false, ""
52 for _, o := range stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.24.0 strings/Split().(stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.24.0 strings/ToLower().(mode), ":") {
53 switch o {
54 case "":
55 continue
56 case "none", "no":
57 return nil
58 case "local":
59 remote, local = false, true
60 case "fastlocal":
61 remote, local, fast = false, true, true
62 case "remote":
63 remote, local = true, false
64 case "force":
65 force = true
66 default:
67 switch d := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/TrimPrefix().(o, "demangle="); d {
68 case "full", "none", "templates":
69 demanglerMode = d
70 force = true
71 continue
72 case "default":
73 continue
74 }
75 s.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("ignoring unrecognized symbolization option: " + mode)
76 s.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("expecting -symbolize=[local|fastlocal|remote|none][:force][:demangle=[none|full|templates|default]")
77 }
78 }
79
80 var err error
81 if local {
82 // Symbolize locally using binutils.
83 if err = localSymbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/localSymbolize.(p, fast, force, s.Objscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#Obj., s.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#UI.); err != nil {
84 s.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#UI..PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("local symbolization: " + err.Error())
85 }
86 }
87 if remote {
88 post := func(source, post string) ([]byte, error) {
89 return postURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/postURL().(source, post, s.Transportscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#Transport.)
90 }
91 if err = symbolzSymbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/symbolzSymbolize.(p, force, sources, post, s.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Symbolizer#UI.); err != nil {
92 return err // Ran out of options.
93 }
94 }
95
96 demangleFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/demangleFunction.(p, force, demanglerMode)
97 return nil
98 }
99
100 // postURL issues a POST to a URL over HTTP.
101 func postURLscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/postURL().(source, post string, tr httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.RoundTripperscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/RoundTripper#) ([]byte, error) {
102 client := &httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Client#{
103 Transportscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Client#Transport.: tr,
104 }
105 resp, err := client.Postscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Client#Post().(source, "application/octet-stream", stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.24.0 strings/NewReader().(post))
106 if err != nil {
107 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("http post %s: %v", source, err)
108 }
109 defer resp.Bodyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src go1.24.0 io/Closer#Close().()
110 if resp.StatusCodescip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#StatusCode. != httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.StatusOKscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/StatusOK. {
111 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("http post %s: %v", source, statusCodeErrorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/statusCodeError().(resp))
112 }
113 return ioscip-go gomod github.com/golang/go/src go1.24.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.24.0 io/ReadAll().(resp.Bodyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Body.)
114 }
115
116 func statusCodeErrorscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/statusCodeError().(resp *httpscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#) error {
117 if resp.Headerscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Header..Getscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Header#Get().("X-Go-Pprof") != "" && stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.0 strings/Contains().(resp.Headerscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Header..Getscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Header#Get().("Content-Type"), "text/plain") {
118 // error is from pprof endpoint
119 if body, err := ioscip-go gomod github.com/golang/go/src go1.24.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.24.0 io/ReadAll().(resp.Bodyscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Body.); err == nil {
120 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("server response: %s - %s", resp.Statusscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Status., body)
121 }
122 }
123 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("server response: %s", resp.Statusscip-go gomod github.com/golang/go/src go1.24.0 `net/http`/Response#Status.)
124 }
125
126 // doLocalSymbolize adds symbol and line number information to all locations
127 // in a profile. mode enables some options to control
128 // symbolization.
129 func doLocalSymbolizescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/doLocalSymbolize().(prof *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, fast, force bool, obj pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjToolscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool#, ui pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#) error {
130 if fast {
131 if bu, ok := obj.(*binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/.Binutilsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/Binutils#); ok {
132 bu.SetFastSymbolizationscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/binutils`/Binutils#SetFastSymbolization().(true)
133 }
134 }
135
136 functions := map[profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#]*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#{}
137 addFunction := func(f *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#) *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function# {
138 if fp := functions[*f]; fp != nil {
139 return fp
140 }
141 functions[*f] = f
142 f.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID. = uint64(len(prof.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function.)) + 1
143 prof.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function. = append(prof.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function., f)
144 return f
145 }
146
147 missingBinaries := false
148 mappingLocs := map[*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#][]*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{}
149 for _, l := range prof.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. {
150 mappingLocs[l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.] = append(mappingLocs[l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping.], l)
151 }
152 for midx, m := range prof.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. {
153 locs := mappingLocs[m]
154 if len(locs) == 0 {
155 // The mapping is dangling and has no locations pointing to it.
156 continue
157 }
158 // Do not attempt to re-symbolize a mapping that has already been symbolized.
159 if !force && (m.HasFunctionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFunctions. || m.HasFilenamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFilenames. || m.HasLineNumbersscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasLineNumbers.) {
160 continue
161 }
162 if m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File. == "" {
163 if midx == 0 {
164 ui.PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("Main binary filename not available.")
165 continue
166 }
167 missingBinaries = true
168 continue
169 }
170 if m.Unsymbolizablescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Unsymbolizable().() {
171 // Skip well-known system mappings
172 continue
173 }
174 if m.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID. == "" {
175 if u, err := urlscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/.Parsescip-go gomod github.com/golang/go/src go1.24.0 `net/url`/Parse().(m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.); err == nil && u.IsAbsscip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#IsAbs().() && stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.0 strings/Contains().(stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.24.0 strings/ToLower().(u.Schemescip-go gomod github.com/golang/go/src go1.24.0 `net/url`/URL#Scheme.), "http") {
176 // Skip mappings pointing to a source URL
177 continue
178 }
179 }
180
181 name := filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Base().(m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.)
182 if m.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID. != "" {
183 name += fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().(" (build ID %s)", m.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.)
184 }
185 f, err := obj.Openscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjTool#Open.(m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File., m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start., m.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit., m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset., m.KernelRelocationSymbolscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#KernelRelocationSymbol.)
186 if err != nil {
187 ui.PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("Local symbolization failed for ", name, ": ", err)
188 missingBinaries = true
189 continue
190 }
191 if fid := f.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#BuildID.(); m.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID. != "" && fid != "" && fid != m.BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID. {
192 ui.PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("Local symbolization failed for ", name, ": build ID mismatch")
193 f.Closescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#Close.()
194 continue
195 }
196 symbolizeOneMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/symbolizeOneMapping().(m, locs, f, addFunction)
197 f.Closescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#Close.()
198 }
199
200 if missingBinaries {
201 ui.PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.("Some binary filenames not available. Symbolization may be incomplete.\n" +
202 "Try setting PPROF_BINARY_PATH to the search path for local binaries.")
203 }
204 return nil
205 }
206
207 func symbolizeOneMappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/symbolizeOneMapping().(m *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#, locs []*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, obj pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.ObjFilescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#, addFunction func(*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#) *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#) {
208 for _, l := range locs {
209 stack, err := obj.SourceLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/ObjFile#SourceLine.(l.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.)
210 if err != nil || len(stack) == 0 {
211 // No answers from addr2line.
212 continue
213 }
214
215 l.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. = make([]profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#, len(stack))
216 l.IsFoldedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#IsFolded. = false
217 for i, frame := range stack {
218 if frame.Funcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Func. != "" {
219 m.HasFunctionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFunctions. = true
220 }
221 if frame.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#File. != "" {
222 m.HasFilenamesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasFilenames. = true
223 }
224 if frame.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line. != 0 {
225 m.HasLineNumbersscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasLineNumbers. = true
226 }
227 f := addFunction(&profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#{
228 Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.: frame.Funcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Func.,
229 SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.: frame.Funcscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Func.,
230 Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.: frame.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#File.,
231 StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#StartLine.: int64(frame.StartLinescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#StartLine.),
232 })
233 l.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.[i] = profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#{
234 Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function.: f,
235 Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Line.: int64(frame.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Line.),
236 Columnscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Column.: int64(frame.Columnscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/Frame#Column.),
237 }
238 }
239
240 if len(stack) > 0 {
241 m.HasInlineFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#HasInlineFrames. = true
242 }
243 }
244 }
245
246 // Demangle updates the function names in a profile with demangled C++
247 // names, simplified according to demanglerMode. If force is set,
248 // overwrite any names that appear already demangled.
249 func Demanglescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/Demangle().(prof *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, force bool, demanglerMode string) {
250 if force {
251 // Remove the current demangled names to force demangling
252 for _, f := range prof.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function. {
253 if f.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name. != "" && f.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName. != "" {
254 f.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name. = f.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.
255 }
256 }
257 }
258
259 options := demanglerModeToOptionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/demanglerModeToOptions().(demanglerMode)
260 // Bail out fast to avoid any parsing, if we really don't want any demangling.
261 if len(options) == 0 {
262 return
263 }
264 for _, fn := range prof.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function. {
265 demangleSingleFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/demangleSingleFunction().(fn, options)
266 }
267 }
268
269 func demanglerModeToOptionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/demanglerModeToOptions().(demanglerMode string) []demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.Optionscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/Option# {
270 switch demanglerMode {
271 case "": // demangled, simplified: no parameters, no templates, no return type
272 return []demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.Optionscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/Option#{demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.NoParamsscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/NoParams., demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.NoEnclosingParamsscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/NoEnclosingParams., demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.NoTemplateParamsscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/NoTemplateParams.}
273 case "templates": // demangled, simplified: no parameters, no return type
274 return []demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.Optionscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/Option#{demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.NoParamsscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/NoParams., demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.NoEnclosingParamsscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/NoEnclosingParams.}
275 case "full":
276 return []demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.Optionscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/Option#{demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.NoClonesscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/NoClones.}
277 case "none": // no demangling
278 return []demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.Optionscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/Option#{}
279 }
280
281 panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().("unknown demanglerMode %s", demanglerMode))
282 }
283
284 func demangleSingleFunctionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/demangleSingleFunction().(fn *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#, opts []demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.Optionscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/Option#) {
285 if fn.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name. != "" && fn.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName. != fn.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name. {
286 return // Already demangled.
287 }
288 if demangled := demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.Filterscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/Filter().(fn.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName., opts...); demangled != fn.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName. {
289 fn.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name. = demangled
290 return
291 }
292
293 // OSX has all the symbols prefixed with extra '_' so lets try
294 // once more without it
295 if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(fn.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName., "_") {
296 if demangled := demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.Filterscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/Filter().(fn.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.[1:], opts...); demangled != fn.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.[1:] {
297 fn.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name. = demangled
298 return
299 }
300 }
301
302 // Could not demangle. Apply heuristics in case the name is
303 // already demangled.
304 name := fn.SystemNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#SystemName.
305 if looksLikeDemangledCPlusPlusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/looksLikeDemangledCPlusPlus().(name) {
306 for _, o := range opts {
307 switch o {
308 case demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.NoParamsscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/NoParams.:
309 name = removeMatchingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/removeMatching().(name, '(', ')')
310 case demanglescip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/.NoTemplateParamsscip-go gomod github.com/ianlancetaylor/demangle f615e6bd150b `github.com/ianlancetaylor/demangle`/NoTemplateParams.:
311 name = removeMatchingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/removeMatching().(name, '<', '>')
312 }
313 }
314 }
315 fn.Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name. = name
316 }
317
318 // looksLikeDemangledCPlusPlus is a heuristic to decide if a name is
319 // the result of demangling C++. If so, further heuristics will be
320 // applied to simplify the name.
321 func looksLikeDemangledCPlusPlusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/looksLikeDemangledCPlusPlus().(demangled string) bool {
322 // Skip java names of the form "class.<init>".
323 if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.0 strings/Contains().(demangled, ".<") {
324 return false
325 }
326 // Skip Go names of the form "foo.(*Bar[...]).Method".
327 if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.0 strings/Contains().(demangled, "]).") {
328 return false
329 }
330 return stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.ContainsAnyscip-go gomod github.com/golang/go/src go1.24.0 strings/ContainsAny().(demangled, "<>[]") || stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.0 strings/Contains().(demangled, "::")
331 }
332
333 // removeMatching removes nested instances of start..end from name.
334 func removeMatchingscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/symbolizer`/removeMatching().(name string, start, end byte) string {
335 s := string(start) + string(end)
336 var nesting, first, current int
337 for index := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.IndexAnyscip-go gomod github.com/golang/go/src go1.24.0 strings/IndexAny().(name[current:], s); index != -1; index = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.IndexAnyscip-go gomod github.com/golang/go/src go1.24.0 strings/IndexAny().(name[current:], s) {
338 switch current += index; name[current] {
339 case start:
340 nesting++
341 if nesting == 1 {
342 first = current
343 }
344 case end:
345 nesting--
346 switch {
347 case nesting < 0:
348 return name // Mismatch, abort
349 case nesting == 0:
350 name = name[:first] + name[current+1:]
351 current = first - 1
352 }
353 }
354 current++
355 }
356 return name
357 }