Browse Source

Cache variables for a Function;

Some bugfixes

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2285 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 19 years ago
parent
commit
0ec8985ebe
  1. 12
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs
  2. 62
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs
  3. 11
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs
  4. 30
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/DebugType-Helpers.cs
  5. 34
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/DebugType.cs
  6. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/PropertyInfo.cs
  7. 9
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/NamedValueCollection.cs
  8. 14
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/Value-Object.cs
  9. 12
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/Value.cs

12
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs

@ -213,16 +213,10 @@ namespace ICSharpCode.SharpDevelop.Services @@ -213,16 +213,10 @@ namespace ICSharpCode.SharpDevelop.Services
/// </summary>
public NamedValue GetVariableFromName(string variableName)
{
if (debuggedProcess == null || debuggedProcess.IsRunning) return null;
NamedValueCollection collection = debuggedProcess.LocalVariables;
if (collection == null) return null;
try {
return collection[variableName];
} catch (DebuggerException) {
if (debuggedProcess == null || debuggedProcess.IsRunning) {
return null;
} else {
return debuggedProcess.GetValue(variableName);
}
}

62
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs

@ -379,6 +379,25 @@ namespace Debugger @@ -379,6 +379,25 @@ namespace Debugger
}
}
/// <summary> Gets value of given name which is accessible from this function </summary>
/// <returns> Null if not found </returns>
public NamedValue GetValue(string name)
{
if (name == "this") {
return ThisValue;
}
if (Arguments.Contains(name)) {
return Arguments[name];
}
if (LocalVariables.Contains(name)) {
return LocalVariables[name];
}
if (ContaingClassVariables.Contains(name)) {
return ContaingClassVariables[name];
}
return null;
}
/// <summary>
/// Gets all variables in the lexical scope of the function.
/// That is, arguments, local variables and varables of the containing class.
@ -406,6 +425,8 @@ namespace Debugger @@ -406,6 +425,8 @@ namespace Debugger
}
}
NamedValue thisValueCache;
/// <summary>
/// Gets the instance of the class asociated with the current frame.
/// That is, 'this' in C#.
@ -413,13 +434,16 @@ namespace Debugger @@ -413,13 +434,16 @@ namespace Debugger
public NamedValue ThisValue {
get {
if (IsStatic) throw new DebuggerException("Static method does not have 'this'.");
return new NamedValue(
"this",
process,
new IExpirable[] {this},
new IMutable[] {},
delegate { return ThisCorValue; }
);
if (thisValueCache == null) {
thisValueCache = new NamedValue(
"this",
process,
new IExpirable[] {this},
new IMutable[] {},
delegate { return ThisCorValue; }
);
}
return thisValueCache;
}
}
@ -501,10 +525,20 @@ namespace Debugger @@ -501,10 +525,20 @@ namespace Debugger
}
}
NamedValueCollection argumentsCache;
/// <summary> Gets all arguments of the function. </summary>
public NamedValueCollection Arguments {
get {
return new NamedValueCollection(ArgumentsEnum);
if (argumentsCache == null) {
DateTime startTime = Util.HighPrecisionTimer.Now;
argumentsCache = new NamedValueCollection(ArgumentsEnum);
TimeSpan totalTime = Util.HighPrecisionTimer.Now - startTime;
process.TraceMessage("Loaded Arguments for " + this.ToString() + " (" + totalTime.TotalMilliseconds + " ms)");
}
return argumentsCache;
}
}
@ -516,10 +550,20 @@ namespace Debugger @@ -516,10 +550,20 @@ namespace Debugger
}
}
NamedValueCollection localVariablesCache;
/// <summary> Gets all local variables of the function. </summary>
public NamedValueCollection LocalVariables {
get {
return new NamedValueCollection(LocalVariablesEnum);
if (localVariablesCache == null) {
DateTime startTime = Util.HighPrecisionTimer.Now;
localVariablesCache = new NamedValueCollection(LocalVariablesEnum);
TimeSpan totalTime = Util.HighPrecisionTimer.Now - startTime;
process.TraceMessage("Loaded LocalVariables for " + this.ToString() + " (" + totalTime.TotalMilliseconds + " ms)");
}
return localVariablesCache;
}
}

11
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs

@ -249,5 +249,16 @@ namespace Debugger @@ -249,5 +249,16 @@ namespace Debugger
}
}
}
/// <summary> Gets value of given name which is accessible from selected function </summary>
/// <returns> Null if not found </returns>
public NamedValue GetValue(string name)
{
if (SelectedFunction == null || IsRunning) {
return null;
} else {
return SelectedFunction.GetValue(name);
}
}
}
}

30
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/DebugType-Helpers.cs

