1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 02:36:01 +02:00

Patch form chris songer deals with sparse output

in the MI format
This commit is contained in:
Alain Magloire 2003-08-19 02:38:41 +00:00
parent 8043fd6640
commit e7f524f9e1
2 changed files with 33 additions and 8 deletions

View file

@ -62,11 +62,13 @@ public class RegisterManager extends SessionObject implements ICDIRegisterManage
throw new CDIException("No answer"); throw new CDIException("No answer");
} }
String[] names = info.getRegisterNames(); String[] names = info.getRegisterNames();
RegisterObject[] regs = new RegisterObject[names.length]; List regsList = new ArrayList(names.length);
for (int i = 0; i < names.length; i++) { for (int i = 0; i < names.length; i++) {
regs[i] = new RegisterObject(session.getCurrentTarget(), names[i], i); if (names[i].length() > 0) {
regsList.add(new RegisterObject(session.getCurrentTarget(), names[i], i));
}
} }
return regs; return (ICDIRegisterObject[])regsList.toArray(new ICDIRegisterObject[0]);
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} }

View file

@ -14,12 +14,18 @@ import java.util.List;
public class MIDataListRegisterNamesInfo extends MIInfo { public class MIDataListRegisterNamesInfo extends MIInfo {
String[] names; String[] names;
protected int realNameCount = 0;
public MIDataListRegisterNamesInfo(MIOutput rr) { public MIDataListRegisterNamesInfo(MIOutput rr) {
super(rr); super(rr);
} }
public String[] getRegisterNames () { /**
* @return the list of register names. This list can include 0 length
* strings in the case where the underlying GDB has a sparse set of
* registers. They are returned as 0 length strings
*/
public String[] getRegisterNames() {
if (names == null) { if (names == null) {
parse(); parse();
} }
@ -32,30 +38,47 @@ public class MIDataListRegisterNamesInfo extends MIInfo {
MIOutput out = getMIOutput(); MIOutput out = getMIOutput();
MIResultRecord rr = out.getMIResultRecord(); MIResultRecord rr = out.getMIResultRecord();
if (rr != null) { if (rr != null) {
MIResult[] results = rr.getMIResults(); MIResult[] results = rr.getMIResults();
for (int i = 0; i < results.length; i++) { for (int i = 0; i < results.length; i++) {
String var = results[i].getVariable(); String var = results[i].getVariable();
if (var.equals("register-names")) { if (var.equals("register-names")) {
MIValue value = results[i].getMIValue(); MIValue value = results[i].getMIValue();
if (value instanceof MIList) { if (value instanceof MIList) {
parseRegisters((MIList)value, aList); parseRegisters((MIList) value, aList);
} }
} }
} }
} }
} }
names = (String[])aList.toArray(new String[aList.size()]); names = (String[]) aList.toArray(new String[aList.size()]);
} }
void parseRegisters(MIList list, List aList) { void parseRegisters(MIList list, List aList) {
MIValue[] values = list.getMIValues(); MIValue[] values = list.getMIValues();
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
if (values[i] instanceof MIConst) { if (values[i] instanceof MIConst) {
String str = ((MIConst)values[i]).getCString(); String str = ((MIConst) values[i]).getCString();
/* this cannot filter nulls because index is critical in retreival
* and index is assigned in the layers above. The MI spec allows
* empty returns, for some register names. */
if (str != null && str.length() > 0) { if (str != null && str.length() > 0) {
realNameCount++;
aList.add(str); aList.add(str);
} else {
aList.add("");
} }
} }
} }
} }
/**
* @return the number of non-null and non-empty names in the
* register list
*/
public int getNumRealNames() {
if (names == null)
parse();
return realNameCount;
}
} }