Esempio n. 1
0
        protected unsafe override void Handle()
        {
            if (!RSession.IsHostRunning)
            {
                return;
            }

            var debugger = VsAppShell.Current.GetGlobalService <IVsDebugger2>(typeof(SVsShellDebugger));

            if (debugger == null)
            {
                return;
            }

            var pDebugEngines = stackalloc Guid[1];

            pDebugEngines[0] = DebuggerGuids.DebugEngine;

            uint pid = RDebugPortSupplier.GetProcessId(RSession.Id);

            var debugTarget = new VsDebugTargetInfo2 {
                cbSize = (uint)Marshal.SizeOf <VsDebugTargetInfo2>(),

                dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning,
                guidPortSupplier      = DebuggerGuids.PortSupplier,
                bstrPortName          = "dummy", // doesn't actually matter, but must not be an empty string
                guidLaunchDebugEngine = DebuggerGuids.DebugEngine,
                dwDebugEngineCount    = 1,
                pDebugEngines         = (IntPtr)pDebugEngines,
                //LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop,

                // R debug port provider represents sessions as pseudo-processes with process ID mapped
                // to session ID. For LaunchDebugTargets2 to attach a process by ID rather than by name,
                // dwProcessId must be set accordingly, _and_ bstrExe must be set to \0 + hex ID.
                dwProcessId = pid,
                bstrExe     = (char)0 + "0x" + pid.ToString("X", CultureInfo.InvariantCulture),
            };

            var pDebugTarget = stackalloc byte[Marshal.SizeOf(debugTarget)];

            Marshal.StructureToPtr(debugTarget, (IntPtr)pDebugTarget, false);

            Marshal.ThrowExceptionForHR(debugger.LaunchDebugTargets2(1, (IntPtr)pDebugTarget));

            // If we have successfully attached, VS has switched to debugging UI context, which hides
            // the REPL window. Show it again and give it focus.
            _interactiveWorkflow.ActiveWindow?.Container.Show(true);
        }
Esempio n. 2
0
        protected unsafe override void Handle()
        {
            if (!RSession.IsHostRunning)
            {
                return;
            }

            var debugger = VsAppShell.Current.GetGlobalService <IVsDebugger2>(typeof(SVsShellDebugger));

            if (debugger == null)
            {
                return;
            }

            var pDebugEngines = stackalloc Guid[1];

            pDebugEngines[0] = DebuggerGuids.DebugEngine;

            uint pid = RDebugPortSupplier.GetProcessId(RSession.Id);

            var debugTarget = new VsDebugTargetInfo2 {
                cbSize                = (uint)Marshal.SizeOf <VsDebugTargetInfo2>(),
                dlo                   = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning,
                guidPortSupplier      = DebuggerGuids.PortSupplier,
                bstrPortName          = RDebugPortSupplier.PortName,
                guidLaunchDebugEngine = DebuggerGuids.DebugEngine,
                dwDebugEngineCount    = 1,
                pDebugEngines         = (IntPtr)pDebugEngines,
                dwProcessId           = pid,
                bstrExe               = RDebugPortSupplier.GetExecutableForAttach(pid),
            };

            var pDebugTarget = stackalloc byte[Marshal.SizeOf(debugTarget)];

            Marshal.StructureToPtr(debugTarget, (IntPtr)pDebugTarget, false);

            Marshal.ThrowExceptionForHR(debugger.LaunchDebugTargets2(1, (IntPtr)pDebugTarget));

            // If we have successfully attached, VS has switched to debugging UI context, which hides
            // the REPL window. Show it again and give it focus.
            _interactiveWorkflow.ActiveWindow?.Container.Show(focus: true, immediate: false);
        }
Esempio n. 3
0
        public override Task <IReadOnlyList <IDebugLaunchSettings> > QueryDebugTargetsAsync(DebugLaunchOptions launchOptions)
        {
            var targets = new List <IDebugLaunchSettings>();

            if (Session.IsHostRunning)
            {
                uint pid = RDebugPortSupplier.GetProcessId(Session.Id);

                var target = new DebugLaunchSettings(launchOptions)
                {
                    LaunchOperation       = DebugLaunchOperation.AlreadyRunning,
                    PortSupplierGuid      = DebuggerGuids.PortSupplier,
                    PortName              = RDebugPortSupplier.PortName,
                    LaunchDebugEngineGuid = DebuggerGuids.DebugEngine,
                    ProcessId             = (int)pid,
                    Executable            = RDebugPortSupplier.GetExecutableForAttach(pid),
                };

                targets.Add(target);
            }

            return(Task.FromResult((IReadOnlyList <IDebugLaunchSettings>)targets));
        }