1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Enable the use of GDBTypeParser to parse

the output of "ptype" and "whatis" from gdb
This commit is contained in:
Alain Magloire 2003-06-03 03:12:13 +00:00
parent 4b0f5e25f1
commit 7232c3d962
9 changed files with 101 additions and 49 deletions

View file

@ -231,7 +231,7 @@ public class GDBTypeParser {
c = getch(); c = getch();
} }
char character = (char) c; //char character = (char) c;
if (c == '(') { if (c == '(') {
if ((c = getch()) == ')') { if ((c = getch()) == ')') {
@ -296,7 +296,6 @@ public class GDBTypeParser {
} }
while (namp-- > 0) { while (namp-- > 0) {
prependChild(GDBType.REFERENCE); prependChild(GDBType.REFERENCE);
GDBDerivedType referenceType = new GDBDerivedType(genericType, GDBDerivedType.REFERENCE);
} }
} }
@ -338,7 +337,13 @@ public class GDBTypeParser {
} }
public static void main(String[] args) { public static void main(String[] args) {
GDBTypeParser parser = new GDBTypeParser(); GDBTypeParser parser = new GDBTypeParser();
System.out.println("struct link { int i; int j; struct link * next} *");
parser.parse("struct link { int i; int j; struct link * next} *");
System.out.println(parser.getGDBType());
System.out.println("char **argv"); System.out.println("char **argv");
parser.parse("unsigned long long int **argv"); parser.parse("unsigned long long int **argv");
System.out.println(parser.getGDBType()); System.out.println(parser.getGDBType());

View file

@ -12,13 +12,17 @@ import org.eclipse.cdt.debug.core.cdi.ICDISourceManager;
import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction; import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction;
import org.eclipse.cdt.debug.core.cdi.model.ICDIMixedInstruction; import org.eclipse.cdt.debug.core.cdi.model.ICDIMixedInstruction;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.mi.core.GDBTypeParser;
import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.MISession; import org.eclipse.cdt.debug.mi.core.MISession;
import org.eclipse.cdt.debug.mi.core.GDBTypeParser.GDBDerivedType;
import org.eclipse.cdt.debug.mi.core.GDBTypeParser.GDBType;
import org.eclipse.cdt.debug.mi.core.cdi.model.Instruction; import org.eclipse.cdt.debug.mi.core.cdi.model.Instruction;
import org.eclipse.cdt.debug.mi.core.cdi.model.MixedInstruction; import org.eclipse.cdt.debug.mi.core.cdi.model.MixedInstruction;
import org.eclipse.cdt.debug.mi.core.cdi.model.type.ArrayType; import org.eclipse.cdt.debug.mi.core.cdi.model.type.ArrayType;
import org.eclipse.cdt.debug.mi.core.cdi.model.type.BoolType; import org.eclipse.cdt.debug.mi.core.cdi.model.type.BoolType;
import org.eclipse.cdt.debug.mi.core.cdi.model.type.CharType; import org.eclipse.cdt.debug.mi.core.cdi.model.type.CharType;
import org.eclipse.cdt.debug.mi.core.cdi.model.type.DerivedType;
import org.eclipse.cdt.debug.mi.core.cdi.model.type.DoubleType; import org.eclipse.cdt.debug.mi.core.cdi.model.type.DoubleType;
import org.eclipse.cdt.debug.mi.core.cdi.model.type.EnumType; import org.eclipse.cdt.debug.mi.core.cdi.model.type.EnumType;
import org.eclipse.cdt.debug.mi.core.cdi.model.type.FloatType; import org.eclipse.cdt.debug.mi.core.cdi.model.type.FloatType;
@ -50,10 +54,12 @@ import org.eclipse.cdt.debug.mi.core.output.MISrcAsm;
public class SourceManager extends SessionObject implements ICDISourceManager { public class SourceManager extends SessionObject implements ICDISourceManager {
boolean autoupdate; boolean autoupdate;
GDBTypeParser gdbTypeParser;
public SourceManager(Session session) { public SourceManager(Session session) {
super(session); super(session);
autoupdate = false; autoupdate = false;
gdbTypeParser = new GDBTypeParser();
} }
/** /**
@ -224,25 +230,50 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
} }
String typename = name.trim(); String typename = name.trim();
// Check the derived types and agregate types // Parse the string.
if (typename.endsWith("]")) { GDBType gdbType = gdbTypeParser.parse(typename);
return new ArrayType(target, typename); Type type = null;
} else if (typename.endsWith("*")) {
return new PointerType(target, typename); for (Type aType = null; gdbType != null; type = aType) {
} else if (typename.endsWith("&")) { if (gdbType instanceof GDBDerivedType) {
return new ReferenceType(target, typename); switch(gdbType.getType()) {
} else if (typename.endsWith(")")) { case GDBType.ARRAY:
return new FunctionType(target, typename); int d = ((GDBDerivedType)gdbType).getDimension();
} else if (typename.startsWith("enum ")) { aType = new ArrayType(target, typename, d);
return new EnumType(target, typename); break;
} else if (typename.startsWith("union ")) { case GDBType.FUNCTION:
return new StructType(target, typename); aType = new FunctionType(target, typename);
} else if (typename.startsWith("struct ")) { break;
return new StructType(target, typename); case GDBType.POINTER:
} else if (typename.startsWith("class ")) { aType = new PointerType(target, typename);
return new StructType(target, typename); break;
case GDBType.REFERENCE:
aType = new ReferenceType(target, typename);
break;
}
gdbType = ((GDBDerivedType)gdbType).getChild();
} else {
aType = toCDIType(target, gdbType.toString());
gdbType = null;
}
if (type instanceof DerivedType) {
((DerivedType)type).setComponentType(aType);
}
} }
if (type != null) {
return type;
}
throw new CDIException("Unknown type");
}
Type toCDIType(ICDITarget target, String name) throws CDIException {
// Check the derived types and agregate types
if (name == null) {
name = new String();
}
String typename = name.trim();
// Check the primitives. // Check the primitives.
if (typename.equals("char")) { if (typename.equals("char")) {
return new CharType(target, typename); return new CharType(target, typename);
@ -268,6 +299,14 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
return new DoubleType(target, typename); return new DoubleType(target, typename);
} else if (typename.equals("void")) { } else if (typename.equals("void")) {
return new VoidType(target, typename); return new VoidType(target, typename);
} else if (typename.equals("enum")) {
return new EnumType(target, typename);
} else if (typename.equals("union")) {
return new StructType(target, typename);
} else if (typename.equals("struct")) {
return new StructType(target, typename);
} else if (typename.equals("class")) {
return new StructType(target, typename);
} }
StringTokenizer st = new StringTokenizer(typename); StringTokenizer st = new StringTokenizer(typename);
@ -286,12 +325,18 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
boolean isLong = (first.equals("long") || second.equals("long")); boolean isLong = (first.equals("long") || second.equals("long"));
boolean isShort = (first.equals("short") || second.equals("short")); boolean isShort = (first.equals("short") || second.equals("short"));
boolean isLongLong = (first.equals("long") && second.equals("long")); boolean isLongLong = (first.equals("long") && second.equals("long"));
boolean isDouble = (first.equals("double") || second.equals("double")); boolean isDouble = (first.equals("double") || second.equals("double"));
boolean isFloat = (first.equals("float") || second.equals("float")); boolean isFloat = (first.equals("float") || second.equals("float"));
boolean isComplex = (first.equals("complex") || second.equals("complex") || boolean isComplex = (first.equals("complex") || second.equals("complex") ||
first.equals("_Complex") || second.equals("_Complex")); first.equals("_Complex") || second.equals("_Complex"));
boolean isImaginery = (first.equals("_Imaginary") || second.equals("_Imaginary")); boolean isImaginery = (first.equals("_Imaginary") || second.equals("_Imaginary"));
boolean isStruct = first.equals("struct");
boolean isClass = first.equals("class");
boolean isUnion = first.equals("union");
boolean isEnum = first.equals("enum");
if (isChar && (isSigned || isUnsigned)) { if (isChar && (isSigned || isUnsigned)) {
return new CharType(target, typename, isUnsigned); return new CharType(target, typename, isUnsigned);
} else if (isShort && (isSigned || isUnsigned)) { } else if (isShort && (isSigned || isUnsigned)) {
@ -306,6 +351,14 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
return new DoubleType(target, typename, isComplex, isImaginery, isLong); return new DoubleType(target, typename, isComplex, isImaginery, isLong);
} else if (isFloat && (isComplex || isImaginery)) { } else if (isFloat && (isComplex || isImaginery)) {
return new FloatType(target, typename, isComplex, isImaginery); return new FloatType(target, typename, isComplex, isImaginery);
} else if (isStruct) {
return new StructType(target, typename);
} else if (isClass) {
return new StructType(target, typename);
} else if (isUnion) {
return new StructType(target, typename);
} else if (isEnum) {
return new EnumType(target, typename);
} }
} else if (count == 3) { } else if (count == 3) {
// ISOC allows permutation. replace short by: long or short // ISOC allows permutation. replace short by: long or short
@ -365,7 +418,6 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
throw new CDIException("Unknown type"); throw new CDIException("Unknown type");
} }
public String getDetailTypeName(String typename) throws CDIException { public String getDetailTypeName(String typename) throws CDIException {
try { try {
Session session = (Session)getSession(); Session session = (Session)getSession();

View file

@ -18,8 +18,19 @@ public class ArrayType extends DerivedType implements ICDIArrayType {
/** /**
* @param typename * @param typename
*/ */
public ArrayType(ICDITarget target, String typename) { public ArrayType(ICDITarget target, String typename,int dim) {
super(target, typename); super(target, typename);
dimension = dim;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType#getDimension()
*/
public int getDimension() {
if (derivedType == null) {
getComponentType();
}
return dimension;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -39,20 +50,9 @@ public class ArrayType extends DerivedType implements ICDIArrayType {
} }
name = orig.substring(0, lbracket).trim(); name = orig.substring(0, lbracket).trim();
} }
setDerivedType(name); setComponentType(name);
} }
return derivedType; return derivedType;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType#getDimension()
*/
public int getDimension() {
// Need to initialize.
if (derivedType == null) {
getComponentType();
}
return dimension;
}
} }

