|
Lines 12-29
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
| 14 |
import java.util.Arrays; |
14 |
import java.util.Arrays; |
|
|
15 |
import java.util.Comparator; |
| 15 |
import java.util.List; |
16 |
import java.util.List; |
| 16 |
|
17 |
|
| 17 |
/** |
18 |
/** |
| 18 |
* GDB/MI thread list parsing. |
19 |
* GDB/MI thread list parsing. |
| 19 |
~"\n" |
20 |
~" 5 Thread 8 ( Name: TIMERThread, State: sleeping, Priority: 14 ) " |
| 20 |
~" 2 Thread 2049 (LWP 29354) " |
21 |
~" 4 Thread 3 ( Name: Network support, State: sleeping, Priority: 7 ) " |
| 21 |
~"* 1 Thread 1024 (LWP 29353) " |
22 |
~" 3 Thread 2 ( Name: Network alarm support, State: sleeping, Priority: 6 ) " |
|
|
23 |
~" 2 Thread 1 ( Name: Idle Thread, State: ready, Priority:31 ) " |
| 24 |
~"* 1 Thread 9 ( Name: pthread.00000800, State: running, Priority: 15 ) " |
| 22 |
|
25 |
|
| 23 |
*/ |
26 |
*/ |
| 24 |
public class CLIInfoThreadsInfo extends MIInfo { |
27 |
public class CLIInfoThreadsInfo extends MIInfo { |
| 25 |
|
28 |
|
| 26 |
protected int[] threadIds; |
29 |
protected int[] threadIds; |
|
|
30 |
protected String[] threadNames ; |
| 27 |
protected int currentThreadId; |
31 |
protected int currentThreadId; |
| 28 |
|
32 |
|
| 29 |
public CLIInfoThreadsInfo(MIOutput out) { |
33 |
public CLIInfoThreadsInfo(MIOutput out) { |
|
Lines 36-42
Link Here
|
| 36 |
} |
40 |
} |
| 37 |
|
41 |
|
| 38 |
public String[] getThreadNames() { |
42 |
public String[] getThreadNames() { |
| 39 |
return null; |
43 |
return threadNames ; |
| 40 |
} |
44 |
} |
| 41 |
|
45 |
|
| 42 |
public int getCurrentThread() { |
46 |
public int getCurrentThread() { |
|
Lines 44-50
Link Here
|
| 44 |
} |
48 |
} |
| 45 |
|
49 |
|
| 46 |
protected void parse() { |
50 |
protected void parse() { |
| 47 |
List aList = new ArrayList(); |
51 |
List infoList = new ArrayList(); |
|
|
52 |
// Compile thread list information |
| 48 |
if (isDone()) { |
53 |
if (isDone()) { |
| 49 |
MIOutput out = getMIOutput(); |
54 |
MIOutput out = getMIOutput(); |
| 50 |
MIOOBRecord[] oobs = out.getMIOOBRecords(); |
55 |
MIOOBRecord[] oobs = out.getMIOOBRecords(); |
|
Lines 53-71
Link Here
|
| 53 |
MIStreamRecord cons = (MIStreamRecord) oobs[i]; |
58 |
MIStreamRecord cons = (MIStreamRecord) oobs[i]; |
| 54 |
String str = cons.getString(); |
59 |
String str = cons.getString(); |
| 55 |
// We are interested in finding the current thread |
60 |
// We are interested in finding the current thread |
| 56 |
parseThreadInfo(str.trim(), aList); |
61 |
parseThreadInfo(str.trim(), infoList); |
| 57 |
} |
62 |
} |
| 58 |
} |
63 |
} |
| 59 |
} |
64 |
} |
| 60 |
threadIds = new int[aList.size()]; |
65 |
// Sort information |
| 61 |
for (int i = 0; i < aList.size(); i++) { |
66 |
ThreadInfo[] infos = (ThreadInfo[]) infoList.toArray(new ThreadInfo[infoList.size()]); |
| 62 |
threadIds[i] = ((Integer) aList.get(i)).intValue(); |
67 |
Arrays.sort(infos, new ThreadInfoComparator()); |
|
|
68 |
// Extract information for quick reference |
| 69 |
threadIds = new int[infos.length]; |
| 70 |
threadNames = new String[infos.length]; |
| 71 |
for (int i = 0; i < infos.length; i++) { |
| 72 |
threadIds[i] = infos[i].threadId ; |
| 73 |
threadNames[i] = infos[i].threadName ; |
| 63 |
} |
74 |
} |
| 64 |
Arrays.sort(threadIds); |
|
|
| 65 |
} |
75 |
} |
| 66 |
|
76 |
|
| 67 |
protected void parseThreadInfo(String str, List aList) { |
77 |
/** |
|
|
78 |
* Make this method private because a private internal class is passed through the List |
| 79 |
* @param str The string with the thread information |
| 80 |
* @param infoList The list of ThreadInfo objects parsed. Another info object will be appended! |
| 81 |
*/ |
| 82 |
private void parseThreadInfo(String str, List infoList) { |
| 68 |
if (str.length() > 0) { |
83 |
if (str.length() > 0) { |
|
|
84 |
ThreadInfo info = new ThreadInfo(); |
| 69 |
boolean isCurrentThread = false; |
85 |
boolean isCurrentThread = false; |
| 70 |
// Discover the current thread |
86 |
// Discover the current thread |
| 71 |
if (str.charAt(0) == '*') { |
87 |
if (str.charAt(0) == '*') { |
|
Lines 81-93
Link Here
|
| 81 |
String number = str.substring(0, i); |
97 |
String number = str.substring(0, i); |
| 82 |
try { |
98 |
try { |
| 83 |
Integer num = Integer.valueOf(number); |
99 |
Integer num = Integer.valueOf(number); |
| 84 |
aList.add(num); |
100 |
info.threadId = num.intValue(); |
| 85 |
if (isCurrentThread) { |
101 |
if (isCurrentThread) { |
| 86 |
currentThreadId = num.intValue(); |
102 |
currentThreadId = info.threadId; |
| 87 |
} |
103 |
} |
| 88 |
} catch (NumberFormatException e) { |
104 |
} catch (NumberFormatException e) { |
| 89 |
} |
105 |
} |
| 90 |
} |
106 |
} |
|
|
107 |
// Probe for name |
| 108 |
// When no name is given we have the default empty string |
| 109 |
int nameFieldStartIndex = str.indexOf("Name: "); |
| 110 |
if (nameFieldStartIndex>0) { |
| 111 |
int nameStartIndex = nameFieldStartIndex + "Name: ".length(); |
| 112 |
int nameEndIndex = str.indexOf(",", nameStartIndex); |
| 113 |
info.threadName = str.substring(nameStartIndex, nameEndIndex); |
| 114 |
} |
| 115 |
infoList.add(info); |
| 91 |
} |
116 |
} |
| 92 |
} |
117 |
} |
|
|
118 |
|
| 119 |
/** |
| 120 |
* This is a minimal capsule class for thread related information |
| 121 |
*/ |
| 122 |
private class ThreadInfo { |
| 123 |
public ThreadInfo() { |
| 124 |
threadName = "" ; // avoid null pointer problems |
| 125 |
} |
| 126 |
public int threadId ; |
| 127 |
public String threadName ; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Sort ThreadInfo objects by thread id, ascending |
| 132 |
*/ |
| 133 |
private class ThreadInfoComparator implements Comparator { |
| 134 |
|
| 135 |
/* (non-Javadoc) |
| 136 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
| 137 |
*/ |
| 138 |
public int compare(Object arg0, Object arg1) { |
| 139 |
if (!(arg0 instanceof ThreadInfo) || !(arg1 instanceof ThreadInfo)) { |
| 140 |
IllegalArgumentException iae = new IllegalArgumentException("Illegal type (or null) for ThreadInfoComparator.compare()!"); |
| 141 |
iae.fillInStackTrace(); |
| 142 |
throw iae ; |
| 143 |
} |
| 144 |
ThreadInfo info0 = (ThreadInfo) arg0 ; |
| 145 |
ThreadInfo info1 = (ThreadInfo) arg1 ; |
| 146 |
|
| 147 |
return info0.threadId - info1.threadId ; |
| 148 |
} |
| 149 |
|
| 150 |
} |
| 93 |
} |
151 |
} |