Ejemplo n.º 1
0
        internal void StartDebugging()
        {
            if (_vm != null)
            {
                return;
            }

            _vm = VirtualMachineManager.Connect(new IPEndPoint(_ipAddress, 11000));
            _vm.EnableEvents(EventType.AssemblyLoad,
                             EventType.ThreadStart,
                             EventType.ThreadDeath,
                             EventType.AssemblyUnload,
                             EventType.UserBreak,
                             EventType.Exception,
                             EventType.UserLog,
                             EventType.KeepAlive,
                             EventType.TypeLoad);

            EventSet set = _vm.GetNextEventSet();

            if (set.Events.OfType <VMStartEvent>().Any())
            {
                //TODO: review by techcap
                _mainThread = new AD7Thread(_engine, new DebuggedThread(set.Events[0].Thread, _engine));
                _engine.Callback.ThreadStarted(_mainThread);

                Task.Factory.StartNew(ReceiveThread, TaskCreationOptions.LongRunning);
            }
            else
            {
                throw new Exception("Didnt get VMStart-Event!");
            }
        }
Ejemplo n.º 2
0
        public AD7StackFrame(AD7Engine engine, AD7Thread thread, ThreadContext threadContext)
        {
            Debug.Assert(threadContext != null, "ThreadContext is null");

            Engine = engine;
            Thread = thread;
            ThreadContext = threadContext;

            _textPosition = threadContext.TextPosition;
            _functionName = threadContext.Function;

            if (threadContext.pc.HasValue)
            {
                _codeCxt = new AD7MemoryAddress(this.Engine, threadContext.pc.Value, _functionName);
            }

            if (_textPosition != null)
            {
                _documentCxt = new AD7DocumentContext(_textPosition, _codeCxt);

                if (_codeCxt != null)
                {
                    _codeCxt.SetDocumentContext(_documentCxt);
                }
            }
        }
Ejemplo n.º 3
0
        // Continue is called from the SDM when it wants execution to continue in the debugee
        // but have stepping state remain. An example is when a tracepoint is executed,
        // and the debugger does not want to actually enter break mode.
        public int Continue(IDebugThread2 pThread)
        {
            // VS Code currently isn't providing a thread Id in certain cases. Work around this by handling null values.
            AD7Thread thread = pThread as AD7Thread;

            try
            {
                if (_pollThread.IsPollThread())
                {
                    _debuggedProcess.Continue(thread?.GetDebuggedThread());
                }
                else
                {
                    _pollThread.RunOperation(() => _debuggedProcess.Continue(thread?.GetDebuggedThread()));
                }
            }
            catch (InvalidCoreDumpOperationException)
            {
                return(AD7_HRESULT.E_CRASHDUMP_UNSUPPORTED);
            }
            catch (Exception e)
            {
                _engineCallback.OnError(EngineUtils.GetExceptionDescription(e));
                return(Constants.E_ABORT);
            }

            return(Constants.S_OK);
        }
Ejemplo n.º 4
0
        public int Step(IDebugThread2 pThread, enum_STEPKIND kind, enum_STEPUNIT unit)
        {
            AD7Thread thread = (AD7Thread)pThread;

            try
            {
                if (null == thread || null == thread.GetDebuggedThread())
                {
                    return(Constants.E_FAIL);
                }

                _debuggedProcess.WorkerThread.RunOperation(() => _debuggedProcess.Step(thread.GetDebuggedThread().Id, kind, unit));
            }
            catch (InvalidCoreDumpOperationException)
            {
                return(AD7_HRESULT.E_CRASHDUMP_UNSUPPORTED);
            }
            catch (Exception e)
            {
                _engineCallback.OnError(EngineUtils.GetExceptionDescription(e));
                return(Constants.E_ABORT);
            }

            return(Constants.S_OK);
        }
Ejemplo n.º 5
0
        public void OnLoadComplete(DebuggedThread thread)
        {
            AD7Thread            ad7Thread   = (AD7Thread)thread.Client;
            AD7LoadCompleteEvent eventObject = new AD7LoadCompleteEvent();

            Send(eventObject, AD7LoadCompleteEvent.IID, ad7Thread);
        }
