~ubuntu-branches/ubuntu/lucid/monodevelop/lucid

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/SoftDebuggerAdaptor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-02-02 11:39:59 UTC
  • mfrom: (1.2.6 upstream) (1.3.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100202113959-s4exdz7er7igylz2
Tags: 2.2.1+dfsg-1
* New upstream release
* debian/control:
  + Standards version 3.8.4 (no changes needed)
* debian/patches/remove_support_for_non_debian_functionality.patch,
  debian/patches/remove_support_for_soft_debugger.patch,
  debian/patches/remove_support_for_moonlight.patch,
  debian/rules:
  + Split patch into two pieces, to make it easier to enable either
    SDB or Moonlight support with a rebuild
* debian/monodevelop-moonlight.install,
  debian/monodevelop-debugger-sdb.install,
  debian/control:
  + Create packaging data for the Soft Debugger addin and Moonlight addin -
    and comment them out of debian/control as we can't provide them on
    Debian for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
using System.Text;
34
34
using System.Reflection;
35
35
using ST = System.Threading;
 
36
using Mono.Debugging.Backend;
36
37
 
37
38
namespace MonoDevelop.Debugger.Soft
38
39
{
70
71
                                        return res.Value;
71
72
                                }
72
73
                        }
 
74
                        else if ((obj is StructMirror) && cx.Options.AllowTargetInvoke) {
 
75
                                StructMirror ob = (StructMirror) obj;
 
76
                                MethodMirror method = OverloadResolve (cx, "ToString", ob.Type, new TypeMirror[0], true, false, false);
 
77
                                if (method != null && method.DeclaringType.FullName != "System.ValueType") {
 
78
                                        StringMirror res = (StringMirror) cx.RuntimeInvoke (method, obj, new Value[0]);
 
79
                                        return res.Value;
 
80
                                }
 
81
                        }
73
82
                        return GetDisplayTypeName (GetValueTypeName (ctx, obj));
74
83
                }
75
84
 
76
 
 
77
 
                public override object Cast (EvaluationContext ctx, object obj, object targetType)
 
85
                public override object TryConvert (EvaluationContext ctx, object obj, object targetType)
78
86
                {
79
 
                        if (obj == null)
80
 
                                return null;
81
87
                        object res = TryCast (ctx, obj, targetType);
82
88
                        if (res != null)
83
89
                                return res;
84
 
                        else
85
 
                                throw new EvaluatorException ("Can't cast an object of type '{0}' to type '{1}'", GetValueTypeName (ctx, obj), GetTypeName (ctx, targetType));
 
90
                        if (obj == null)
 
91
                                return null;
 
92
                        object otype = GetValueType (ctx, obj);
 
93
                        if (otype is Type) {
 
94
                                if (targetType is TypeMirror)
 
95
                                        targetType = Type.GetType (((TypeMirror)targetType).FullName, false);
 
96
                                Type tt = targetType as Type;
 
97
                                if (tt != null) {
 
98
                                        try {
 
99
                                                if (obj is PrimitiveValue)
 
100
                                                        obj = ((PrimitiveValue)obj).Value;
 
101
                                                res = System.Convert.ChangeType (obj, tt);
 
102
                                                return CreateValue (ctx, res);
 
103
                                        } catch {
 
104
                                        }
 
105
                                }
 
106
                        }
 
107
                        return null;
86
108
                }
87
109
 
88
110
                public override object TryCast (EvaluationContext ctx, object obj, object targetType)
