-
Notifications
You must be signed in to change notification settings - Fork 5
/
parser.go
58 lines (52 loc) · 1.24 KB
/
parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package uprobe
import (
"github.com/jschwinger233/ufuncgraph/elf"
)
type ParseOptions struct {
Wildcards []string
ExWildcards []string
Fetch map[string]map[string]string
SearchDepth int
Backtrace bool
}
func Parse(elf *elf.ELF, opts *ParseOptions) (uprobes []Uprobe, err error) {
fetchArgs, err := parseFetchArgs(opts.Fetch)
if err != nil {
return
}
funcTrees, err := parseFuncTrees(elf, opts.Wildcards, opts.ExWildcards, opts.SearchDepth)
if err != nil {
return
}
visited := map[string]interface{}{}
for _, tree := range funcTrees {
tree.Print(0)
tree.Traverse(func(layer int, parent, self *FuncTree) bool {
if _, ok := visited[self.Name]; ok {
return false
}
visited[self.Name] = nil
if self.Err != nil {
return true
}
userSpecified := layer == 0
uprobes = append(uprobes, Uprobe{
Funcname: self.Name,
Location: AtFramePointer,
Offset: self.FpOffset,
UserSpecified: userSpecified,
Backtrace: userSpecified && opts.Backtrace,
FetchArgs: fetchArgs[self.Name],
})
for _, off := range self.RetOffsets {
uprobes = append(uprobes, Uprobe{
Funcname: self.Name,
Location: AtRet,
Offset: off,
})
}
return true
})
}
return
}