Ejemplo n.º 6
0
        public AD7StackFrame(AD7Engine engine, AD7Thread thread, ThreadContext threadContext)
        {
            Debug.Assert(threadContext != null, "ThreadContext is null");

            Engine        = engine;
            Thread        = thread;
            ThreadContext = threadContext;

            _textPosition = threadContext.TextPosition;
            _functionName = threadContext.Function;

            if (threadContext.pc.HasValue)
            {
                _codeCxt = new AD7MemoryAddress(this.Engine, threadContext.pc.Value, _functionName);
            }

            if (_textPosition != null)
            {
                _documentCxt = new AD7DocumentContext(_textPosition, _codeCxt);

                if (_codeCxt != null)
                {
                    _codeCxt.SetDocumentContext(_documentCxt);
                }
            }
        }
Ejemplo n.º 7
0
        // ExecuteOnThread is called when the SDM wants execution to continue and have
        // stepping state cleared.
        public int ExecuteOnThread(IDebugThread2 pThread)
        {
            AD7Thread thread = (AD7Thread)pThread;

            _pollThread.RunOperation(() => _debuggedProcess.Execute(thread.GetDebuggedThread()));

            return(Constants.S_OK);
        }
Ejemplo n.º 8
0
        // Exception events are sent when an exception occurs in the debuggee that the debugger was not expecting.
        public void OnException(DebuggedThread thread, string name, string description, uint code)
        {
            AD7ExceptionEvent eventObject = new AD7ExceptionEvent(name, description, code);

            AD7Thread ad7Thread = (AD7Thread)thread.Client;

            Send(eventObject, AD7ExceptionEvent.IID, ad7Thread);
        }
Ejemplo n.º 9
0
        public int Step(IDebugThread2 pThread, enum_STEPKIND kind, enum_STEPUNIT unit)
        {
            AD7Thread thread = (AD7Thread)pThread;

            _debuggedProcess.WorkerThread.RunOperation(() => _debuggedProcess.Step(thread.GetDebuggedThread().Id, kind, unit));

            return(Constants.S_OK);
        }
Ejemplo n.º 10
0
        // Exception events are sent when an exception occurs in the debuggee that the debugger was not expecting.
        public void OnException(DebuggedThread thread, string name, string description, uint code, Guid?exceptionCategory = null, ExceptionBreakpointState state = ExceptionBreakpointState.None)
        {
            AD7ExceptionEvent eventObject = new AD7ExceptionEvent(name, description, code, exceptionCategory, state);

            AD7Thread ad7Thread = (AD7Thread)thread.Client;

            Send(eventObject, AD7ExceptionEvent.IID, ad7Thread);
        }
Ejemplo n.º 11
0
        public void OnStepComplete(DebuggedThread thread)
        {
            // Step complete is sent when a step has finished
            AD7StepCompleteEvent eventObject = new AD7StepCompleteEvent();

            AD7Thread ad7Thread = (AD7Thread)thread.Client;

            Send(eventObject, AD7StepCompleteEvent.IID, ad7Thread);
        }
Ejemplo n.º 12
0
 public DebuggedThread(ThreadMirror thread, AD7Engine engine)
 {
     Thread = thread;
     Id = thread.TID;
     Name = "";
     TargetId = thread.TID;
     AD7Thread ad7Thread = new AD7Thread(engine, this);
     Client = ad7Thread;
 }
Ejemplo n.º 13
0
        // Continue is called from the SDM when it wants execution to continue in the debugee
        // but have stepping state remain. An example is when a tracepoint is executed,
        // and the debugger does not want to actually enter break mode.
        public int Continue(IDebugThread2 pThread)
        {
            // VS Code currently isn't providing a thread Id in certain cases. Work around this by handling null values.
            AD7Thread thread = pThread as AD7Thread;

            _pollThread.RunOperation(() => _debuggedProcess.Continue(thread?.GetDebuggedThread()));

            return(Constants.S_OK);
        }
