-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy paththread.go
131 lines (102 loc) · 3.23 KB
/
thread.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2013 Chris McGee <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gdblib
import (
"strings"
)
type ThreadListIdsResult struct {
ThreadIds []string `json:"thread-ids"`
CurrentThreadId string `json:"current-thread-id"`
NumThreads string `json:"number-of-threads"`
}
func (gdb *GDB) ThreadListIds() (*ThreadListIdsResult, error) {
descriptor := cmdDescr{}
descriptor.cmd = "-thread-list-ids"
descriptor.response = make(chan cmdResultRecord)
gdb.input <- descriptor
result := <-descriptor.response
// Swap out the thread-ids because they don't work with the normal JSON
// mapping
resultStr := result.result
beginThreadIds := strings.Index(resultStr, "thread-ids={")
endThreadIds := strings.Index(resultStr[beginThreadIds:], "}") + beginThreadIds
threadIds := resultStr[beginThreadIds : endThreadIds+1]
// Change the object block into an array block and remote the "thread-id" fields to use
// those as the string literal
newThreadIds := strings.Replace(threadIds, "thread-id=", "", -1)
newThreadIds = strings.Replace(newThreadIds, "{", "[", -1)
newThreadIds = strings.Replace(newThreadIds, "}", "]", -1)
resultStr = strings.Replace(resultStr, threadIds, newThreadIds, 1)
result.result = resultStr
resultObj := ThreadListIdsResult{}
err := parseResult(result, &resultObj)
if err != nil {
return nil, err
}
return &resultObj, nil
}
type ThreadInfoParms struct {
ThreadId string
}
type ThreadInfoResult struct {
Threads []ThreadInfo `json:"threads"`
CurrentThreadId string `json:"current-thread-id"`
}
type ThreadInfo struct {
Id string `json:"id"`
TargetId string `json:"target-id"`
Frame FrameInfo `json:"frame"`
State string `json:"state"`
}
type FrameInfo struct {
Level string `json:"level"`
Addr string `json:"addr"`
Func string `json:"func"`
Args []ArgInfo `json:"args"`
File string `json:"file"`
Fullname string `json:"fullname"`
Line string `json:"line"`
}
type ArgInfo struct {
Name string `json:"name"`
Value string `json:"value"`
}
func (gdb *GDB) ThreadInfo(parms ThreadInfoParms) (*ThreadInfoResult, error) {
descriptor := cmdDescr{}
descriptor.cmd = "-thread-info"
if parms.ThreadId != "" {
descriptor.cmd = descriptor.cmd + " " + parms.ThreadId
}
descriptor.response = make(chan cmdResultRecord)
gdb.input <- descriptor
result := <-descriptor.response
resultObj := ThreadInfoResult{}
err := parseResult(result, &resultObj)
if err != nil {
return nil, err
}
return &resultObj, nil
}
type ThreadSelectParms struct {
ThreadId string
}
type ThreadSelectResult struct {
NewThreadId string `json:"new-thread-id"`
}
func (gdb *GDB) ThreadSelect(parms ThreadSelectParms) (*ThreadSelectResult, error) {
descriptor := cmdDescr{}
descriptor.cmd = "-thread-select"
if parms.ThreadId != "" {
descriptor.cmd = descriptor.cmd + " " + parms.ThreadId
}
descriptor.response = make(chan cmdResultRecord)
gdb.input <- descriptor
result := <-descriptor.response
resultObj := ThreadSelectResult{}
err := parseResult(result, &resultObj)
if err != nil {
return nil, err
}
return &resultObj, nil
}