Example #1
0
 private void DebugProc(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam)
 {
     string msg = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(message, length);
     Console.WriteLine(
         "{0} {1} {2} {3}: {4}",
         source, type, id, severity, msg);
 }
Example #2
0
 private static void DebugCallback(DebugSource source, DebugType type, int id,
 DebugSeverity severity, int length, IntPtr message, IntPtr userParam)
 {
     string msg = Marshal.PtrToStringAnsi(message);
     Console.WriteLine("[GL] {0}; {1}; {2}; {3}; {4}",
         source, type, id, severity, msg);
 }
 static void PCCallbackHandler(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam)
 {
     if (severity == DebugSeverity.DebugSeverityHigh || severity == DebugSeverity.DebugSeverityMedium)
     {
         string msg = Marshal.PtrToStringAnsi(message);
         Console.WriteLine("[GL] {0}; {1}; {2}; {3}; {4}", source, type, id, severity, msg);
     }
 }
		/// <summary>
		/// Creates an expression which, when evaluated, creates a List&lt;T&gt; in the debugee
		/// filled with contents of IEnumerable&lt;T&gt; from the debugee.
		/// </summary>
		/// <param name="iEnumerableVariable">Expression for IEnumerable variable in the debugee.</param>
		/// <param name="itemType">
		/// The generic argument of IEnumerable&lt;T&gt; that <paramref name="iEnumerableVariable"/> implements.</param>
		public static Expression CreateDebugListExpression(Expression iEnumerableVariable, DebugType itemType, out DebugType listType)
		{
			// is using itemType.AppDomain ok?
			listType = DebugType.CreateFromType(itemType.AppDomain, typeof(System.Collections.Generic.List<>), itemType);
			var iEnumerableType = DebugType.CreateFromType(itemType.AppDomain, typeof(IEnumerable<>), itemType);
			// explicitely cast the variable to IEnumerable<T>, where T is itemType
			Expression iEnumerableVariableExplicitCast = new CastExpression(iEnumerableType.GetTypeReference() , iEnumerableVariable, CastType.Cast);
			return new ObjectCreateExpression(listType.GetTypeReference(), iEnumerableVariableExplicitCast.ToList());
		}
Example #5
0
        public LogEntry(char TypeId, string Tag, int Pid, string Message)
        {
            this.LogType = GetDebugTypeFromIdentifier(TypeId);

            if (this.LogType == DebugType.Unknown)
                throw new Exception("Unknown DebugType identifier");

            this.LogTag = Tag;
            this.Pid = Pid;
            this.LogMsg = Message;
        }
Example #6
0
        internal static void Debug(DebugType type, string s, params object[] args)
        {
            if (!Configuration.Debug.Contains(DebugType.All) &&
                !Configuration.Debug.Contains(type))
            {
                return;
            }

            string message = Output.Format(s, args);
            Console.WriteLine(message);
        }
Example #7
0
        /// <summary>
        /// Creates an expression which, when evaluated, creates a List&lt;T&gt; in the debugee
        /// filled with contents of IEnumerable&lt;T&gt; from the debugee.
        /// </summary>
        /// <param name="iEnumerableVariable">Expression for IEnumerable variable in the debugee.</param>
        /// <param name="itemType">
        /// The generic argument of IEnumerable&lt;T&gt; that <paramref name="iEnumerableVariable"/> implements.</param>
        public static Expression CreateDebugListExpression(Expression iEnumerableVariable, DebugType itemType, out DebugType listType)
        {
            // is using itemType.AppDomain ok?
            listType = DebugType.CreateFromType(itemType.AppDomain, typeof(System.Collections.Generic.List<>), itemType);
            var iEnumerableType = DebugType.CreateFromType(itemType.AppDomain, typeof(IEnumerable<>), itemType);
            // explicitely cast the variable to IEnumerable<T>, where T is itemType
            Expression iEnumerableVariableExplicitCast = new CastExpression { Expression = iEnumerableVariable.Clone() , Type = iEnumerableType.GetTypeReference() };

            var obj = new ObjectCreateExpression() { Type = listType.GetTypeReference() };
            obj.Arguments.Add(iEnumerableVariableExplicitCast);

            return obj;
        }