Ejemplo n.º 14
0
        public DebuggedThread(ThreadMirror thread, AD7Engine engine)
        {
            Thread   = thread;
            Id       = thread.TID;
            Name     = "";
            TargetId = thread.TID;
            AD7Thread ad7Thread = new AD7Thread(engine, this);

            Client = ad7Thread;
        }
Ejemplo n.º 15
0
        public void OnAsyncBreakComplete(DebuggedThread thread)
        {
            // This will get called when the engine receives the breakpoint event that is created when the user
            // hits the pause button in vs.
            Debug.Assert(_engine.DebuggedProcess.WorkerThread.IsPollThread());

            AD7Thread ad7Thread = (AD7Thread)thread.Client;
            AD7AsyncBreakCompleteEvent eventObject = new AD7AsyncBreakCompleteEvent();

            Send(eventObject, AD7AsyncBreakCompleteEvent.IID, ad7Thread);
        }
Ejemplo n.º 16
0
        // Continue is called from the SDM when it wants execution to continue in the debugee
        // but have stepping state remain. An example is when a tracepoint is executed,
        // and the debugger does not want to actually enter break mode.
        public int Continue(IDebugThread2 pThread)
        {
            AD7Thread thread = (AD7Thread)pThread;

            _pollThread.RunOperation(new Operation(delegate
            {
                _debuggedProcess.Continue(thread.GetDebuggedThread());
            }));

            return(Constants.S_OK);
        }
Ejemplo n.º 17
0
        public void OnThreadExit(DebuggedThread debuggedThread, uint exitCode)
        {
            Debug.Assert(_engine.DebuggedProcess.WorkerThread.IsPollThread());

            AD7Thread ad7Thread = (AD7Thread)debuggedThread.Client;

            Debug.Assert(ad7Thread != null);

            AD7ThreadDestroyEvent eventObject = new AD7ThreadDestroyEvent(exitCode);

            Send(eventObject, AD7ThreadDestroyEvent.IID, ad7Thread);
        }
Ejemplo n.º 18
0
        //This method gets the value/type info for the method parameters without creating an MI debugger varialbe for them. For use in the callstack window
        //NOTE: eval is not called
        public async Task <List <SimpleVariableInformation> > GetParameterInfoOnly(AD7Thread thread, ThreadContext ctx)
        {
            List <SimpleVariableInformation> parameters = new List <SimpleVariableInformation>();

            ValueListValue localAndParameters = await MICommandFactory.StackListVariables(PrintValues.SimpleValues, thread.Id, ctx.Level);

            foreach (var results in localAndParameters.Content.Where(r => r.TryFindString("arg") == "1"))
            {
                parameters.Add(new SimpleVariableInformation(results.FindString("name"), /*isParam*/ true, results.FindString("value"), results.FindString("type")));
            }

            return(parameters);
        }
Ejemplo n.º 19
0
        private VariableInformation(ThreadContext ctx, AD7Engine engine, AD7Thread thread)
        {
            _engine          = engine;
            _debuggedProcess = _engine.DebuggedProcess;
            _ctx             = ctx;
            Client           = thread;

            IsParameter     = false;
            IsChild         = false;
            _attribsFetched = false;
            Access          = enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_NONE;
            _fullname       = null;
        }
Ejemplo n.º 20
0
        //internal void Resume()
        //{
        //    _vm.Resume();
        //}

        /// <summary>
        /// For Run
        /// </summary>
        /// <param name="thread"></param>
        internal void Execute(AD7Thread thread)
        {
            DebugHelper.TraceEnteringMethod();
            try
            {
                ResumeVM();
            }
            catch (Exception)
            {
                // TODO
                throw;
            }
        }