93
115
                        if (otype is TypeMirror) {
94
116
                                if ((targetType is TypeMirror) && ((TypeMirror)targetType).IsAssignableFrom ((TypeMirror)otype))
95
117
                                        return obj;
 
118
                                // Try casting the primitive type of the enum
 
119
                                EnumMirror em = obj as EnumMirror;
 
120
                                if (em != null)
 
121
                                        return TryCast (ctx, CreateValue (ctx, em.Value), targetType);
96
122
                        } else if (otype is Type) {
97
 
                                if (targetType is TypeMirror)
 
123
                                if (targetType is TypeMirror) {
 
124
                                        TypeMirror tm = (TypeMirror) targetType;
 
125
                                        if (tm.IsEnum) {
 
126
                                                // TODO: convert to enum
 
127
                                        }
98
128
                                        targetType = Type.GetType (((TypeMirror)targetType).FullName, false);
99
 
                                if ((targetType is Type) && ((Type)targetType).IsAssignableFrom ((Type)otype))
100
 
                                        return obj;
 
129
                                }
 
130
                                Type tt = targetType as Type;
 
131
                                if (tt != null) {
 
132
                                        if (tt.IsAssignableFrom ((Type)otype))
 
133
                                                return obj;
 
134
                                        if (obj is PrimitiveValue)
 
135
                                                obj = ((PrimitiveValue)obj).Value;
 
136
                                        if (tt != typeof(string) && !(obj is string)) {
 
137
                                                try {
 
138
                                                        object res = System.Convert.ChangeType (obj, tt);
 
139
                                                        return CreateValue (ctx, res);
 
140
                                                } catch {
 
141
                                                }
 
142
                                        }
 
143
                                }
101
144
                        }
102
145
                        return null;
103
146
                }
362
405
                {
363
406
                        SoftEvaluationContext ctx = (SoftEvaluationContext) gctx;
364
407
                        
365
 
                        TypeMirror[] types = new TypeMirror [argTypes.Length];
366
 
                        for (int n=0; n<argTypes.Length; n++)
367
 
                                types [n] = (TypeMirror) argTypes [n];
 
408
                        TypeMirror[] types;
 
409
                        if (argTypes == null)
 
410
                                types = new TypeMirror [0];
 
411
                        else {
 
412
                                types = new TypeMirror [argTypes.Length];
 
413
                                for (int n=0; n<argTypes.Length; n++) {
 
414
                                        if (argTypes [n] is TypeMirror)
 
415
                                                types [n] = (TypeMirror) argTypes [n];
 
416
                                        else
 
417
                                                types [n] = (TypeMirror) GetType (ctx, ((Type)argTypes[n]).FullName);
 
418
                                }
 
419
                        }
368
420
                        
369
421
                        MethodMirror met = OverloadResolve (ctx, methodName, (TypeMirror) targetType, types, (flags & BindingFlags.Instance) != 0, (flags & BindingFlags.Static) != 0, false);
370
422
                        return met != null;
406
458
                {
407
459
                        return val is EnumMirror;
408
460
                }
409
 
 
 
461
                
410
462
                protected override TypeDisplayData OnGetTypeDisplayData (EvaluationContext gctx, object type)
411
463
                {
412
464
                        SoftEvaluationContext ctx = (SoftEvaluationContext) gctx;
424
476
                                        DebuggerTypeProxyAttribute at = BuildAttribute<DebuggerTypeProxyAttribute> (attr);
425
477
                                        td.ProxyType = at.ProxyTypeName;
426
478
                                        if (!string.IsNullOrEmpty (td.ProxyType))
427
 
                                                ForceLoadType (ctx, t, td.ProxyType);
 
479
                                                ForceLoadType (ctx, td.ProxyType);
428
480
                                }
429
481
                        }
430
482
                        foreach (FieldInfoMirror fi in t.GetFields ()) {
461
513
                        return default(T);
462
514
                }
463
515
                
464
 
                void ForceLoadType (SoftEvaluationContext ctx, TypeMirror helperType, string typeName)
 
516
                public override object ForceLoadType (EvaluationContext gctx, string typeName)
