Exemplo n.º 1
0
        public static AD_PROCESS_ID GetPhysicalProcessId(this IDebugProcess2 process)
        {
            Contract.Requires <ArgumentNullException>(process != null, "process");

            AD_PROCESS_ID[] processId = new AD_PROCESS_ID[1];
            ErrorHandler.ThrowOnFailure(process.GetPhysicalProcessId(processId));
            return(processId[0]);
        }
Exemplo n.º 2
0
        public static int GetProcessId(IDebugProcess2 process) {
            AD_PROCESS_ID[] pid = new AD_PROCESS_ID[1];
            EngineUtils.RequireOk(process.GetPhysicalProcessId(pid));

            if (pid[0].ProcessIdType != (uint)enum_AD_PROCESS_ID.AD_PROCESS_ID_SYSTEM) {
                return 0;
            }

            return (int)pid[0].dwProcessId;
        }
Exemplo n.º 3
0
        public static int GetProcessId(IDebugProcess2 process)
        {
            AD_PROCESS_ID[] pid = new AD_PROCESS_ID[1];
            EngineUtils.RequireOk(process.GetPhysicalProcessId(pid));

            if (pid[0].ProcessIdType != (uint)enum_AD_PROCESS_ID.AD_PROCESS_ID_SYSTEM)
            {
                return(0);
            }

            return((int)pid[0].dwProcessId);
        }
        internal void InitializeDebuggerChannel(JavaDebugEngine debugEngine, IDebugEventCallback2 callback)
        {
            Contract.Requires <ArgumentNullException>(debugEngine != null, "debugEngine");
            Contract.Requires <ArgumentNullException>(callback != null, "callback");

            _debugEngine = debugEngine;
            _callback    = callback;

            var connector = new LocalDebuggingAttachingConnector();

            Dictionary <string, IConnectorArgument> arguments = new Dictionary <string, IConnectorArgument>();

            string argumentName = "pid";
            IConnectorIntegerArgument defaultArgument = (IConnectorIntegerArgument)connector.DefaultArguments[argumentName];
            IConnectorIntegerArgument argument        = new ConnectorIntegerArgument(defaultArgument, (int)_process.GetPhysicalProcessId().dwProcessId);

            arguments.Add(argumentName, argument);

            argumentName = "sourcePaths";
            IConnectorStringArgument defaultPathsArgument = (IConnectorStringArgument)connector.DefaultArguments[argumentName];
            List <string>            sourcePaths          = GetSourcePaths();
            IConnectorStringArgument stringArgument       = new ConnectorStringArgument(defaultPathsArgument, string.Join(";", sourcePaths));

            arguments.Add(argumentName, stringArgument);

            connector.AttachComplete += HandleAttachComplete;
            _virtualMachine           = connector.Attach(arguments);

            IVirtualMachineEvents events = _virtualMachine.GetEventQueue() as IVirtualMachineEvents;

            if (events != null)
            {
                events.VirtualMachineStart     += HandleVirtualMachineStart;
                events.VirtualMachineDeath     += HandleVirtualMachineDeath;
                events.SingleStep              += HandleSingleStep;
                events.Breakpoint              += HandleBreakpoint;
                events.MethodEntry             += HandleMethodEntry;
                events.MethodExit              += HandleMethodExit;
                events.MonitorContendedEnter   += HandleMonitorContendedEnter;
                events.MonitorContendedEntered += HandleMonitorContendedEntered;
                events.MonitorContendedWait    += HandleMonitorContendedWait;
                events.MonitorContendedWaited  += HandleMonitorContendedWaited;
                events.Exception         += HandleException;
                events.ThreadStart       += HandleThreadStart;
                events.ThreadDeath       += HandleThreadDeath;
                events.ClassPrepare      += HandleClassPrepare;
                events.ClassUnload       += HandleClassUnload;
                events.FieldAccess       += HandleFieldAccess;
                events.FieldModification += HandleFieldModification;
            }
        }
Exemplo n.º 5
0
        public static int GetProcessId(this IDebugProcess2 process)
        {
            if (process == null)
            {
                return(0);
            }
            var id = new AD_PROCESS_ID[1];

            if (process.GetPhysicalProcessId(id) != VSConstants.S_OK)
            {
                return(0);
            }
            return((int)id[0].dwProcessId);
        }