Example #8
0
        public DebugRect(Point _Center, Point _Offset, int _Width, int _Height, DebugType _Type, Game _Game)
            : base(_Game)
        {
            Offset = _Offset;
            Color Color = Color.HotPink;
            switch (_Type)
            {
                case DebugType.View: { Color = Color.Blue; } break;
                case DebugType.Physics: { Color = Color.White; } break;
                case DebugType.Hostile: { Color = Color.Red; } break;
                case DebugType.Trigger: { Color = Color.Yellow; } break;
            }

            RectangeGraphic = new RectangeGraphic(new Rectangle(_Center.X - Offset.X, _Center.Y - Offset.Y, _Width, _Height), 3, Color, _Game);
        }
Example #9
0
 /// <summary>
 /// 输出 debug 日志
 /// </summary>
 /// <param name="msg">输入内容</param>
 /// <param name="logType">输出的类型</param>
 private static void WriteDebug(object msg, DebugType logType)
 {
     if (!LCSConfig.IsDebugMode) return;
     switch (logType)
     {
         case DebugType.Log:
             UnityEngine.Debug.Log(msg);
             break;
         case DebugType.Warning:
             UnityEngine.Debug.LogWarning(msg);
             break;
         case DebugType.Error:
             UnityEngine.Debug.LogError(msg);
             break;
     }
 }
Example #10
0
        internal Value(AppDomain appDomain, ICorDebugValue corValue)
        {
            if (corValue == null)
                throw new ArgumentNullException("corValue");
            this.appDomain = appDomain;
            this.corValue = corValue;
            this.corValue_pauseSession = this.Process.PauseSession;

            this.isNull = corValue is ICorDebugReferenceValue && ((ICorDebugReferenceValue)corValue).IsNull() != 0;

            if (corValue is ICorDebugReferenceValue &&
                ((ICorDebugReferenceValue)corValue).GetValue() == 0 &&
                ((ICorDebugValue2)corValue).GetExactType() == null)
            {
                // We were passed null reference and no metadata description
                // (happens during CreateThread callback for the thread object)
                this.type = appDomain.ObjectType;
            } else {
                ICorDebugType exactType = ((ICorDebugValue2)this.CorValue).GetExactType();
                this.type = DebugType.CreateFromCorType(appDomain, exactType);
            }
        }