Ejemplo n.º 21
0
        internal void Step(AD7Thread thread, enum_STEPKIND sk, enum_STEPUNIT stepUnit)
        {
            DebugHelper.TraceEnteringMethod();
            if (!_isStepping)
            {
                if (currentStepRequest == null)
                {
                    currentStepRequest = _vm.CreateStepRequest(thread.ThreadMirror);
                }
                else
                {
                    currentStepRequest.Disable();
                }

                _isStepping = true;
                if (stepUnit == enum_STEPUNIT.STEP_LINE || stepUnit == enum_STEPUNIT.STEP_STATEMENT)
                {
                    switch (sk)
                    {
                    case enum_STEPKIND.STEP_INTO:
                        currentStepRequest.Depth = StepDepth.Into;
                        break;

                    case enum_STEPKIND.STEP_OUT:
                        currentStepRequest.Depth = StepDepth.Out;
                        break;

                    case enum_STEPKIND.STEP_OVER:
                        currentStepRequest.Depth = StepDepth.Over;
                        break;

                    default:
                        return;
                    }
                }
                else if (stepUnit == enum_STEPUNIT.STEP_INSTRUCTION)
                {
                    //TODO: by techcap
                }
                else
                {
                    throw new NotImplementedException();
                }

                currentStepRequest.Size = StepSize.Line;
                currentStepRequest.Enable();
            }

            ResumeVM();
        }
Ejemplo n.º 22
0
        public int Step(IDebugThread2 pThread, enum_STEPKIND kind, enum_STEPUNIT unit)
        {
            AD7Thread thread = (AD7Thread)pThread;

            try
            {
                _debuggedProcess.WorkerThread.RunOperation(() => _debuggedProcess.Step(thread.GetDebuggedThread().Id, kind, unit));
            }
            catch (InvalidCoreDumpOperationException)
            {
                return(AD7_HRESULT.E_CRASHDUMP_UNSUPPORTED);
            }

            return(Constants.S_OK);
        }
Ejemplo n.º 23
0
        // ExecuteOnThread is called when the SDM wants execution to continue and have
        // stepping state cleared.
        public int ExecuteOnThread(IDebugThread2 pThread)
        {
            AD7Thread thread = (AD7Thread)pThread;

            try
            {
                _pollThread.RunOperation(() => _debuggedProcess.Execute(thread?.GetDebuggedThread()));
            }
            catch (InvalidCoreDumpOperationException)
            {
                return(AD7_HRESULT.E_CRASHDUMP_UNSUPPORTED);
            }

            return(Constants.S_OK);
        }
Ejemplo n.º 24
0
        // EnumThreads is called by the debugger when it needs to enumerate the threads in the program.
        public int EnumThreads(out IEnumDebugThreads2 ppEnum)
        {
            DebuggedThread[] threads = null;
            DebuggedProcess.WorkerThread.RunOperation(async() => threads = await DebuggedProcess.ThreadCache.GetThreads());

            AD7Thread[] threadObjects = new AD7Thread[threads.Length];
            for (int i = 0; i < threads.Length; i++)
            {
                Debug.Assert(threads[i].Client != null);
                threadObjects[i] = (AD7Thread)threads[i].Client;
            }

            ppEnum = new Microsoft.MIDebugEngine.AD7ThreadEnum(threadObjects);

            return(Constants.S_OK);
        }
Ejemplo n.º 25
0
        //This method gets the locals and parameters and creates an MI debugger variable for each one so that we can manipulate them (and expand children, etc.)
        //NOTE: Eval is called
        internal async Task <List <VariableInformation> > GetLocalsAndParameters(AD7Thread thread, ThreadContext ctx)
        {
            List <VariableInformation> variables = new List <VariableInformation>();

            ValueListValue localsAndParameters = await MICommandFactory.StackListVariables(PrintValues.NoValues, thread.Id, ctx.Level);

            foreach (var localOrParamResult in localsAndParameters.Content)
            {
                string name    = localOrParamResult.FindString("name");
                bool   isParam = localOrParamResult.TryFindString("arg") == "1";
                SimpleVariableInformation simpleInfo = new SimpleVariableInformation(name, isParam);
                VariableInformation       vi         = await simpleInfo.CreateMIDebuggerVariable(ctx, Engine, thread);

                variables.Add(vi);
            }

            return(variables);
        }
