-
Notifications
You must be signed in to change notification settings - Fork 5
/
region.go
48 lines (42 loc) · 1.18 KB
/
region.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
package perforator
import (
"errors"
"strconv"
"strings"
"github.com/zyedidia/perforator/bininfo"
"github.com/zyedidia/perforator/utrace"
)
func parseLocation(s string, bin *bininfo.BinFile) (uint64, error) {
if strings.Contains(s, ":") {
parts := strings.Split(s, ":")
file, lineStr := parts[0], parts[1]
line, err := strconv.Atoi(lineStr)
if err != nil {
return 0, err
}
return bin.LineToPC(file, line)
}
return strconv.ParseUint(s, 0, 64)
}
// ParseRegion parses an address region. The region is written as loc-loc,
// where 'loc' is a location specified as either a file:line source code
// location (if the elf binary has DWARF debugging information), or a direct
// hexadecimal address in the form 0x...
func ParseRegion(s string, bin *bininfo.BinFile, rangeInnerDelimiter string) (*utrace.AddressRegion, error) {
parts := strings.Split(s, rangeInnerDelimiter)
if len(parts) != 2 {
return nil, errors.New("invalid region")
}
start, err := parseLocation(parts[0], bin)
if err != nil {
return nil, err
}
end, err := parseLocation(parts[1], bin)
if err != nil {
return nil, err
}
return &utrace.AddressRegion{
StartAddr: start,
EndAddr: end,
}, nil
}