Example #11
0
        void EvaluateExpression()
        {
            evaluated = true;

            Value val;
            try {
                var frame = WindowsDebugger.DebuggedProcess.SelectedThread.MostRecentStackFrame;
                var key = frame.MethodInfo.ToMethodKey();
                // get the target name
                int index = Name.IndexOf('.');
                string targetName = Name;
                if (index != -1) {
                    targetName = Name.Substring(0, index);
                }

                // get local variable index
                MemberMapping mapping;
                var textView = MainWindow.Instance.ActiveTextView;
                var cm = textView == null ? null : textView.CodeMappings;
                if (cm != null && cm.TryGetValue(key, out mapping)) {
                    var variable = mapping.LocalVariables == null ? null : mapping.LocalVariables.FirstOrDefault(v => v.Name == targetName);
                    if (variable != null && variable.OriginalVariable != null) {
                        if (expression is MemberReferenceExpression) {
                            var memberExpression = (MemberReferenceExpression)expression;
                            memberExpression.Target.AddAnnotation(new [] { variable.OriginalVariable.Index });
                        } else {
                            expression.AddAnnotation(new [] { variable.OriginalVariable.Index });
                        }
                    }
                }

                // evaluate expression
                val = expression.Evaluate(WindowsDebugger.DebuggedProcess);
            } catch (GetValueException e) {
                error = e;
                this.Text = e.Message;
                return;
            }

            this.canSetText = val.Type.IsPrimitive || val.Type.FullName == typeof(string).FullName;

            this.expressionType = val.Type;
            this.Type = val.Type.Name;
            this.valueIsNull = val.IsNull;

            // Note that these return enumerators so they are lazy-evaluated
            if (val.IsNull) {
            } else if (val.Type.IsPrimitive || val.Type.FullName == typeof(string).FullName) { // Must be before IsClass
            } else if (val.Type.IsArray) { // Must be before IsClass
                if (val.ArrayLength > 0)
                    this.ChildNodes = Utils.LazyGetChildNodesOfArray(this.Expression, val.ArrayDimensions);
            } else if (val.Type.IsClass || val.Type.IsValueType) {
                if (val.Type.FullNameWithoutGenericArguments == typeof(List<>).FullName) {
                    if ((int)val.GetMemberValue("_size").PrimitiveValue > 0)
                        this.ChildNodes = Utils.LazyGetItemsOfIList(this.expression);
                } else {
                    this.ChildNodes = Utils.LazyGetChildNodesOfObject(this.Expression, val.Type);
                }
            } else if (val.Type.IsPointer) {
                Value deRef = val.Dereference();
                if (deRef != null) {
                    this.ChildNodes = new ExpressionNode [] { new ExpressionNode(this.ImageSource, "*" + this.Name, this.Expression.AppendDereference()) };
                }
            }

            //			if (DebuggingOptions.Instance.ICorDebugVisualizerEnabled) {
            //				TreeNode info = ICorDebug.GetDebugInfoRoot(val.AppDomain, val.CorValue);
            //				this.ChildNodes = Utils.PrependNode(info, this.ChildNodes);
            //			}

            // Do last since it may expire the object
            if (val.Type.IsInteger) {
                fullText = FormatInteger(val.PrimitiveValue);
            } else if (val.Type.IsPointer) {
                fullText = String.Format("0x{0:X}", val.PointerAddress);
            } else if ((val.Type.FullName == typeof(string).FullName ||
                        val.Type.FullName == typeof(char).FullName) && !val.IsNull) {
                try {
                    fullText = '"' + Escape(val.InvokeToString()) + '"';
                } catch (GetValueException e) {
                    error = e;
                    fullText = e.Message;
                    return;
                }
            } else if ((val.Type.IsClass || val.Type.IsValueType) && !val.IsNull) {
                try {
                    fullText = val.InvokeToString();
                } catch (GetValueException e) {
                    error = e;
                    fullText = e.Message;
                    return;
                }
            } else {
                fullText = val.AsString();
            }

            this.Text = (fullText.Length > 256) ? fullText.Substring(0, 256) + "…" : fullText;
        }
 /// <summary>
 /// Changes the properties of an array of debug message ids.
 /// This might be source, type, severity or just enable/disable them.
 /// Enables or Disables an array of Debug Messages ids
 /// </summary>
 /// <param name="source">Source of ids.</param>
 /// <param name="type">Type of ids</param>
 /// <param name="severity">Severity of ids.</param>
 /// <param name="ids">array of ids to change.</param>
 /// <param name="Enabled">Enables or disables the ids.</param>
 public static void DebugMessageControlARB(DebugSource source, DebugType type, DebugSeverity severity, uint[] ids, bool Enabled)
 {
     Delegates.glDebugMessageControlARB(source, type, severity, ids.Length, ref ids[0], Enabled);
 }
 /// <summary>
 /// Insert a new debug message in the debug message log array.
 /// </summary>
 /// <param name="source">Source of inserted message.</param>
 /// <param name="type">type of inserted message.</param>
 /// <param name="id">id of inserted message. Userid has own range of ids.</param>
 /// <param name="severity">Severity of inserted message.</param>
 /// <param name="Text">The text of inserted message.</param>
 public static void DebugMessageInsertARB(DebugSource source, DebugType type, uint id, DebugSeverity severity, string Text)
 {
     Delegates.glDebugMessageInsertARB(source, type, id, severity, Text.Length, Text);
 }
Example #14
0
		public static IEnumerable<TreeNode> LazyGetChildNodesOfObject(Expression targetObject, DebugType shownType)
		{
			MemberInfo[] publicStatic      = shownType.GetFieldsAndNonIndexedProperties(BindingFlags.Public    | BindingFlags.Static   | BindingFlags.DeclaredOnly);
			MemberInfo[] publicInstance    = shownType.GetFieldsAndNonIndexedProperties(BindingFlags.Public    | BindingFlags.Instance | BindingFlags.DeclaredOnly);
			MemberInfo[] nonPublicStatic   = shownType.GetFieldsAndNonIndexedProperties(BindingFlags.NonPublic | BindingFlags.Static   | BindingFlags.DeclaredOnly);
			MemberInfo[] nonPublicInstance = shownType.GetFieldsAndNonIndexedProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
			
			DebugType baseType = (DebugType)shownType.BaseType;
			if (baseType != null) {
				yield return new TreeNode(
					ImageService.GetImage("Icons.16x16.Class"),
					"BaseClass",
					baseType.Name,
					baseType.FullName,
					baseType.FullName == "System.Object" ? null : Utils.LazyGetChildNodesOfObject(targetObject, baseType)
				);
			}
			
			if (nonPublicInstance.Length > 0) {
				yield return new TreeNode(
					null,
					"NonPublicMembers",
					string.Empty,
					string.Empty,
					Utils.LazyGetMembersOfObject(targetObject, nonPublicInstance)
				);
			}
			
			if (publicStatic.Length > 0 || nonPublicStatic.Length > 0) {
				IEnumerable<TreeNode> childs = Utils.LazyGetMembersOfObject(targetObject, publicStatic);
				if (nonPublicStatic.Length > 0) {
					TreeNode nonPublicStaticNode = new TreeNode(
						null,
						"NonPublicStaticMembers",
						string.Empty,
						string.Empty,
						Utils.LazyGetMembersOfObject(targetObject, nonPublicStatic)
					);
					childs = Utils.PrependNode(nonPublicStaticNode, childs);
				}
				yield return new TreeNode(
					null,
					"StaticMembers",
					string.Empty,
					string.Empty,
					childs
				);
			}
			
			DebugType iListType = (DebugType)shownType.GetInterface(typeof(IList).FullName);
			if (iListType != null) {
				yield return new IListNode(targetObject);
			} else {
				DebugType iEnumerableType, itemType;
				if (shownType.ResolveIEnumerableImplementation(out iEnumerableType, out itemType)) {
					yield return new IEnumerableNode(targetObject, itemType);
				}
			}
			
			foreach(TreeNode node in LazyGetMembersOfObject(targetObject, publicInstance)) {
				yield return node;
			}
		}
        /// <summary>
        /// Retrives a number of messages from message log.
        /// How many retrives is determined by Math.Min([all arrays]) and availible messages.
        /// </summary>
        /// <param name="sources"></param>
        /// <param name="types"></param>
        /// <param name="ids"></param>
        /// <param name="severities"></param>
        /// <param name="lengths"></param>
        /// <param name="messageLog">A single preallocated stringbuilder with enough capacity to contain all the messages?</param>
        /// <returns></returns>
        public static uint GetDebugMessageLogARB(DebugSource[] sources, DebugType[] types, uint[] ids, DebugSeverity[] severities, int[] lengths, StringBuilder messageLog)
        {
            var count = Math.Min(sources.Length, Math.Min(types.Length, Math.Min(ids.Length, Math.Min(severities.Length, lengths.Length))));

            return Delegates.glGetDebugMessageLogARB((uint)count, messageLog.Capacity, ref sources[0], ref types[0], ref ids[0], ref severities[0], ref lengths[0], messageLog);
        }
Example #16
0
 public static void LogWarning(DebugType debugType, object message, params object[] arguments)
 {
     if(EnumExtensions.IsFlagSet(DebugType.Warning, debugType)) {
         Debug.LogWarning(string.Format(message.ToString(), arguments));
     }
 }
Example #17
0
		public static Eval AsyncNewObjectNoConstructor(DebugType debugType)
		{
			return new Eval(
				debugType.AppDomain,
				"New object: " + debugType.FullName,
				delegate(Eval eval) {
					eval.CorEval2.NewParameterizedObjectNoConstructor(debugType.CorType.GetClass(), (uint)debugType.GetGenericArguments().Length, debugType.GenericArgumentsAsCorDebugType);
				}
			);
		}
		TypedValue EvaluateAs(INode expression, DebugType type)
		{
			TypedValue val = Evaluate(expression);
			if (val.Type == type)
				return val;
			if (!val.Type.CanImplicitelyConvertTo(type))
				throw new EvaluateException(expression, "Can not implicitely cast {0} to {1}", val.Type.FullName, type.FullName);
			if (type.IsPrimitive) {
				object oldVal = val.PrimitiveValue;
				object newVal;
				try {
					newVal = Convert.ChangeType(oldVal, type.PrimitiveType);
				} catch (InvalidCastException) {
					throw new EvaluateException(expression, "Can not cast {0} to {1}", val.GetType().FullName, type.FullName);
				} catch (OverflowException) {
					throw new EvaluateException(expression, "Overflow");
				}
				return CreateValue(newVal);
			} else {
				return new TypedValue(val.Value, type);
			}
		}
		public TypedValue(Value value, DebugType type)
		{
			this.value = value;
			this.type = type;
		}