Exemplo n.º 6
0
        private bool Initialize(
            QmlEngine engine,
            IDebugProcess2 nativeProc,
            string execPath,
            string execArgs)
        {
            Engine     = engine;
            NativeProc = nativeProc;

            var nativeProcId = new AD_PROCESS_ID[1];

            nativeProc.GetPhysicalProcessId(nativeProcId);
            NativeProcId = nativeProcId[0].dwProcessId;

            ExecPath = execPath;
            ExecArgs = execArgs;

            Debugger = QmlDebugger.Create(this, execPath, execArgs);
            if (Debugger == null)
            {
                return(false);
            }

            VsDebugger = VsServiceProvider.GetService <IVsDebugger>();
            if (VsDebugger != null)
            {
                ThreadHelper.JoinableTaskFactory.Run(async() =>
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    VsDebugger.AdviseDebugEventCallback(this);
                });
            }
            vsDebuggerThreadDispatcher = Dispatcher.CurrentDispatcher;

            ProcessId     = Guid.NewGuid();
            CurrentFrames = new List <StackFrame>();

            lock (criticalSectionGlobal) {
                if (runningPrograms == 0)
                {
                    originalBreakAllProcesses = BreakAllProcesses;
                }
                runningPrograms++;
            }

            return(true);
        }
Exemplo n.º 7
0
        int IDebugEventCallback2.Event(
            IDebugEngine2 pEngine,
            IDebugProcess2 pProcess,
            IDebugProgram2 pProgram,
            IDebugThread2 pThread,
            IDebugEvent2 pEvent,
            ref Guid riidEvent,
            uint dwAttrib)
        {
            if (pEngine == Engine)
            {
                return(VSConstants.S_OK);
            }

            if (pProcess == null && pProgram == null)
            {
                return(VSConstants.S_OK);
            }

            if (pProcess == null)
            {
                if (pProgram.GetProcess(out pProcess) != VSConstants.S_OK || pProcess == null)
                {
                    return(VSConstants.S_OK);
                }
            }

            var pProcessId = new AD_PROCESS_ID[1];

            if (pProcess.GetPhysicalProcessId(pProcessId) != VSConstants.S_OK)
            {
                return(VSConstants.S_OK);
            }

            if (pProcessId[0].dwProcessId != NativeProcId)
            {
                return(VSConstants.S_OK);
            }

            if (riidEvent == typeof(IDebugProgramDestroyEvent2).GUID)
            {
                TerminateProcess();
            }

            return(VSConstants.S_OK);
        }
Exemplo n.º 8
0
        private bool CreateProcEvArgs(IDebugProcess2 pProcess, out CPProcEvArgs args)
        {
            args = null;
            string name = string.Empty;

            if (pProcess.GetName((uint)enum_GETNAME_TYPE.GN_NAME /*GN_BASENAME*/, out name) != VSConstants.S_OK)
            {
                return(false);
            }
            AD_PROCESS_ID[] adProcId = new AD_PROCESS_ID[1];
            if (pProcess.GetPhysicalProcessId(adProcId) != VSConstants.S_OK)
            {
                return(false);
            }
            args = new CPProcEvArgs(adProcId[0].dwProcessId, name);

            return(true);
        }
Exemplo n.º 9
0
        bool GetProcessInfo(IDebugProcess2 pProcess, bool native, out string execPath, out uint procId)
        {
            execPath = "";
            procId   = 0;

            string fileName;

            if (pProcess.GetName(enum_GETNAME_TYPE.GN_FILENAME, out fileName) != VSConstants.S_OK)
            {
                return(false);
            }

            var pProcessId = new AD_PROCESS_ID[1];

            if (pProcess.GetPhysicalProcessId(pProcessId) != VSConstants.S_OK)
            {
                return(false);
            }

            if (native)
            {
                execPath = Path.GetFullPath(fileName);
            }
            else
            {
                var wslPath = wslPathParser.Parse(fileName)
                              .GetValues <WslPath>("WSLPATH").FirstOrDefault();
                if (wslPath != null)
                {
                    execPath = Path.GetFullPath(wslPath);
                }
                else
                {
                    execPath = fileName;
                }
            }

            procId = pProcessId[0].dwProcessId;
            return(true);
        }