@ -14,7 +14,18 @@ namespace Debugger @@ -14,7 +14,18 @@ namespace Debugger
{
public partial class DebugType
{
IList<T> FilterMemberInfo<T>(List<T> input, BindingFlags bindingFlags) where T:MemberInfo
IList<T> FilterMemberInfo<T>(IList<T> input, string name) where T:MemberInfo
{
List<T> filtered = new List<T>();
foreach(T memberInfo in input) {
if (memberInfo.Name == name) {
filtered.Add(memberInfo);
}
}
return filtered.AsReadOnly();
}
IList<T> FilterMemberInfo<T>(IList<T> input, BindingFlags bindingFlags) where T:MemberInfo
{
List<T> filtered = new List<T>();
foreach(T memberInfo in input) {
@ -23,7 +34,7 @@ namespace Debugger @@ -23,7 +34,7 @@ namespace Debugger
if (memberInfo.IsPrivate && ((bindingFlags & BindingFlags.NonPublic) != 0) ||
memberInfo.IsPublic && ((bindingFlags & BindingFlags.Public) != 0)) {
filtered.Add(memberInfo);
}
}
@ -77,6 +88,21 @@ namespace Debugger @@ -77,6 +88,21 @@ namespace Debugger
return currModule.CorModule.GetClassFromToken(superToken);
}
// TypeSpec - generic class whith 'which'
if ((superToken & 0xFF000000) == 0x1B000000) {
// Walkaround - fake 'object' type
string fullTypeName = "System.Object";
foreach (Module superModule in process.Modules) {
try {
uint token = superModule.MetaData.FindTypeDefByName(fullTypeName, 0).Token;
return superModule.CorModule.GetClassFromToken(token);
} catch {
continue;
}
}
}
// TypeRef - Referencing to external assembly
if ((superToken & 0xFF000000) == 0x01000000) {
string fullTypeName = currModule.MetaData.GetTypeRefProps(superToken).Name;

34
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/DebugType.cs

@ -36,6 +36,7 @@ namespace Debugger @@ -36,6 +36,7 @@ namespace Debugger
List<FieldInfo> fields = new List<FieldInfo>();
List<MethodInfo> methods = new List<MethodInfo>();
List<PropertyInfo> properties = new List<PropertyInfo>();
List<MemberInfo> members = new List<MemberInfo>(); // All combined
// Stores all DebugType instances. FullName is the key
static Dictionary<string, List<DebugType>> loadedTypes = new Dictionary<string, List<DebugType>>();
@ -326,7 +327,9 @@ namespace Debugger @@ -326,7 +327,9 @@ namespace Debugger
Dictionary<string, object> propertyNames = new Dictionary<string, object>();
foreach(MethodInfo method in methods) {
if (method.IsSpecialName && (method.Name.StartsWith("get_") || method.Name.StartsWith("set_"))) {
accessors.Add(method.Name, method);
// There can be many get_Items
// TODO: This returns only last, return all
accessors[method.Name] = method;
propertyNames[method.Name.Remove(0,4)] = null;
}
}
@ -338,6 +341,17 @@ namespace Debugger @@ -338,6 +341,17 @@ namespace Debugger
accessors.TryGetValue("set_" + kvp.Key, out setter);
properties.Add(new PropertyInfo(this, getter, setter));
}
// Make a combined collection
foreach(FieldInfo field in fields) {
members.Add(field);
}
foreach(MemberInfo method in methods) {
members.Add(method);
}
foreach(PropertyInfo property in properties) {
members.Add(property);
}
}
/// <summary> Determines whether the current type is sublass of
@ -397,6 +411,24 @@ namespace Debugger @@ -397,6 +411,24 @@ namespace Debugger
return FilterMemberInfo(properties, bindingFlags);
}
/// <summary> Return all members that have spefied name and satisfy binding flags </summary>
public IList<MemberInfo> GetMember(string name, BindingFlags bindingFlags)
{
return FilterMemberInfo(FilterMemberInfo(members, name), bindingFlags);
}
/// <summary> Return all public members.</summary>
public IList<MemberInfo> GetMembers()
{
return GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
}
/// <summary> Return all members satisfing binding flags.</summary>
public IList<MemberInfo> GetMembers(BindingFlags bindingFlags)
{
return FilterMemberInfo(members, bindingFlags);
}
/// <summary> Compares two types </summary>
public override bool Equals(object obj)
{

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/PropertyInfo.cs

@ -98,7 +98,7 @@ namespace Debugger @@ -98,7 +98,7 @@ namespace Debugger
this.Process,
dependencies.ToArray(),
dependencies.ToArray(),
delegate { return getMethod.Invoke(objectInstance, parameters).CorValue; }
delegate { return getMethod.Invoke(objectInstance, parameters).RawCorValue; }
);
}

9
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/NamedValueCollection.cs

@ -48,6 +48,15 @@ namespace Debugger @@ -48,6 +48,15 @@ namespace Debugger
}
}
/// <summary>
/// Gets a value indicating whether the collection contains a
/// value with a given name
/// </summary>
public bool Contains(string name)
{
return hashtable.ContainsKey(name);
}
/// <summary>
/// Gets number of <see cref="Debugger.NamedValue">named values</see> contained in the collection
/// </summary>

14
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/Value-Object.cs

@ -36,7 +36,19 @@ namespace Debugger @@ -36,7 +36,19 @@ namespace Debugger
/// </summary>
public NamedValue GetMember(string name)
{
return GetMembers()[name];
DebugType currentType = this.Type;
while (currentType != null) {
foreach(MemberInfo memberInfo in currentType.GetMember(name, BindingFlags.All)) {
if (memberInfo is FieldInfo) {
((FieldInfo)memberInfo).GetValue(this);
}
if (memberInfo is PropertyInfo) {
((PropertyInfo)memberInfo).GetValue(this);
}
}
currentType = currentType.BaseType;
}
throw new DebuggerException("Member " + name + " was not found");
}
/// <summary>

12
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/Value.cs

@ -107,6 +107,12 @@ namespace Debugger @@ -107,6 +107,12 @@ namespace Debugger
}
}
internal ICorDebugValue RawCorValue {
get {
return Cache.RawCorValue;
}
}
internal ICorDebugValue CorValue {
get {
return Cache.CorValue;
@ -123,12 +129,6 @@ namespace Debugger @@ -123,12 +129,6 @@ namespace Debugger
}
}
ICorDebugValue RawCorValue {
get {
return Cache.RawCorValue;
}
}
internal ICorDebugValue SoftReference {
get {
if (this.HasExpired) throw new DebuggerException("CorValue has expired");

Loading…
Cancel
Save