Ejemplo n.º 26
0
        public AD7StackFrame(AD7Engine engine, AD7Thread thread, Mono.Debugger.Soft.StackFrame threadContext)
        {
            Debug.Assert(threadContext != null, "ThreadContext is null");

            Engine = engine;
            this.Thread = thread;
            this.ThreadContext = threadContext;

            _textPosition = RoslynHelper.GetStatementRange(ThreadContext.FileName, ThreadContext.LineNumber, ThreadContext.ColumnNumber);
            _functionName = threadContext.Method.Name;

            //if(threadContext.IsNativeTransition)
            //{

            //}

            if (_textPosition != null)
            {
                docContext = new AD7DocumentContext(_textPosition);
            }

            this.LocalVariables = threadContext.GetVisibleVariables().Select(x => new MonoProperty(threadContext, x)).ToList();
        }
Ejemplo n.º 27
0
        //This method gets the value/type info for the method parameters of all frames without creating an mi debugger varialbe for them. For use in the callstack window
        //NOTE: eval is not called
        public async Task <List <ArgumentList> > GetParameterInfoOnly(AD7Thread thread, bool values, bool types, uint low, uint high)
        {
            var frames = await MICommandFactory.StackListArguments(values || types?PrintValues.SimpleValues : PrintValues.NoValues, thread.Id, low, high);

            List <ArgumentList> parameters = new List <ArgumentList>();

            foreach (var f in frames)
            {
                int       level   = f.FindInt("level");
                ListValue argList = null;
                f.TryFind <ListValue>("args", out argList);
                List <SimpleVariableInformation> args = new List <SimpleVariableInformation>();
                if (argList != null)
                {
                    if (argList is ValueListValue) // a tuple for each arg
                    {
                        foreach (var arg in ((ValueListValue)argList).Content)
                        {
                            args.Add(new SimpleVariableInformation(arg.FindString("name"), /*isParam*/ true, arg.TryFindString("value"), arg.TryFindString("type")));
                        }
                    }
                    else
                    {
                        // simple arg name list
                        string[] names = ((ResultListValue)argList).FindAllStrings("name");
                        foreach (var n in names)
                        {
                            args.Add(new SimpleVariableInformation(n, /*isParam*/ true, null, null));
                        }
                    }
                }
                parameters.Add(new ArgumentList(level, args));
            }

            return(parameters);
        }
Ejemplo n.º 28
0
        public void OnBreakpoint(DebuggedThread thread, ReadOnlyCollection <object> clients)
        {
            IDebugBoundBreakpoint2[] boundBreakpoints = new IDebugBoundBreakpoint2[clients.Count];

            int i = 0;

            foreach (object objCurrentBreakpoint in clients)
            {
                boundBreakpoints[i] = (IDebugBoundBreakpoint2)objCurrentBreakpoint;
                i++;
            }

            // An engine that supports more advanced breakpoint features such as hit counts, conditions and filters
            // should notify each bound breakpoint that it has been hit and evaluate conditions here.
            // The sample engine does not support these features.

            AD7BoundBreakpointsEnum boundBreakpointsEnum = new AD7BoundBreakpointsEnum(boundBreakpoints);

            AD7BreakpointEvent eventObject = new AD7BreakpointEvent(boundBreakpointsEnum);

            AD7Thread ad7Thread = (AD7Thread)thread.Client;

            Send(eventObject, AD7BreakpointEvent.IID, ad7Thread);
        }