Exemplo n.º 10
0
 public int GetHostPid(AD_PROCESS_ID[] hostProcessId)
 {
     taskContext.ThrowIfNotOnMainThread();
     return(process.GetPhysicalProcessId(hostProcessId));
 }
Exemplo n.º 11
0
 public static AD_PROCESS_ID GetProcessId(IDebugProcess2 process)
 {
     AD_PROCESS_ID[] pid = new AD_PROCESS_ID[1];
     EngineUtils.RequireOk(process.GetPhysicalProcessId(pid));
     return(pid[0]);
 }
Exemplo n.º 12
0
 int IDebugProgramNode2.GetHostPid(AD_PROCESS_ID[] pHostProcessId)
 {
     _process.GetPhysicalProcessId(pHostProcessId);
     return(VSConstants.S_OK);
 }
Exemplo n.º 13
0
        public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes) {
            bool savedProgram = false;
            bool savedThread = false;

            if (riidEvent == processCreateEvent) {
                AD_PROCESS_ID[] pdwProcessId = new AD_PROCESS_ID[1];
                process.GetPhysicalProcessId(pdwProcessId);
                Debug.Assert(!this.attachedProcesses.Contains(pdwProcessId[0].dwProcessId));
                this.attachedProcesses.Add(pdwProcessId[0].dwProcessId);
            } else if (riidEvent == processDestroyEvent) {
                AD_PROCESS_ID[] pdwProcessId = new AD_PROCESS_ID[1];
                process.GetPhysicalProcessId(pdwProcessId);
                Debug.Assert(this.attachedProcesses.Contains(pdwProcessId[0].dwProcessId));
                this.attachedProcesses.Remove(pdwProcessId[0].dwProcessId);
            } else if (riidEvent == breakInEvent && this.currentDebugProgram != program && program != null && thread != null) {
                // Evaluate an expression get access to the memory context and the bitness.
                IDebugProperty2 debugProperty = this.EvaluateExpression(thread, "(void**)0x0 + 1");
                if (debugProperty != null) {
                    using (new DisposableComReference(debugProperty)) {
                        DEBUG_PROPERTY_INFO[] debugPropertyInfo = new DEBUG_PROPERTY_INFO[1];
                        if (debugProperty.GetPropertyInfo((uint)enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE, 16, evaluateExpressionTimeout, null, 0, debugPropertyInfo) == S_OK) {
                            IDebugMemoryContext2 memoryContext = null;
                            IDebugMemoryBytes2 memoryBytes = null;
                            if (debugProperty.GetMemoryContext(out memoryContext) == S_OK && debugProperty.GetMemoryBytes(out memoryBytes) == S_OK) {
                                DisposableComReference.SetReference(ref this.currentDebugProgram, program);
                                DisposableComReference.SetReference(ref this.currentThread, thread);
                                DisposableComReference.SetReference(ref this.memoryContext, memoryContext);
                                DisposableComReference.SetReference(ref this.memoryBytes, memoryBytes);
                                ulong offset = ulong.Parse(debugPropertyInfo[0].bstrValue.Substring("0x".Length), System.Globalization.NumberStyles.AllowHexSpecifier);

                                // Adjust the memory context and calculate the bitness.
                                this.memoryContext.Subtract(offset, out memoryContext);
                                DisposableComReference.SetReference(ref this.memoryContext, memoryContext);
                                this.isPointer64Bit = (offset == 8);

                                this.engine.NotifyDebuggerStatusChange(DebuggerChangeEventArgs.DebuggerStatus.Detaching);
                                this.engine.DiaLoader.ClearSymbols();
                                savedProgram = true;
                                savedThread = true;
                            } else {
                                DisposableComReference.ReleaseIfNotNull(ref memoryContext);
                                DisposableComReference.ReleaseIfNotNull(ref memoryBytes);
                            }
                        }
                    }
                }
            } else if (riidEvent == stopDebugEvent) {
                // The debugger stopped.  Clear the references.
                DisposableComReference.ReleaseIfNotNull(ref this.currentDebugProgram);
                DisposableComReference.ReleaseIfNotNull(ref this.memoryContext);
                DisposableComReference.ReleaseIfNotNull(ref this.memoryBytes);
                this.engine.NotifyDebuggerStatusChange(DebuggerChangeEventArgs.DebuggerStatus.Detaching);
                this.engine.DiaLoader.ClearSymbols();
            } else if (riidEvent == breakInEvent) {
                // The debugger broke in, notify the client.
                this.engine.NotifyDebuggerStatusChange(DebuggerChangeEventArgs.DebuggerStatus.Break);
            } else if (riidEvent == threadSwitchEvent) {
                // The user switched the current thread.
                DisposableComReference.SetReference(ref this.currentThread, thread);
                savedThread = true;
                if (this.currentThread != null) {
                    uint threadId;
                    thread.GetThreadId(out threadId);
                    this.TargetThreadSystemId = threadId;
                }

                bool processChanged = false;
                if (process != null) {
                    AD_PROCESS_ID[] pdwProcessId = new AD_PROCESS_ID[1];
                    process.GetPhysicalProcessId(pdwProcessId);
                    if (this.TargetProcessSystemId != 0) {
                        if (pdwProcessId[0].dwProcessId != this.TargetProcessSystemId) {
                            this.TargetProcessSystemId = pdwProcessId[0].dwProcessId;
                            processChanged = true;
                        }
                    } else {
                        this.TargetProcessSystemId = pdwProcessId[0].dwProcessId;
                        if (this.TargetProcessSystemId != 0) {
                            processChanged = true;
                        }
                    }
                } else if (this.TargetProcessSystemId != 0) {
                    this.TargetProcessSystemId = 0;
                    processChanged = true;
                }

                if (processChanged) {
                    DisposableComReference.SetReference(ref this.currentDebugProgram, program);
                    savedProgram = true;

                    if (program != null) {
                        // Evaluate an expression get access to the memory context and the bitness.
                        IDebugProperty2 debugProperty = this.EvaluateExpression(thread, "(void**)0x0 + 1");
                        if (debugProperty != null) {
                            using (new DisposableComReference(debugProperty)) {
                                DEBUG_PROPERTY_INFO[] debugPropertyInfo = new DEBUG_PROPERTY_INFO[1];
                                if (debugProperty.GetPropertyInfo((uint)enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE, 16, evaluateExpressionTimeout, null, 0, debugPropertyInfo) == S_OK) {
                                    IDebugMemoryContext2 memoryContext = null;
                                    IDebugMemoryBytes2 memoryBytes = null;
                                    if ((debugProperty.GetMemoryContext(out memoryContext) == S_OK) && (debugProperty.GetMemoryBytes(out memoryBytes) == S_OK)) {
                                        DisposableComReference.SetReference(ref this.memoryContext, memoryContext);
                                        DisposableComReference.SetReference(ref this.memoryBytes, memoryBytes);
                                        ulong offset = ulong.Parse(debugPropertyInfo[0].bstrValue.Substring("0x".Length), System.Globalization.NumberStyles.AllowHexSpecifier);

                                        // Adjust the memory context and calculate the bitness.
                                        this.memoryContext.Subtract(offset, out memoryContext);
                                        DisposableComReference.SetReference(ref this.memoryContext, memoryContext);
                                        this.isPointer64Bit = (offset == 8);
                                    } else {
                                        DisposableComReference.ReleaseIfNotNull(ref memoryContext);
                                        DisposableComReference.ReleaseIfNotNull(ref memoryBytes);
                                    }
                                }
                            }
                        }

                        this.engine.NotifyDebuggerStatusChange(DebuggerChangeEventArgs.DebuggerStatus.ChangingProcess);
                    }
                } else {
                    this.engine.NotifyDebuggerStatusChange(DebuggerChangeEventArgs.DebuggerStatus.ChangingThread);
                }
            }

            if (!savedProgram) {
                DisposableComReference.ReleaseIfNotNull(ref program);
            }
            if (!savedThread) {
                DisposableComReference.ReleaseIfNotNull(ref thread);
            }
            DisposableComReference.ReleaseIfNotNull(ref engine);
            DisposableComReference.ReleaseIfNotNull(ref process);
            DisposableComReference.ReleaseIfNotNull(ref debugEvent);

            return S_OK;
        }