View file

@ -22,8 +22,11 @@ public abstract class DerivedType extends Type implements ICDIDerivedType {
super(target, typename); super(target, typename);
} }
public void setComponentType(ICDIType dtype) {
derivedType = dtype;
}
void setDerivedType(String name) { public void setComponentType(String name) {
ICDITarget target = getTarget(); ICDITarget target = getTarget();
Session session = (Session)(target.getSession()); Session session = (Session)(target.getSession());
SourceManager sourceMgr = (SourceManager)session.getSourceManager(); SourceManager sourceMgr = (SourceManager)session.getSourceManager();
@ -41,5 +44,4 @@ public abstract class DerivedType extends Type implements ICDIDerivedType {
derivedType = new IncompleteType(getTarget(), name); derivedType = new IncompleteType(getTarget(), name);
} }
} }
} }

View file

@ -32,15 +32,9 @@ public class FunctionType extends DerivedType implements ICDIFunctionType {
params = name.substring(lparen + 1, rparen).trim(); params = name.substring(lparen + 1, rparen).trim();
name = orig.substring(0, lparen).trim(); name = orig.substring(0, lparen).trim();
} }
setDerivedType(name); setComponentType(name);
} }
return derivedType; return derivedType;
} }
public String getArguments() {
if (derivedType != null) {
getComponentType();
}
return params;
}
} }

View file

@ -19,8 +19,8 @@ public class IntType extends IntegralType implements ICDIIntType {
this(target, typename, false); this(target, typename, false);
} }
public IntType(ICDITarget target, String typename, boolean usigned) { public IntType(ICDITarget target, String typename, boolean isUnsigned) {
super(target, typename, usigned); super(target, typename, isUnsigned);
} }
} }

View file

@ -14,9 +14,9 @@ public abstract class IntegralType extends Type implements ICDIIntegralType {
boolean unSigned; boolean unSigned;
public IntegralType(ICDITarget target, String typename, boolean usigned) { public IntegralType(ICDITarget target, String typename, boolean isUnsigned) {
super(target, typename); super(target, typename);
unSigned = usigned; unSigned = isUnsigned;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -17,7 +17,6 @@ public class PointerType extends DerivedType implements ICDIPointerType {
super(target, typename); super(target, typename);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIDerivedType#getComponentType() * @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIDerivedType#getComponentType()
*/ */
@ -30,7 +29,7 @@ public class PointerType extends DerivedType implements ICDIPointerType {
if (star != -1) { if (star != -1) {
name = orig.substring(0, star).trim(); name = orig.substring(0, star).trim();
} }
setDerivedType(name); setComponentType(name);
} }
return derivedType; return derivedType;
} }

View file

@ -32,7 +32,7 @@ public class ReferenceType extends DerivedType implements ICDIReferenceType {
if (amp != -1) { if (amp != -1) {
name = orig.substring(0, amp).trim(); name = orig.substring(0, amp).trim();
} }
setDerivedType(name); setComponentType(name);
} }
return derivedType; return derivedType;
} }