-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlinux_mangle_test.go
93 lines (85 loc) · 2.16 KB
/
linux_mangle_test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file tests mangle_linux.go, and can be removed or renamed once
// it's in better shape.
package main
import (
"fmt"
"regexp"
"bufio"
"os"
"io"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func test() {
syms := []string{
"_ZN3net23TCPClientSocketLibevent14DoReadCallbackEi",
"_ZN14ProfileManager22DoFinalInitForServicesEP7Profileb",
"_ZNK3gfx17PlatformFontPango10DeriveFontEii",
"_ZN10extensions16SettingsFrontendC2ERK13scoped_refptrINS_22SettingsStorageFactoryEEP7Profile",
"_ZNSt8_Rb_treeISsSt4pairIKSsPN4base5ValueEESt10_Select1stIS5_ESt4lessISsESaIS5_EE16_M_insert_uniqueERKS5_",
"_Z11UTF16ToUTF8RKSbItN4base20string16_char_traitsESaItEE",
}
d := NewLinuxDemangler(true)
for _, sym := range syms {
fmt.Printf("%s\n", sym)
dem, err := d.Demangle(sym)
check(err)
fmt.Printf("=> %s\n", dem)
}
}
func output(buf []byte) {
_, err := os.Stdout.Write(buf)
if err != nil {
panic(err)
}
}
func filt() {
d := NewLinuxDemangler(false)
re := regexp.MustCompile(`_Z[_a-zA-Z0-9]+`)
r := bufio.NewReader(os.Stdin)
for {
line, isPrefix, err := r.ReadLine()
if isPrefix {
panic("overlong line")
}
if err == io.EOF {
break
}
if err != nil {
panic(err)
}
offsets := re.FindAllIndex(line, -1)
if offsets != nil {
last := 0
for _, match := range offsets {
start, end := match[0], match[1]
output(line[last:start])
dem, err := d.Demangle(string(line[start:end]))
check(err)
output([]byte(dem))
last = end
}
output(line[last:])
output([]byte("\n"))
}
}
}
func main() {
test()
}