1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core.cdi.model;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType;
import org.eclipse.cdt.debug.mi.core.cdi.ExpressionManager;
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.model.type.IncompleteType;
import org.eclipse.cdt.debug.mi.core.cdi.model.type.Type;
/**
*/
public class Expression extends CObject implements ICDIExpression {
private static int ID_COUNT = 0;
private int id;
String fExpression;
Type fType;
Variable fVariable;
ICDIStackFrame fContext;
public Expression(Target target, String ex) {
super(target);
fExpression = ex;
id = ++ID_COUNT;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpression#getExpressionText()
*/
public String getExpressionText() {
return fExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpression#equals(org.eclipse.cdt.debug.core.cdi.model.ICDIExpression)
*/
public boolean equals(ICDIExpression obj) {
if (obj instanceof Expression) {
Expression other = (Expression)obj;
return other.id == id;
}
return false;
}
/**
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIVariable#getType()
*/
public ICDIType getType(ICDIStackFrame frame) throws CDIException {
Type type = null;
Target target = (Target)getTarget();
Session session = (Session) (target.getSession());
SourceManager sourceMgr = session.getSourceManager();
String nametype = sourceMgr.getTypeNameFromVariable((StackFrame)frame, getExpressionText());
try {
type = sourceMgr.getType(target, nametype);
} catch (CDIException e) {
// Try with ptype.
try {
String ptype = sourceMgr.getDetailTypeName(target, nametype);
type = sourceMgr.getType(target, ptype);
} catch (CDIException ex) {
// Some version of gdb does not work with the name of the class
// ex: class data foo --> ptype data --> fails
// ex: class data foo --> ptype foo --> succeed
try {
String ptype = sourceMgr.getDetailTypeNameFromVariable((StackFrame)frame, getExpressionText());
type = sourceMgr.getType(target, ptype);
} catch (CDIException e2) {
// give up.
}
}
}
if (type == null) {
type = new IncompleteType(target, nametype);
}
return type;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpression#getValue(org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame)
*/
public ICDIValue getValue(ICDIStackFrame context) throws CDIException {
Session session = (Session)getTarget().getSession();
ExpressionManager mgr = session.getExpressionManager();
if (fVariable != null && fContext != null && !context.equals(fContext))
{ // Get rid of the underlying variable if the context has changed.
// This is defensive, in practice each stack frame has it's own
// list of expressions.
mgr.deleteVariable(fVariable);
fVariable = null;
}
if (fVariable == null)
{ // Reuse the variable so we don't have to ask gdb to create another one. Bug 150565.
fVariable = mgr.createVariable((StackFrame)context, getExpressionText());
}
fContext = context;
return fVariable.getValue();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.cdi.model.ICDIExpression#dispose()
*/
public void dispose() throws CDIException {
Session session = (Session)getTarget().getSession();
ExpressionManager mgr = session.getExpressionManager();
mgr.destroyExpressions((Target)getTarget(), new Expression[] {this});
if (fVariable != null)
mgr.deleteVariable(fVariable);
}
}
|