Ejemplo n.º 29
0
        // EnumThreads is called by the debugger when it needs to enumerate the threads in the program.
        public int EnumThreads(out IEnumDebugThreads2 ppEnum)
        {
            DebuggedThread[] threads = null;
            DebuggedProcess.WorkerThread.RunOperation(async () => threads = await DebuggedProcess.ThreadCache.GetThreads());

            AD7Thread[] threadObjects = new AD7Thread[threads.Length];
            for (int i = 0; i < threads.Length; i++)
            {
                Debug.Assert(threads[i].Client != null);
                threadObjects[i] = (AD7Thread)threads[i].Client;
            }

            ppEnum = new Microsoft.MIDebugEngine.AD7ThreadEnum(threadObjects);

            return Constants.S_OK;
        }
        internal void StartDebugging()
        {
            if (_vm != null)
                return;

            _vm = VirtualMachineManager.Connect(new IPEndPoint(_ipAddress, 11000));
            _vm.EnableEvents(EventType.AssemblyLoad,
                EventType.ThreadStart,
                EventType.ThreadDeath,
                EventType.AssemblyUnload,
                EventType.UserBreak,
                EventType.Exception,
                EventType.UserLog,
                EventType.KeepAlive,
                EventType.TypeLoad);

            EventSet set = _vm.GetNextEventSet();
            if (set.Events.OfType<VMStartEvent>().Any())
            {
                //TODO: review by techcap
                _mainThread = new AD7Thread(_engine, new DebuggedThread(set.Events[0].Thread, _engine));
                _engine.Callback.ThreadStarted(_mainThread);

                Task.Factory.StartNew(ReceiveThread, TaskCreationOptions.LongRunning);
            }
            else
                throw new Exception("Didnt get VMStart-Event!");
        }
        internal void Step(AD7Thread thread, enum_STEPKIND sk, enum_STEPUNIT stepUnit)
        {
            if (!isStepping)
            {
                if (currentStepRequest == null)
                    currentStepRequest = _vm.CreateStepRequest(thread.ThreadMirror);
                else
                {
                    currentStepRequest.Disable();
                }

                isStepping = true;
                if (stepUnit == enum_STEPUNIT.STEP_LINE || stepUnit == enum_STEPUNIT.STEP_STATEMENT)
                {
                    switch (sk)
                    {
                        case enum_STEPKIND.STEP_INTO:
                            currentStepRequest.Depth = StepDepth.Into;
                            break;
                        case enum_STEPKIND.STEP_OUT:
                            currentStepRequest.Depth = StepDepth.Out;
                            break;
                        case enum_STEPKIND.STEP_OVER:
                            currentStepRequest.Depth = StepDepth.Over;
                            break;
                        default:
                            return;
                    }
                }
                else if (stepUnit == enum_STEPUNIT.STEP_INSTRUCTION)
                {
                    //TODO: by techcap
                }
                else
                    throw new NotImplementedException();

                currentStepRequest.Size = StepSize.Line;
                currentStepRequest.Enable();
            }

            _vm.Resume();
        }
        //internal void Resume()
        //{
        //    _vm.Resume();
        //}

        /// <summary>
        /// For Run
        /// </summary>
        /// <param name="debuggedMonoThread"></param>
        internal void Execute(AD7Thread debuggedMonoThread)
        {
            _vm.Resume();
        }
Ejemplo n.º 33
0
        //This method gets the value/type info for the method parameters of all frames without creating an mi debugger variable for them. For use in the callstack window
        //NOTE: eval is not called
        public async Task<List<ArgumentList>> GetParameterInfoOnly(AD7Thread thread, bool values, bool types, uint low, uint high)
        {
            var frames = await MICommandFactory.StackListArguments(values || types ? PrintValues.SimpleValues : PrintValues.NoValues, thread.Id, low, high);
            List<ArgumentList> parameters = new List<ArgumentList>();

            foreach (var f in frames)
            {
                int level = f.FindInt("level");
                ListValue argList = null;
                f.TryFind<ListValue>("args", out argList);
                List<SimpleVariableInformation> args = new List<SimpleVariableInformation>();
                if (argList != null)
                {
                    if (argList is ValueListValue) // a tuple for each arg
                    {
                        foreach (var arg in ((ValueListValue)argList).Content)
                        {
                            args.Add(new SimpleVariableInformation(arg.FindString("name"), /*isParam*/ true, arg.TryFindString("value"), arg.TryFindString("type")));
                        }
                    }
                    else
                    {
                        // simple arg name list
                        string[] names = ((ResultListValue)argList).FindAllStrings("name");
                        foreach (var n in names)
                        {
                            args.Add(new SimpleVariableInformation(n, /*isParam*/ true, null, null));
                        }
                    }
                }
                parameters.Add(new ArgumentList(level, args));
            }

            return parameters;
        }
