mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-15 20:25:46 +02:00
implements gdb "info threads" parsing
This commit is contained in:
parent
13020cbc3c
commit
dae454d929
1 changed files with 81 additions and 0 deletions
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.mi.core.output;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GDB/MI thread list parsing.
|
||||||
|
~"\n"
|
||||||
|
~" 2 Thread 2049 (LWP 29354) "
|
||||||
|
~"* 1 Thread 1024 (LWP 29353) "
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class MIInfoThreadsInfo extends MIInfo {
|
||||||
|
|
||||||
|
int[] threadIds;
|
||||||
|
int currentThreadId;
|
||||||
|
|
||||||
|
public MIInfoThreadsInfo(MIOutput out) {
|
||||||
|
super(out);
|
||||||
|
parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getThreadIds() {
|
||||||
|
return threadIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentThread() {
|
||||||
|
return currentThreadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse() {
|
||||||
|
List aList = new ArrayList();
|
||||||
|
if (isDone()) {
|
||||||
|
MIOutput out = getMIOutput();
|
||||||
|
MIOOBRecord[] oobs = out.getMIOOBRecords();
|
||||||
|
for (int i = 0; i < oobs.length; i++) {
|
||||||
|
if (oobs[i] instanceof MIConsoleStreamOutput) {
|
||||||
|
MIStreamRecord cons = (MIStreamRecord) oobs[i];
|
||||||
|
String str = cons.getString();
|
||||||
|
// We are interested in finding the current thread
|
||||||
|
parseThreadInfo(str.trim(), aList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
threadIds = new int[aList.size()];
|
||||||
|
for (int i = 0; i < aList.size(); i++) {
|
||||||
|
threadIds[i] = ((Integer) aList.get(i)).intValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void parseThreadInfo(String str, List aList) {
|
||||||
|
if (str.length() > 0) {
|
||||||
|
boolean isCurrentThread = false;
|
||||||
|
// Discover the current thread
|
||||||
|
if (str.charAt(0) == '*') {
|
||||||
|
isCurrentThread = true;
|
||||||
|
str = str.substring(1).trim();
|
||||||
|
}
|
||||||
|
// Fetch the threadId
|
||||||
|
if (str.length() > 0 && Character.isDigit(str.charAt(0))) {
|
||||||
|
int i = 1;
|
||||||
|
while (i < str.length() && Character.isDigit(str.charAt(i))) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
String number = str.substring(0, i);
|
||||||
|
try {
|
||||||
|
Integer num = Integer.valueOf(number);
|
||||||
|
aList.add(num);
|
||||||
|
if (isCurrentThread) {
|
||||||
|
currentThreadId = num.intValue();
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue