Skip to content

Commit c798a96

Browse files
committed
fix unwindstack support for arm
1 parent c3734fe commit c798a96

7 files changed

Lines changed: 172 additions & 129 deletions

File tree

preload_libs/libstackplz.so

0 Bytes
Binary file not shown.

user/common/const.go

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,46 @@ const (
2828
REG_ARM_LR
2929
REG_ARM_PC
3030
REG_ARM_MAX
31-
REG_ARM_INDEX
32-
REG_ARM_ABS
3331
)
3432

33+
var RegsArmIdxMap map[uint32]string = map[uint32]string{
34+
REG_ARM_R0: "r0",
35+
REG_ARM_R1: "r1",
36+
REG_ARM_R2: "r2",
37+
REG_ARM_R3: "r3",
38+
REG_ARM_R4: "r4",
39+
REG_ARM_R5: "r5",
40+
REG_ARM_R6: "r6",
41+
REG_ARM_R7: "r7",
42+
REG_ARM_R8: "r8",
43+
REG_ARM_R9: "r9",
44+
REG_ARM_R10: "r10",
45+
REG_ARM_FP: "fp",
46+
REG_ARM_IP: "ip",
47+
REG_ARM_SP: "sp",
48+
REG_ARM_LR: "lr",
49+
REG_ARM_PC: "pc",
50+
}
51+
52+
var RegsArmNameMap map[string]uint32 = map[string]uint32{
53+
"r0": REG_ARM_R0,
54+
"r1": REG_ARM_R1,
55+
"r2": REG_ARM_R2,
56+
"r3": REG_ARM_R3,
57+
"r4": REG_ARM_R4,
58+
"r5": REG_ARM_R5,
59+
"r6": REG_ARM_R6,
60+
"r7": REG_ARM_R7,
61+
"r8": REG_ARM_R8,
62+
"r9": REG_ARM_R9,
63+
"r10": REG_ARM_R10,
64+
"fp": REG_ARM_FP,
65+
"ip": REG_ARM_IP,
66+
"sp": REG_ARM_SP,
67+
"lr": REG_ARM_LR,
68+
"pc": REG_ARM_PC,
69+
}
70+
3571
const (
3672
REG_ARM64_X0 uint32 = iota
3773
REG_ARM64_X1
@@ -67,11 +103,9 @@ const (
67103
REG_ARM64_SP
68104
REG_ARM64_PC
69105
REG_ARM64_MAX
70-
REG_ARM64_INDEX
71-
REG_ARM64_ABS
72106
)
73107

74-
var RegsMagicMap map[string]uint32 = map[string]uint32{
108+
var RegsNameMap map[string]uint32 = map[string]uint32{
75109
"x0": REG_ARM64_X0,
76110
"x1": REG_ARM64_X1,
77111
"x2": REG_ARM64_X2,
@@ -107,16 +141,52 @@ var RegsMagicMap map[string]uint32 = map[string]uint32{
107141
"pc": REG_ARM64_PC,
108142
}
109143

144+
var RegsIdxMap map[uint32]string = map[uint32]string{
145+
REG_ARM64_X0: "x0",
146+
REG_ARM64_X1: "x1",
147+
REG_ARM64_X2: "x2",
148+
REG_ARM64_X3: "x3",
149+
REG_ARM64_X4: "x4",
150+
REG_ARM64_X5: "x5",
151+
REG_ARM64_X6: "x6",
152+
REG_ARM64_X7: "x7",
153+
REG_ARM64_X8: "x8",
154+
REG_ARM64_X9: "x9",
155+
REG_ARM64_X10: "x10",
156+
REG_ARM64_X11: "x11",
157+
REG_ARM64_X12: "x12",
158+
REG_ARM64_X13: "x13",
159+
REG_ARM64_X14: "x14",
160+
REG_ARM64_X15: "x15",
161+
REG_ARM64_X16: "x16",
162+
REG_ARM64_X17: "x17",
163+
REG_ARM64_X18: "x18",
164+
REG_ARM64_X19: "x19",
165+
REG_ARM64_X20: "x20",
166+
REG_ARM64_X21: "x21",
167+
REG_ARM64_X22: "x22",
168+
REG_ARM64_X23: "x23",
169+
REG_ARM64_X24: "x24",
170+
REG_ARM64_X25: "x25",
171+
REG_ARM64_X26: "x26",
172+
REG_ARM64_X27: "x27",
173+
REG_ARM64_X28: "x28",
174+
REG_ARM64_X29: "x29",
175+
REG_ARM64_LR: "lr",
176+
REG_ARM64_SP: "sp",
177+
REG_ARM64_PC: "pc",
178+
}
179+
110180
func GetRegIndex(reg string) uint32 {
111-
value, ok := RegsMagicMap[reg]
181+
value, ok := RegsNameMap[reg]
112182
if !ok {
113183
panic(fmt.Sprintf("ParseAsReg failed =>%s<=", reg))
114184
}
115185
return value
116186
}
117187

118188
func GetRegName(index uint32) string {
119-
for k, v := range RegsMagicMap {
189+
for k, v := range RegsNameMap {
120190
if v == index {
121191
return k
122192
}

user/event/chelper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import "C"
1313
var LibPath string
1414

1515
func ParseStack(map_buffer string, opt *UnwindOption, ubuf *UnwindBuf) string {
16-
stack_str := C.get_stack(C.CString(LibPath), C.CString(map_buffer), unsafe.Pointer(opt), unsafe.Pointer(ubuf.GetLibArg()), unsafe.Pointer(&ubuf.Data[0]))
16+
stack_str := C.get_stack(C.CString(LibPath), C.CString(map_buffer), unsafe.Pointer(opt), unsafe.Pointer(&ubuf.Regs[0]), unsafe.Pointer(&ubuf.Data[0]))
1717
// char* 转到 go 的 string
1818
return C.GoString(stack_str)
1919
}

user/event/event_brk.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,7 @@ func (this *BrkEvent) ParseContextStack() {
119119
}
120120
return
121121
}
122-
opt := &UnwindOption{}
123-
opt.RegMask = (1 << common.REG_ARM64_MAX) - 1
124-
if this.mconf.Is32Bit {
125-
opt.RegMask = (1 << common.REG_ARM_MAX) - 1
126-
}
127-
opt.ShowPC = this.mconf.ShowPC
128-
this.Stackinfo = ParseStack(content, opt, this.UnwindBuffer)
122+
this.Stackinfo = ParseStack(content, this.GetOpt(), this.UnwindBuffer)
129123
} else if this.rec.ExtraOptions.ShowRegs {
130124
err := this.RegsBuffer.ParseContext(this.buf)
131125
if err != nil {

0 commit comments

Comments
 (0)