465
517
                {
 
518
                        // Shortcut to avoid a target invoke in case the type is already loaded
 
519
                        object t = GetType (gctx, typeName);
 
520
                        if (t != null)
 
521
                                return t;
 
522
                        
 
523
                        SoftEvaluationContext ctx = (SoftEvaluationContext) gctx;
466
524
                        if (!ctx.Options.AllowTargetInvoke)
467
 
                                return;
468
 
                        TypeMirror tm = helperType.GetTypeObject ().Type;
469
 
                        TypeMirror[] ats = new TypeMirror[] { ctx.Session.GetType ("System.String") };
 
525
                                return null;
 
526
                        TypeMirror tm = (TypeMirror) ctx.Thread.Type.GetTypeObject ().Type;
 
527
                        TypeMirror stype = ctx.Session.GetType ("System.String");
 
528
                        if (stype == null) {
 
529
                                // If the string type is not loaded, we need to get it in another way
 
530
                                StringMirror ss = ctx.Thread.Domain.CreateString ("");
 
531
                                stype = ss.Type;
 
532
                        }
 
533
                        TypeMirror[] ats = new TypeMirror[] { stype };
470
534
                        MethodMirror met = OverloadResolve (ctx, "GetType", tm, ats, false, true, true);
471
 
                        tm.InvokeMethod (ctx.Thread, met, new Value[] {(Value) CreateValue (ctx, typeName)});
472
 
                        ctx.Session.StackVersion++;
 
535
                        try {
 
536
                                tm.InvokeMethod (ctx.Thread, met, new Value[] {(Value) CreateValue (ctx, typeName)});
 
537
                        } catch {
 
538
                                return null;
 
539
                        } finally {
 
540
                                ctx.Session.StackVersion++;
 
541
                        }
 
542
                        return GetType (ctx, typeName);
473
543
                }
 
544
 
474
545
                
475
546
                T BuildAttribute<T> (CustomAttributeDataMirror attr)
476
547
                {
649
720
                                return ((StringMirror)obj).Value;
650
721
                        else if (obj is EnumMirror) {
651
722
                                EnumMirror eob = (EnumMirror) obj;
652
 
                                return new LiteralExp (eob.StringValue);
 
723
                                return new EvaluationResult (eob.Type.FullName + "." + eob.StringValue, eob.StringValue);
653
724
                        }
654
725
                        else if (obj is PrimitiveValue)
655
726
                                return ((PrimitiveValue)obj).Value;
707
778
                                exception = ex;
708
779
                        } catch (Exception ex) {
709
780
                                ctx.Session.StackVersion++;
710
 
                                MonoDevelop.Core.LoggingService.LogError ("Error in soft debugger method call thread", ex);
 
781
                                MonoDevelop.Core.LoggingService.LogError ("Error in soft debugger method call thread on " + GetInfo (), ex);
711
782
                                exception = ex;
712
783
                        }
713
784
                }
735
806
                        } catch (InvocationException ex) {
736
807
                                exception = ex;
737
808
                        } catch (Exception ex) {
738
 
                                MonoDevelop.Core.LoggingService.LogError ("Error in soft debugger method call thread", ex);
 
809
                                MonoDevelop.Core.LoggingService.LogError ("Error in soft debugger method call thread on " + GetInfo (), ex);
739
810
                                exception = ex;
740
811
                        } finally {
741
812
                                ctx.Session.StackVersion++;
742
813
                        }
743
814
                }
 
815
                
 
816
                string GetInfo ()
 
817
                {
 
818
                        try {
 
819
                                TypeMirror type = null;
 
820
                                if (obj is ObjectMirror)
 
821
                                        type = ((ObjectMirror)obj).Type;
 
822
                                else if (obj is TypeMirror)
 
823
                                        type = (TypeMirror)obj;
 
824
                                else if (obj is StructMirror)
 
825
                                        type = ((StructMirror)obj).Type;
 
826
                                return string.Format ("method {0} on object {1}",
 
827
                                                      function == null? "[null]" : function.FullName,
 
828
                                                      type == null? "[null]" : type.FullName);
 
829
                        } catch (Exception ex) {
 
830
                                MonoDevelop.Core.LoggingService.LogError ("Error getting info for SDB MethodCall", ex);
 
831
                                return "";
 
832
                        }
 
833
                }
744
834
 
745
835
                public override bool WaitForCompleted (int timeout)
746
836
                {