Ejemplo n.º 34
0
 internal void BreakpointHit(AD7PendingBreakpoint breakpoint, AD7Thread thread)
 {
     var iid = new Guid(AD7BreakpointEvent.IID);
     _eventCallback.Event(_engine, _engine.RemoteProcess, _engine, thread, new AD7BreakpointEvent(breakpoint), ref iid,
         AD7StoppingEvent.Attributes);
 }
Ejemplo n.º 35
0
        //internal void Resume()
        //{
        //    _vm.Resume();
        //}

        /// <summary>
        /// For Run
        /// </summary>
        /// <param name="debuggedMonoThread"></param>
        internal void Execute(AD7Thread debuggedMonoThread)
        {
            _vm.Resume();
        }
Ejemplo n.º 36
0
 //this constructor is used to create root nodes (local/params)
 internal VariableInformation(string expr, ThreadContext ctx, AD7Engine engine, AD7Thread thread, bool isParameter = false)
     : this(ctx, engine, thread)
 {
     // strip off formatting string
     _strippedName    = StripFormatSpecifier(expr, out _format);
     Name             = expr;
     IsParameter      = isParameter;
     _parent          = null;
     VariableNodeType = NodeType.Root;
 }
Ejemplo n.º 37
0
        //This method gets the locals and parameters and creates an MI debugger variable for each one so that we can manipulate them (and expand children, etc.)
        //NOTE: Eval is called
        internal async Task<List<VariableInformation>> GetLocalsAndParameters(AD7Thread thread, ThreadContext ctx)
        {
            List<VariableInformation> variables = new List<VariableInformation>();

            ValueListValue localsAndParameters = await MICommandFactory.StackListVariables(PrintValues.NoValues, thread.Id, ctx.Level);

            foreach (var localOrParamResult in localsAndParameters.Content)
            {
                string name = localOrParamResult.FindString("name");
                bool isParam = localOrParamResult.TryFindString("arg") == "1";
                SimpleVariableInformation simpleInfo = new SimpleVariableInformation(name, isParam);
                VariableInformation vi = await simpleInfo.CreateMIDebuggerVariable(ctx, Engine, thread);
                variables.Add(vi);
            }

            return variables;
        }
Ejemplo n.º 38
0
        //This method gets the value/type info for the method parameters without creating an MI debugger variable for them. For use in the callstack window
        //NOTE: eval is not called
        public async Task<List<SimpleVariableInformation>> GetParameterInfoOnly(AD7Thread thread, ThreadContext ctx)
        {
            List<SimpleVariableInformation> parameters = new List<SimpleVariableInformation>();

            ValueListValue localAndParameters = await MICommandFactory.StackListVariables(PrintValues.SimpleValues, thread.Id, ctx.Level);

            foreach (var results in localAndParameters.Content.Where(r => r.TryFindString("arg") == "1"))
            {
                parameters.Add(new SimpleVariableInformation(results.FindString("name"), /*isParam*/ true, results.FindString("value"), results.FindString("type")));
            }

            return parameters;
        }