Example #20
0
        /// <summary>
        /// Retrives a number of messages from message log and return the messages in array.
        /// </summary>
        /// <param name="sources"></param>
        /// <param name="types"></param>
        /// <param name="ids"></param>
        /// <param name="severities"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static string[] GetDebugMessageLog(DebugSource[] sources, DebugType[] types, uint[] ids, DebugSeverity[] severities, int count = -1)
        {
            if (count == -1)
            {
                count = GetIntegerv(GetParameters.DebugLoggedMessages);
            }
            else
                count = Math.Min(sources.Length, Math.Min(types.Length, Math.Min(ids.Length, severities.Length))); // , MessageLogs.Length))));

            var maxmessagelength = GetIntegerv(GetParameters.MaxDebugMessageLength);
            var sb = new StringBuilder(count * maxmessagelength + 4);

            var lengths = new int[count];

            var result = (int)Delegates.glGetDebugMessageLog((uint)count, sb.Capacity - 2, ref sources[0], ref types[0], ref ids[0], ref severities[0], ref lengths[0], sb);

            if (result > 0)
            {
                var messages = new string[Math.Min(result, lengths.Length)];
                int lastpos = 0;
                for (int i = 0; i < messages.Length; i++)
                {
                    messages[i] = sb.ToString(lastpos, lengths[i] - 1);
                    lastpos = lengths[i];
                }

                return messages;
            }
            else
                return new string[0];
        }
Example #21
0
 private bool DoMatchForLogType(DebugType type)
 {
     switch (Oper)
     {
         case FilterOperator.Equal:
             return ((DebugType)Value) == type;
         case FilterOperator.NotEqual:
             return ((DebugType)Value) != type;
         default:
             return false;
     }
 }
Example #22
0
		public static Value NewObjectNoConstructor(DebugType debugType)
		{
			return AsyncNewObjectNoConstructor(debugType).WaitForResult();
		}
Example #23
0
 public Operation SetDebug(string file, int line, int col, DebugType type, string data)
 {
     this.Debug = string.Format("{0}:{1}.{2}:{3}:{4}", file, line, col, type, data);
     return this;
 }
Example #24
0
		public static Value NewArray(DebugType type, uint length, uint? lowerBound)
		{
			return AsyncNewArray(type, length, lowerBound).WaitForResult();
		}
Example #25
0
 public static void LogError(DebugType debugType, object message)
 {
     if(EnumExtensions.IsFlagSet(DebugType.Error, debugType)) {
         Debug.LogError(message);
     }
 }
        /// <summary>
        /// Bind properties.
        /// </summary>
        protected override void BindProperties()
        {
            if (this.ProjectMgr == null)
            {
                return;
            }
            string type = "";
            type= getCfgString(nameof(DebugType), DebugType.none.ToString());
            if (type != null && type.Length > 0)
            {
                try
                {
                    this.debugtype = (DebugType)Enum.Parse(typeof(DebugType), type);
                }
                catch (ArgumentException)
                {
                    this.debugtype = DebugType.none;
                }
            }
            debuggercommand = getCfgString(nameof(DebuggerCommand), "$(TargetPath)");
            debuggercommandarguments = getCfgString(nameof(DebuggerCommandArguments),  "");
            debuggerworkingdirectory= getCfgString(nameof(DebuggerWorkingDirectory),  "");
            debuggerattach= getCfgLogic(nameof(DebuggerAttach),  false);
            enableunmanageddebugging = getCfgLogic(nameof(EnableUnmanagedDebugging),  true);
            usevshostingprocess = getCfgLogic(nameof(UseVSHostingProcess),  true);

        }
Example #27
0
 public static void LogWarning(DebugType debugType, object message)
 {
     if(EnumExtensions.IsFlagSet(DebugType.Warning, debugType)) {
         Debug.LogWarning(message);
     }
 }
Example #28
0
 protected void OnDebugFps(bool enabled)
 {
     _debugType = enabled ? DebugType.Fps : DebugType.None;
 }
Example #29
0
		public static Eval AsyncNewObjectNoConstructor(DebugType debugType)
		{
			return CreateEval(
				debugType.Process,
				"New object: " + debugType.FullName,
				delegate(Eval eval) {
					eval.CorEval.CastTo<ICorDebugEval2>().NewParameterizedObjectNoConstructor(debugType.CorType.Class, (uint)debugType.GenericArguments.Count, debugType.GenericArgumentsAsCorDebugType);
				}
			);
		}
Example #30
0
		public static Eval AsyncNewArray(DebugType type, uint length, uint? lowerBound)
		{
			lowerBound = lowerBound ?? 0;
			return new Eval(
				type.AppDomain,
				"New array: " + type + "[" + length + "]",
				delegate(Eval eval) {
					// Multi-dimensional arrays not supported in .NET 2.0
					eval.CorEval2.NewParameterizedArray(type.CorType, 1, new uint[] { length }, new uint[] { lowerBound.Value });
				}
			);
		}