-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathThreadManager.xcsm
More file actions
214 lines (185 loc) · 6.64 KB
/
ThreadManager.xcsm
File metadata and controls
214 lines (185 loc) · 6.64 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//xlang Source, Name:ThreadManager.xcsm
//Date: Sun Sep 02:03:10 2018
class ThreadManager{
public static Object threadLock = new Object();
public static long currentThreadId = 0;
public static int currentFrameId = 0;
public static const int XDBG_STATE_UPDATE = 0; //状态更新
public static const int XDBG_STATE_CREATE = 1; //线程创建
public static const int XDBG_STATE_EXIT = 2; //线程退出
public static const int XDBG_STATE_EXCEPTION = 4; //捕获异常
public static const int XDBG_STATE_REIGGEBP = 8; //触发断点
public static class StackFrame{
public int id;
public String source;
public long ip;
public int line;
public int column;
public long moffset;
public String method ;
public String path ;
public StackFrame(int _id, JsonObject frame){
id = id;
if (frame != nilptr){
source = frame.getString("source");
String tmofst = frame.getString("moffset");
if (tmofst != nilptr){
moffset = tmofst.parseLong();
}
ip = frame.getLong("ip");
method = frame.getString("method");
path = frame.getString("path");
line = frame.getInt("line");
column = frame.getInt("column");
}
}
};
public static class ThreadObject{
public long id;
public bool bInterrupt;
public String name;
public bool bException;
public bool bSender = false;
public StackFrame [] frames;
public String except_name;
public String except_msg;
public String except_addr;
public ThreadObject(@NotNilptr JsonObject thread){
parse(thread);
}
public void parse(@NotNilptr JsonObject thread){
id = thread.getLong("id");
name = thread.getString("name");
if (name != nilptr && name.length() == 0){
name = "Thread:" + id;
}
bInterrupt = thread.getBool("interrupt");
if (thread.has("sender")){
bSender = thread.getBool("sender");
}
JsonObject exception = (JsonObject)thread.get("exception");
if (exception != nilptr){
bException = true;
parseException(exception);
}
parseStack((JsonArray)thread.get("stack"));
}
public void parseException(@NotNilptr JsonObject exception){
except_name = exception.getString("name");
except_msg = exception.getString("msg");
if (except_msg == nilptr || except_msg.length() == 0){
except_msg = "<没有更多信息>";
}
except_addr = exception.getString("address");
}
public void parseStack(JsonArray stacks){
if (stacks != nilptr){
int size = stacks.length();
frames = new StackFrame[size];
for (int i = 0; i < size; i ++){
frames[i] = new StackFrame(i, (JsonObject)stacks.get(i));
}
}
}
};
static Map<long, ThreadObject> thread_list = new Map<long, ThreadObject>();
public static void Update(@NotNilptr JsonObject root, bool reset){
synchronized(threadLock){
if (reset){
thread_list.clear();
}
JsonArray threads = (JsonArray)root.get("threads");
int action = root.getInt("action");
bool remove = false;
if (action == XDBG_STATE_EXIT){
remove = true;
}
if (threads != nilptr){
int c = threads.length();
bool bNeedUpdateFrame = false;
bool interrupted = false;
for (int i = 0; i < c; i++){
JsonObject thread = (JsonObject)threads.get(i);
if (thread == nilptr){
continue;
}
long tid = 0;
if (remove){
tid = thread.getLong("id");
thread_list.remove(tid);
}else{
ThreadObject to = new ThreadObject(thread);
tid = to.id;
if (tid != 0){
thread_list.put(tid, to);
interrupted = to.bInterrupt;
if (to.bSender){
setThreadFrameId(tid, 0);
}
}
}
if (tid != 0){
XStackInfor.updateThread(tid, action);
if (tid == currentThreadId){
bNeedUpdateFrame = interrupted;
}
}
}
if (bNeedUpdateFrame){
updateDisplayInformation();
}
}
}
}
public static bool isCurrentInterrupt(){
bool bInterrupt = false;
synchronized(threadLock){
Map.Iterator<long,ThreadObject> iter = thread_list.find(currentThreadId);
if (iter != nilptr){
ThreadObject to = iter.getValue();
if (to != nilptr){
bInterrupt = to.bInterrupt;
}
}
}
return bInterrupt;
}
public static void updateControlPane(long thread){
bool bInterrupt = false;
synchronized(threadLock){
Map.Iterator<long,ThreadObject> iter = thread_list.find(thread);
if (iter != nilptr){
ThreadObject to = iter.getValue();
if (to != nilptr){
bInterrupt = to.bInterrupt;
}
}
}
XWorkspace.workspace.refreshDebugControl(bInterrupt);
}
public static void updateDisplayInformation(){
if (currentThreadId > 0){
updateControlPane(currentThreadId);
XWorkspace.workspace.debuggee.queryFrame(currentThreadId, currentFrameId);
}
}
public static void setThreadFrameId(long tid, int frame){
synchronized(threadLock){
currentThreadId = tid;
currentFrameId = frame;
}
}
public static void setCurrentThread(long tid, int frame){
setThreadFrameId(tid, frame);
updateDisplayInformation();
}
public static ThreadObject getThread(long tid){
synchronized(threadLock){
Map.Iterator<long, ThreadObject> iterator = thread_list.find(tid);
if (iterator != nilptr){
return iterator.getValue();
}
}
return nilptr;
}
};