Ejemplo n.º 39
0
        private void HandleEventSet(Event ev)
        {
            var type = ev.EventType;

            _engine.IsSuspended = true;

            logger.Trace($"HandleEventSet: {ev}");

            try
            {
                switch (type)
                {
                case EventType.AssemblyLoad:
                    HandleAssemblyLoad((AssemblyLoadEvent)ev);
                    break;

                case EventType.UserBreak:
                    if (!HandleUserBreak((UserBreakEvent)ev))
                    {
                        return;
                    }
                    break;

                case EventType.Breakpoint:
                    if (!HandleBreakPoint((BreakpointEvent)ev))
                    {
                        return;
                    }
                    break;

                case EventType.Step:
                    HandleStep((StepEvent)ev);
                    return;

                case EventType.TypeLoad:
                    var typeEvent = (TypeLoadEvent)ev;
                    RegisterType(typeEvent.Type);
                    TryBindBreakpoints();
                    break;

                case EventType.UserLog:
                    UserLogEvent e = (UserLogEvent)ev;
                    HostOutputWindowEx.WriteLaunchError(e.Message);
                    break;

                case EventType.VMDeath:
                case EventType.VMDisconnect:
                    Disconnect();
                    return;

                case EventType.VMStart:
                case EventType.ThreadStart:
                    var domain    = ev.Thread.Domain.FriendlyName;
                    var threadId  = ev.Thread.ThreadId;
                    var newThread = new AD7Thread(_engine, ev.Thread);
                    if (_threads.TryAdd(threadId, newThread))
                    {
                        _engine.Callback.ThreadStarted(newThread);
                    }
                    else
                    {
                        logger.Error($"Thread {threadId} already added!");
                    }
                    break;

                case EventType.ThreadDeath:
                    var       oldThreadId = ev.Thread.ThreadId;
                    AD7Thread oldThread   = null;
                    if (!_threads.TryRemove(oldThreadId, out oldThread))
                    {
                        _engine.Callback.ThreadDestroyed(oldThread, 0);
                    }
                    else
                    {
                        logger.Error($"Thread {oldThreadId} not found!");
                    }
                    break;

                case EventType.Exception:
                    var exEvent = ev as ExceptionEvent;
                    var exceptionObjectMirror = exEvent.Exception;
                    // TODO Reading properties from complex exceptions throws an exception. Why?
                    var filter = MonoProperty.EnumOnlyFieldsFilter;
                    IEnumDebugPropertyInfo2 propInfo;
                    var monoProperty = new MonoProperty(exEvent.Thread.GetFrames().FirstOrDefault(), exceptionObjectMirror);
                    var propInfo1    = new DEBUG_PROPERTY_INFO[1];
                    monoProperty.GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ALL, 0, 10000, null, 0, propInfo1);
                    monoProperty.EnumChildren(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_ALL, 0, ref filter, enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_ALL, "", 10000, out propInfo);
                    var sbException = new StringBuilder();
                    sbException.AppendLine($"Excption thrown: {exceptionObjectMirror.Type.FullName}");
                    var propInfoCast = propInfo as AD7PropertyEnum;
                    foreach (var prop in propInfoCast.GetData())
                    {
                        if (prop.bstrName.StartsWith("_message") || prop.bstrName.StartsWith("_innerException"))
                        {
                            sbException.AppendLine($"{prop.bstrName} = {prop.bstrValue}");
                        }
                    }
                    logger.Error($"Exception thrown: {sbException.ToString()}");
                    HostOutputWindowEx.WriteLaunchError($"Exception thrown: {sbException.ToString()}");
                    break;

                default:
                    logger.Trace(ev);
                    break;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"Exception thrown in {nameof(HandleEventSet)}({ev})");
            }

            try
            {
                if (type != EventType.VMStart)
                {
                    logger.Trace($"HandleEventSet: ResumeVM ({ev})");
                    ResumeVM();
                }
            }
            catch (VMNotSuspendedException)
            {
                if (type != EventType.VMStart && _vm.Version.AtLeast(2, 2))
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Ejemplo n.º 40
0
 internal void StepCompleted(AD7Thread thread)
 {
     var iid = new Guid(Microsoft.MIDebugEngine.AD7StepCompleteEvent.IID);
     _eventCallback.Event(_engine, _engine.RemoteProcess, _engine, thread, new Microsoft.MIDebugEngine.AD7StepCompleteEvent(), ref iid,
         AD7StoppingEvent.Attributes);
 }
Ejemplo n.º 41
0
        internal async Task <VariableInformation> CreateMIDebuggerVariable(ThreadContext ctx, AD7Engine engine, AD7Thread thread)
        {
            VariableInformation vi = new VariableInformation(Name, ctx, engine, thread, IsParameter);
            await vi.Eval();

            return(vi);
        }
Ejemplo n.º 42
0
 /// <summary>
 /// On First run
 /// </summary>
 /// <param name="thread"></param>
 internal void Continue(AD7Thread thread)
 {
     DebugHelper.TraceEnteringMethod();
     //_vm.Resume();
 }