| 1 |
// Copyright 2018 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package objabi |
| 6 |
|
| 7 |
import "strings" |
| 8 |
|
| 9 |
// A FuncFlag records bits about a function, passed to the runtime. |
| 10 |
type FuncFlag uint8 |
| 11 |
|
| 12 |
// Note: This list must match the list in runtime/symtab.go. |
| 13 |
const ( |
| 14 |
FuncFlag_TOPFRAME = 1 << iota |
| 15 |
FuncFlag_SPWRITE |
| 16 |
FuncFlag_ASM |
| 17 |
) |
| 18 |
|
| 19 |
// A FuncID identifies particular functions that need to be treated |
| 20 |
// specially by the runtime. |
| 21 |
// Note that in some situations involving plugins, there may be multiple |
| 22 |
// copies of a particular special runtime function. |
| 23 |
type FuncID uint8 |
| 24 |
|
| 25 |
// Note: this list must match the list in runtime/symtab.go. |
| 26 |
const ( |
| 27 |
FuncID_normal FuncID = iota // not a special function |
| 28 |
FuncID_abort |
| 29 |
FuncID_asmcgocall |
| 30 |
FuncID_asyncPreempt |
| 31 |
FuncID_cgocallback |
| 32 |
FuncID_debugCallV2 |
| 33 |
FuncID_gcBgMarkWorker |
| 34 |
FuncID_goexit |
| 35 |
FuncID_gogo |
| 36 |
FuncID_gopanic |
| 37 |
FuncID_handleAsyncEvent |
| 38 |
FuncID_mcall |
| 39 |
FuncID_morestack |
| 40 |
FuncID_mstart |
| 41 |
FuncID_panicwrap |
| 42 |
FuncID_rt0_go |
| 43 |
FuncID_runfinq |
| 44 |
FuncID_runtime_main |
| 45 |
FuncID_sigpanic |
| 46 |
FuncID_systemstack |
| 47 |
FuncID_systemstack_switch |
| 48 |
FuncID_wrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.) |
| 49 |
) |
| 50 |
|
| 51 |
var funcIDs = map[string]FuncID{ |
| 52 |
"abort": FuncID_abort, |
| 53 |
"asmcgocall": FuncID_asmcgocall, |
| 54 |
"asyncPreempt": FuncID_asyncPreempt, |
| 55 |
"cgocallback": FuncID_cgocallback, |
| 56 |
"debugCallV2": FuncID_debugCallV2, |
| 57 |
"gcBgMarkWorker": FuncID_gcBgMarkWorker, |
| 58 |
"go": FuncID_rt0_go, |
| 59 |
"goexit": FuncID_goexit, |
| 60 |
"gogo": FuncID_gogo, |
| 61 |
"gopanic": FuncID_gopanic, |
| 62 |
"handleAsyncEvent": FuncID_handleAsyncEvent, |
| 63 |
"main": FuncID_runtime_main, |
| 64 |
"mcall": FuncID_mcall, |
| 65 |
"morestack": FuncID_morestack, |
| 66 |
"mstart": FuncID_mstart, |
| 67 |
"panicwrap": FuncID_panicwrap, |
| 68 |
"runfinq": FuncID_runfinq, |
| 69 |
"sigpanic": FuncID_sigpanic, |
| 70 |
"switch": FuncID_systemstack_switch, |
| 71 |
"systemstack": FuncID_systemstack, |
| 72 |
|
| 73 |
// Don't show in call stack but otherwise not special. |
| 74 |
"deferreturn": FuncID_wrapper, |
| 75 |
"runOpenDeferFrame": FuncID_wrapper, |
| 76 |
"deferCallSave": FuncID_wrapper, |
| 77 |
} |
| 78 |
|
| 79 |
// Get the function ID for the named function in the named file. |
| 80 |
// The function should be package-qualified. |
| 81 |
func GetFuncID(name string, isWrapper bool) FuncID { |
| 82 |
if isWrapper { |
| 83 |
return FuncID_wrapper |
| 84 |
} |
| 85 |
if strings.HasPrefix(name, "runtime.") { |
| 86 |
if id, ok := funcIDs[name[len("runtime."):]]; ok { |
| 87 |
return id |
| 88 |
} |
| 89 |
} |
| 90 |
return FuncID_normal |
| 91 |
} |