mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Fix to PR 60020.
GDB returns the children when a pointer points to a structure. Also ignore the keyword "const" when parsing. * cdi/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java * cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java * src/org/eclipse/cdt/debug/mi/core/GDBTypeParser.java
This commit is contained in:
parent
6dc35eb0c0
commit
f9065c3dda
5 changed files with 79 additions and 43 deletions
|
@ -1,3 +1,15 @@
|
||||||
|
2004-05-28 Alain Magloire
|
||||||
|
|
||||||
|
Fix to PR 60020.
|
||||||
|
GDB returns the children when a pointer
|
||||||
|
points to a structure.
|
||||||
|
Also ignore the keyword "const" when parsing.
|
||||||
|
|
||||||
|
* cdi/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java
|
||||||
|
* cdi/org/eclipse/cdt/debug/mi/core/cdi/model/Variable.java
|
||||||
|
* cdi/org/eclipse/cdt/debug/mi/core/cdi/model/VariableObject.java
|
||||||
|
* src/org/eclipse/cdt/debug/mi/core/GDBTypeParser.java
|
||||||
|
|
||||||
2004-05-18 Alain Magloire
|
2004-05-18 Alain Magloire
|
||||||
|
|
||||||
Remove dependencies on the compatibility plugin
|
Remove dependencies on the compatibility plugin
|
||||||
|
|
|
@ -42,11 +42,13 @@ import org.eclipse.cdt.debug.mi.core.command.MIDataDisassemble;
|
||||||
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory;
|
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory;
|
||||||
import org.eclipse.cdt.debug.mi.core.command.MIGDBShowDirectories;
|
import org.eclipse.cdt.debug.mi.core.command.MIGDBShowDirectories;
|
||||||
import org.eclipse.cdt.debug.mi.core.command.MIPType;
|
import org.eclipse.cdt.debug.mi.core.command.MIPType;
|
||||||
|
import org.eclipse.cdt.debug.mi.core.command.MIWhatis;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIAsm;
|
import org.eclipse.cdt.debug.mi.core.output.MIAsm;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIDataDisassembleInfo;
|
import org.eclipse.cdt.debug.mi.core.output.MIDataDisassembleInfo;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIGDBShowDirectoriesInfo;
|
import org.eclipse.cdt.debug.mi.core.output.MIGDBShowDirectoriesInfo;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIPTypeInfo;
|
import org.eclipse.cdt.debug.mi.core.output.MIPTypeInfo;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MISrcAsm;
|
import org.eclipse.cdt.debug.mi.core.output.MISrcAsm;
|
||||||
|
import org.eclipse.cdt.debug.mi.core.output.MIWhatisInfo;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,7 +242,12 @@ public class SourceManager extends Manager implements ICDISourceManager {
|
||||||
}
|
}
|
||||||
gdbType = ((GDBDerivedType)gdbType).getChild();
|
gdbType = ((GDBDerivedType)gdbType).getChild();
|
||||||
} else {
|
} else {
|
||||||
aType = toCDIType(target, gdbType.toString());
|
//try {
|
||||||
|
aType = toCDIType(target, gdbType.toString());
|
||||||
|
//} catch (CDIException e) {
|
||||||
|
// String ptype = getDetailTypeName(gdbType.toString());
|
||||||
|
// aType = getType(target, ptype);
|
||||||
|
//}
|
||||||
gdbType = null;
|
gdbType = null;
|
||||||
}
|
}
|
||||||
if (type instanceof DerivedType) {
|
if (type instanceof DerivedType) {
|
||||||
|
@ -426,4 +433,21 @@ public class SourceManager extends Manager implements ICDISourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTypeName(String variable) throws CDIException {
|
||||||
|
try {
|
||||||
|
Session session = (Session) getSession();
|
||||||
|
MISession mi = session.getMISession();
|
||||||
|
CommandFactory factory = mi.getCommandFactory();
|
||||||
|
MIWhatis whatis = factory.createMIWhatis(variable);
|
||||||
|
mi.postCommand(whatis);
|
||||||
|
MIWhatisInfo info = whatis.getMIWhatisInfo();
|
||||||
|
if (info == null) {
|
||||||
|
throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
return info.getType();
|
||||||
|
} catch (MIException e) {
|
||||||
|
throw new MI2CDIException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ public class Variable extends VariableObject implements ICDIVariable {
|
||||||
for (int i = 0; i < vars.length; i++) {
|
for (int i = 0; i < vars.length; i++) {
|
||||||
String fn= getFullName();
|
String fn= getFullName();
|
||||||
String childName = vars[i].getExp();
|
String childName = vars[i].getExp();
|
||||||
String childTypename = null;
|
ICDIType childType = null;
|
||||||
boolean childFake = false;
|
boolean childFake = false;
|
||||||
ICDIType t = getType();
|
ICDIType t = getType();
|
||||||
if (t instanceof ICDIArrayType) {
|
if (t instanceof ICDIArrayType) {
|
||||||
|
@ -174,7 +174,22 @@ public class Variable extends VariableObject implements ICDIVariable {
|
||||||
int index = castingIndex + i;
|
int index = castingIndex + i;
|
||||||
childName = getName() + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
childName = getName() + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
} else if (t instanceof ICDIPointerType) {
|
} else if (t instanceof ICDIPointerType) {
|
||||||
fn = "*(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$
|
ICDIType subType = ((ICDIPointerType)t).getComponentType();
|
||||||
|
if (subType instanceof ICDIStructType) {
|
||||||
|
if (isCPPLanguage()) {
|
||||||
|
if (!isFake()
|
||||||
|
|| (isFake() && !(name.equals("private") || name.equals("public") || name.equals("protected")))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
childFake = true;
|
||||||
|
childType = t;
|
||||||
|
} else {
|
||||||
|
fn = "(" + fn + ")->" + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
|
} else { // If not C++ language
|
||||||
|
fn = "(" + fn + ")->" + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fn = "*(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
} else if (t instanceof ICDIStructType) {
|
} else if (t instanceof ICDIStructType) {
|
||||||
if (isCPPLanguage()) {
|
if (isCPPLanguage()) {
|
||||||
// For C++ in GDB the children of the
|
// For C++ in GDB the children of the
|
||||||
|
@ -196,7 +211,7 @@ public class Variable extends VariableObject implements ICDIVariable {
|
||||||
if (!isFake()
|
if (!isFake()
|
||||||
|| (isFake() && !(name.equals("private") || name.equals("public") || name.equals("protected")))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|| (isFake() && !(name.equals("private") || name.equals("public") || name.equals("protected")))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
childFake = true;
|
childFake = true;
|
||||||
childTypename = getTypeName();
|
childType = t;
|
||||||
} else {
|
} else {
|
||||||
fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
|
fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
|
@ -205,9 +220,9 @@ public class Variable extends VariableObject implements ICDIVariable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Variable v = new Variable(getTarget(), childName, fn, getStackFrame(), getPosition(), getStackDepth(), vars[i]);
|
Variable v = new Variable(getTarget(), childName, fn, getStackFrame(), getPosition(), getStackDepth(), vars[i]);
|
||||||
if (childTypename != null) {
|
if (childType != null) {
|
||||||
// Hack to reset the typename to a known value
|
// Hack to reset the typename to a known value
|
||||||
v.typename = childTypename;
|
v.type = childType;
|
||||||
}
|
}
|
||||||
v.setIsFake(childFake);
|
v.setIsFake(childFake);
|
||||||
children[i] = v;
|
children[i] = v;
|
||||||
|
@ -222,20 +237,6 @@ public class Variable extends VariableObject implements ICDIVariable {
|
||||||
return miVar.getNumChild();
|
return miVar.getNumChild();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* We overload the VariableObject since the gdb-varobject already knows
|
|
||||||
* the type and its probably more accurate.
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject#getTypeName()
|
|
||||||
*/
|
|
||||||
public String getTypeName() throws CDIException {
|
|
||||||
// We overload here not to use the whatis command.
|
|
||||||
if (typename == null) {
|
|
||||||
typename = miVar.getType();
|
|
||||||
}
|
|
||||||
return typename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getValue()
|
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getValue()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,12 +22,9 @@ import org.eclipse.cdt.debug.mi.core.cdi.MI2CDIException;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.Session;
|
import org.eclipse.cdt.debug.mi.core.cdi.Session;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.SourceManager;
|
import org.eclipse.cdt.debug.mi.core.cdi.SourceManager;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.model.type.IncompleteType;
|
import org.eclipse.cdt.debug.mi.core.cdi.model.type.IncompleteType;
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.model.type.Type;
|
|
||||||
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
|
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
|
||||||
import org.eclipse.cdt.debug.mi.core.command.MIDataEvaluateExpression;
|
import org.eclipse.cdt.debug.mi.core.command.MIDataEvaluateExpression;
|
||||||
import org.eclipse.cdt.debug.mi.core.command.MIWhatis;
|
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIDataEvaluateExpressionInfo;
|
import org.eclipse.cdt.debug.mi.core.output.MIDataEvaluateExpressionInfo;
|
||||||
import org.eclipse.cdt.debug.mi.core.output.MIWhatisInfo;
|
|
||||||
import org.eclipse.cdt.debug.mi.core.cdi.CdiResources;
|
import org.eclipse.cdt.debug.mi.core.cdi.CdiResources;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +43,7 @@ public class VariableObject extends CObject implements ICDIVariableObject {
|
||||||
|
|
||||||
String qualifiedName = null;
|
String qualifiedName = null;
|
||||||
String fullName = null;
|
String fullName = null;
|
||||||
Type type = null;
|
ICDIType type = null;
|
||||||
String typename = null;
|
String typename = null;
|
||||||
String sizeof = null;
|
String sizeof = null;
|
||||||
|
|
||||||
|
@ -159,7 +156,7 @@ public class VariableObject extends CObject implements ICDIVariableObject {
|
||||||
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();
|
||||||
String nametype = getTypeName();
|
String nametype = sourceMgr.getTypeName(getQualifiedName());
|
||||||
try {
|
try {
|
||||||
type = sourceMgr.getType(target, nametype);
|
type = sourceMgr.getType(target, nametype);
|
||||||
} catch (CDIException e) {
|
} catch (CDIException e) {
|
||||||
|
@ -168,6 +165,15 @@ public class VariableObject extends CObject implements ICDIVariableObject {
|
||||||
String ptype = sourceMgr.getDetailTypeName(nametype);
|
String ptype = sourceMgr.getDetailTypeName(nametype);
|
||||||
type = sourceMgr.getType(target, ptype);
|
type = sourceMgr.getType(target, ptype);
|
||||||
} catch (CDIException ex) {
|
} catch (CDIException ex) {
|
||||||
|
// Some version of gdb does not work woth the name of the class
|
||||||
|
// ex: class data foo --> ptype data --> fails
|
||||||
|
// ex: class data foo --> ptype foo --> succeed
|
||||||
|
try {
|
||||||
|
String ptype = sourceMgr.getDetailTypeName(getQualifiedName());
|
||||||
|
type = sourceMgr.getType(target, ptype);
|
||||||
|
} catch (CDIException e2) {
|
||||||
|
// give up.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
|
@ -236,21 +242,8 @@ public class VariableObject extends CObject implements ICDIVariableObject {
|
||||||
*/
|
*/
|
||||||
public String getTypeName() throws CDIException {
|
public String getTypeName() throws CDIException {
|
||||||
if (typename == null) {
|
if (typename == null) {
|
||||||
try {
|
ICDIType theType = getType();
|
||||||
ICDITarget target = getTarget();
|
typename = theType.getTypeName();
|
||||||
Session session = (Session) (target.getSession());
|
|
||||||
MISession mi = session.getMISession();
|
|
||||||
CommandFactory factory = mi.getCommandFactory();
|
|
||||||
MIWhatis whatis = factory.createMIWhatis(getQualifiedName());
|
|
||||||
mi.postCommand(whatis);
|
|
||||||
MIWhatisInfo info = whatis.getMIWhatisInfo();
|
|
||||||
if (info == null) {
|
|
||||||
throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
typename = info.getType();
|
|
||||||
} catch (MIException e) {
|
|
||||||
throw new MI2CDIException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return typename;
|
return typename;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.debug.mi.core;
|
package org.eclipse.cdt.debug.mi.core;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GDB Type Parser.
|
* GDB Type Parser.
|
||||||
* The code was lifted from: The C Programming Language
|
* The code was lifted from: The C Programming Language
|
||||||
|
@ -53,6 +55,7 @@ public class GDBTypeParser {
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
s = new String();
|
s = new String();
|
||||||
}
|
}
|
||||||
|
s = Pattern.compile("\\bconst\\b").matcher(s).replaceAll("");
|
||||||
s = s.trim();
|
s = s.trim();
|
||||||
|
|
||||||
// Initialize.
|
// Initialize.
|
||||||
|
@ -70,10 +73,13 @@ public class GDBTypeParser {
|
||||||
|
|
||||||
// Hack for GDB, the typename can be something like
|
// Hack for GDB, the typename can be something like
|
||||||
// class A : public B, C { ... } *
|
// class A : public B, C { ... } *
|
||||||
// We are only interreste in "class A"
|
// We are only interested in "class A"
|
||||||
|
// Carefull for class A::data
|
||||||
int column = dataType.indexOf(':');
|
int column = dataType.indexOf(':');
|
||||||
if (column > 0) {
|
if (column > 0) {
|
||||||
dataType = dataType.substring(0, column);
|
if ((column + 1) < dataType.length() && dataType.charAt(column + 1) != ':') {
|
||||||
|
dataType = dataType.substring(0, column);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
genericType = new GDBType(dataType);
|
genericType = new GDBType(dataType);
|
||||||
|
|
||||||
|
@ -220,7 +226,7 @@ public class GDBTypeParser {
|
||||||
// GDB hack accept ':' ',' part of the GDB hacks
|
// GDB hack accept ':' ',' part of the GDB hacks
|
||||||
// when doing ptype gdb returns "class A : public C { ..}"
|
// when doing ptype gdb returns "class A : public C { ..}"
|
||||||
boolean isCIdentifierPart(int c) {
|
boolean isCIdentifierPart(int c) {
|
||||||
if ((c >= '0' && c <= 9) || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') {
|
if ((c >= '0' && c <= 9) || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || c == ':') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue