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:
parent
4b0f5e25f1
commit
7232c3d962
9 changed files with 101 additions and 49 deletions
|
@ -231,7 +231,7 @@ public class GDBTypeParser {
|
|||
c = getch();
|
||||
}
|
||||
|
||||
char character = (char) c;
|
||||
//char character = (char) c;
|
||||
|
||||
if (c == '(') {
|
||||
if ((c = getch()) == ')') {
|
||||
|
@ -296,7 +296,6 @@ public class GDBTypeParser {
|
|||
}
|
||||
while (namp-- > 0) {
|
||||
prependChild(GDBType.REFERENCE);
|
||||
GDBDerivedType referenceType = new GDBDerivedType(genericType, GDBDerivedType.REFERENCE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,7 +337,13 @@ public class GDBTypeParser {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
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");
|
||||
parser.parse("unsigned long long int **argv");
|
||||
System.out.println(parser.getGDBType());
|
||||
|
|
|
@ -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.ICDIMixedInstruction;
|
||||
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.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.MixedInstruction;
|
||||
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.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.EnumType;
|
||||
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 {
|
||||
|
||||
boolean autoupdate;
|
||||
GDBTypeParser gdbTypeParser;
|
||||
|
||||
public SourceManager(Session session) {
|
||||
super(session);
|
||||
autoupdate = false;
|
||||
gdbTypeParser = new GDBTypeParser();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,25 +230,50 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
|
|||
}
|
||||
String typename = name.trim();
|
||||
|
||||
// Check the derived types and agregate types
|
||||
if (typename.endsWith("]")) {
|
||||
return new ArrayType(target, typename);
|
||||
} else if (typename.endsWith("*")) {
|
||||
return new PointerType(target, typename);
|
||||
} else if (typename.endsWith("&")) {
|
||||
return new ReferenceType(target, typename);
|
||||
} else if (typename.endsWith(")")) {
|
||||
return new FunctionType(target, typename);
|
||||
} else if (typename.startsWith("enum ")) {
|
||||
return new EnumType(target, typename);
|
||||
} else if (typename.startsWith("union ")) {
|
||||
return new StructType(target, typename);
|
||||
} else if (typename.startsWith("struct ")) {
|
||||
return new StructType(target, typename);
|
||||
} else if (typename.startsWith("class ")) {
|
||||
return new StructType(target, typename);
|
||||
// Parse the string.
|
||||
GDBType gdbType = gdbTypeParser.parse(typename);
|
||||
Type type = null;
|
||||
|
||||
for (Type aType = null; gdbType != null; type = aType) {
|
||||
if (gdbType instanceof GDBDerivedType) {
|
||||
switch(gdbType.getType()) {
|
||||
case GDBType.ARRAY:
|
||||
int d = ((GDBDerivedType)gdbType).getDimension();
|
||||
aType = new ArrayType(target, typename, d);
|
||||
break;
|
||||
case GDBType.FUNCTION:
|
||||
aType = new FunctionType(target, typename);
|
||||
break;
|
||||
case GDBType.POINTER:
|
||||
aType = new PointerType(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.
|
||||
if (typename.equals("char")) {
|
||||
return new CharType(target, typename);
|
||||
|
@ -268,6 +299,14 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
|
|||
return new DoubleType(target, typename);
|
||||
} else if (typename.equals("void")) {
|
||||
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);
|
||||
|
@ -286,12 +325,18 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
|
|||
boolean isLong = (first.equals("long") || second.equals("long"));
|
||||
boolean isShort = (first.equals("short") || second.equals("short"));
|
||||
boolean isLongLong = (first.equals("long") && second.equals("long"));
|
||||
|
||||
boolean isDouble = (first.equals("double") || second.equals("double"));
|
||||
boolean isFloat = (first.equals("float") || second.equals("float"));
|
||||
boolean isComplex = (first.equals("complex") || second.equals("complex") ||
|
||||
first.equals("_Complex") || second.equals("_Complex"));
|
||||
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)) {
|
||||
return new CharType(target, typename, 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);
|
||||
} else if (isFloat && (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) {
|
||||
// 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");
|
||||
}
|
||||
|
||||
|
||||
public String getDetailTypeName(String typename) throws CDIException {
|
||||
try {
|
||||
Session session = (Session)getSession();
|
||||
|
|
|
@ -18,8 +18,19 @@ public class ArrayType extends DerivedType implements ICDIArrayType {
|
|||
/**
|
||||
* @param typename
|
||||
*/
|
||||
public ArrayType(ICDITarget target, String typename) {
|
||||
public ArrayType(ICDITarget target, String typename,int dim) {
|
||||
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)
|
||||
|
@ -39,20 +50,9 @@ public class ArrayType extends DerivedType implements ICDIArrayType {
|
|||
}
|
||||
name = orig.substring(0, lbracket).trim();
|
||||
}
|
||||
setDerivedType(name);
|
||||
setComponentType(name);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,8 +22,11 @@ public abstract class DerivedType extends Type implements ICDIDerivedType {
|
|||
super(target, typename);
|
||||
}
|
||||
|
||||
public void setComponentType(ICDIType dtype) {
|
||||
derivedType = dtype;
|
||||
}
|
||||
|
||||
void setDerivedType(String name) {
|
||||
public void setComponentType(String name) {
|
||||
ICDITarget target = getTarget();
|
||||
Session session = (Session)(target.getSession());
|
||||
SourceManager sourceMgr = (SourceManager)session.getSourceManager();
|
||||
|
@ -41,5 +44,4 @@ public abstract class DerivedType extends Type implements ICDIDerivedType {
|
|||
derivedType = new IncompleteType(getTarget(), name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,15 +32,9 @@ public class FunctionType extends DerivedType implements ICDIFunctionType {
|
|||
params = name.substring(lparen + 1, rparen).trim();
|
||||
name = orig.substring(0, lparen).trim();
|
||||
}
|
||||
setDerivedType(name);
|
||||
setComponentType(name);
|
||||
}
|
||||
return derivedType;
|
||||
}
|
||||
|
||||
public String getArguments() {
|
||||
if (derivedType != null) {
|
||||
getComponentType();
|
||||
}
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ public class IntType extends IntegralType implements ICDIIntType {
|
|||
this(target, typename, false);
|
||||
}
|
||||
|
||||
public IntType(ICDITarget target, String typename, boolean usigned) {
|
||||
super(target, typename, usigned);
|
||||
public IntType(ICDITarget target, String typename, boolean isUnsigned) {
|
||||
super(target, typename, isUnsigned);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ public abstract class IntegralType extends Type implements ICDIIntegralType {
|
|||
|
||||
boolean unSigned;
|
||||
|
||||
public IntegralType(ICDITarget target, String typename, boolean usigned) {
|
||||
public IntegralType(ICDITarget target, String typename, boolean isUnsigned) {
|
||||
super(target, typename);
|
||||
unSigned = usigned;
|
||||
unSigned = isUnsigned;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -17,7 +17,6 @@ public class PointerType extends DerivedType implements ICDIPointerType {
|
|||
super(target, typename);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @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) {
|
||||
name = orig.substring(0, star).trim();
|
||||
}
|
||||
setDerivedType(name);
|
||||
setComponentType(name);
|
||||
}
|
||||
return derivedType;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class ReferenceType extends DerivedType implements ICDIReferenceType {
|
|||
if (amp != -1) {
|
||||
name = orig.substring(0, amp).trim();
|
||||
}
|
||||
setDerivedType(name);
|
||||
setComponentType(name);
|
||||
}
|
||||
return derivedType;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue