Esempio n. 1
0
        public static int LaunchDebugTargets(this IVsDebugger2 debugger, params VsDebugTargetInfo2[] targets)
        {
            IntPtr ptr             = IntPtr.Zero;
            int    marshalledCount = 0;

            try
            {
                ptr = Marshal.AllocHGlobal(targets.Length * Marshal.SizeOf(typeof(VsDebugTargetInfo2)));
                for (int i = 0; i < targets.Length; i++)
                {
                    IntPtr current = new IntPtr(ptr.ToInt64() + i * Marshal.SizeOf(typeof(VsDebugTargetInfo2)));
                    Marshal.StructureToPtr(targets[i], current, false);
                    marshalledCount++;
                }

                return(debugger.LaunchDebugTargets2((uint)targets.Length, ptr));
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    for (int i = 0; i < marshalledCount; i++)
                    {
                        IntPtr current = new IntPtr(ptr.ToInt64() + i * Marshal.SizeOf(typeof(VsDebugTargetInfo2)));
                        Marshal.DestroyStructure(current, typeof(VsDebugTargetInfo2));
                    }

                    Marshal.FreeHGlobal(ptr);
                    ptr = IntPtr.Zero;
                }
            }
        }
        public int GetEngineInfo(out string pbstrEngine, out Guid pguidEngine)
        {
            pguidEngine = JavaDebuggerConstants.JavaDebugEngineGuid;
            IVsDebugger2 shellDebugger = (IVsDebugger2)Package.GetGlobalService(typeof(SVsShellDebugger));

            return(shellDebugger.GetEngineName(ref pguidEngine, out pbstrEngine));
        }
 public SymbolSettingsProvider(IVsDebuggerSymbolSettingsManager120A symbolSettingsManager,
                               IVsDebugger2 debuggerService, bool symbolServerEnabled,
                               JoinableTaskContext taskContext)
 {
     _symbolSettingsManager = symbolSettingsManager ?? throw new ArgumentNullException();
     _debuggerService       = debuggerService;
     IsSymbolServerEnabled  = symbolServerEnabled;
     _taskContext           = taskContext ?? throw new ArgumentNullException();
 }
Esempio n. 4
0
        public static DBGMODE GetInternalDebugMode(this IVsDebugger2 debugger)
        {
            DBGMODE[] mode = new DBGMODE[1];
            if (ErrorHandler.Failed(debugger.GetInternalDebugMode(mode)))
            {
                return(DBGMODE.DBGMODE_Design);
            }

            return(mode[0]);
        }
Esempio n. 5
0
        public static int LaunchDebugTargets(this IVsDebugger2 debugger, params DebugTargetInfo[] targets)
        {
            VsDebugTargetInfo2[] vstargets = new VsDebugTargetInfo2[targets.Length];

            try
            {
                for (int i = 0; i < targets.Length; i++)
                {
                    vstargets[i].bstrArg           = targets[i].Arguments;
                    vstargets[i].bstrCurDir        = targets[i].CurrentDirectory;
                    vstargets[i].bstrEnv           = GetEnvironmentString(targets[i].Environment);
                    vstargets[i].bstrExe           = targets[i].Executable;
                    vstargets[i].bstrOptions       = targets[i].Options;
                    vstargets[i].bstrPortName      = targets[i].PortName;
                    vstargets[i].bstrRemoteMachine = targets[i].RemoteMachine;
                    vstargets[i].cbSize            = (uint)Marshal.SizeOf(typeof(VsDebugTargetInfo2));
                    vstargets[i].dlo                   = (uint)targets[i].LaunchOperation;
                    vstargets[i].dwProcessId           = targets[i].ProcessId;
                    vstargets[i].dwReserved            = 0;
                    vstargets[i].fSendToOutputWindow   = targets[i].SendToOutputWindow ? 1 : 0;
                    vstargets[i].guidLaunchDebugEngine = Guid.Empty;
                    vstargets[i].guidPortSupplier      = targets[i].PortSupplier;
                    vstargets[i].guidProcessLanguage   = targets[i].ProcessLanguage;
                    //vstargets[i].hStdError = targets[i].StdError;
                    //vstargets[i].hStdInput = targets[i].StdInput;
                    //vstargets[i].hStdOutput = targets[i].StdOutput;
                    vstargets[i].LaunchFlags = (uint)targets[i].LaunchFlags;
                    vstargets[i].pUnknown    = null;

                    vstargets[i].dwDebugEngineCount = (uint)targets[i].DebugEngines.Length;
                    vstargets[i].pDebugEngines      = Marshal.AllocHGlobal(targets[i].DebugEngines.Length * Marshal.SizeOf(typeof(Guid)));
                    for (int j = 0; j < targets[i].DebugEngines.Length; j++)
                    {
                        Marshal.StructureToPtr(targets[i].DebugEngines[j], new IntPtr(vstargets[i].pDebugEngines.ToInt64() + j * Marshal.SizeOf(typeof(Guid))), false);
                    }
                }

                return(debugger.LaunchDebugTargets(vstargets));
            }
            finally
            {
                for (int i = 0; i < vstargets.Length; i++)
                {
                    if (vstargets[i].pDebugEngines != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(vstargets[i].pDebugEngines);
                    }
                }
            }
        }
        public unsafe int DebugLaunch(uint grfLaunch)
        {
            try
            {
                if (!this.m_project.CanLaunch)
                {
                    Utility.ShowMessageBox("The project must have either an output type of 'Console Application', or an output type of 'Class Library' and the start action set to a valid .NET MicroFramework application");
                    return(Utility.COM_HResults.E_FAIL);
                }

                //Consider Launching ourselves (at least for device), and then calling Attach.
                //This would get rid of the ugly dummy thread hack in CorDebugProcess.
                //However, we would need to jump through some other hoops, like resuming the process,
                //perhaps setting up the entry point breakpoint ourselves, ..?

                VsDebugTargetInfo2 vsDebugTargetInfo = new VsDebugTargetInfo2();
                DebugPort          port         = GetDebugPort();
                Process            processWin32 = null;
                bool fNoDebug = (__VSDBGLAUNCHFLAGS.DBGLAUNCH_NoDebug & (__VSDBGLAUNCHFLAGS)grfLaunch) != 0;
                int  hRes     = Utility.COM_HResults.S_OK;
                PlatformInfo.Emulator emulatorConfig = GetEmulatorConfig();

                if (port == null)
                {
                    throw new Exception("Cannot find port to deploy to");
                }

                string commandLine = GetCommandLineForLaunch(fNoDebug, emulatorConfig, IsTargetBigEndian());
                string exe         = port.IsLocalPort ? emulatorConfig.application : typeof(CorDebugProcess).Assembly.Location;

                if (!fNoDebug)
                {
                    commandLine = string.Format("{0} \"{1}{2}\"", commandLine, CorDebugProcess.c_DeployDeviceName, this.DeployDeviceName);
                }

                //use emulator args even though this may be a device launch.  This is needed to store
                //paths to assemblies.
                vsDebugTargetInfo.bstrArg           = commandLine;
                vsDebugTargetInfo.bstrCurDir        = (string)m_project.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir);
                vsDebugTargetInfo.bstrEnv           = null;
                vsDebugTargetInfo.bstrExe           = exe;
                vsDebugTargetInfo.bstrOptions       = null;
                vsDebugTargetInfo.bstrPortName      = DeployTransportName;
                vsDebugTargetInfo.bstrRemoteMachine = null;
                vsDebugTargetInfo.cbSize            = (uint)Marshal.SizeOf(vsDebugTargetInfo);
                vsDebugTargetInfo.dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
                vsDebugTargetInfo.dwDebugEngineCount    = 0;
                vsDebugTargetInfo.dwProcessId           = 0;
                vsDebugTargetInfo.dwReserved            = 0;
                vsDebugTargetInfo.fSendToOutputWindow   = 0;
                vsDebugTargetInfo.guidLaunchDebugEngine = CorDebug.s_guidDebugEngine;
                vsDebugTargetInfo.guidPortSupplier      = DebugPortSupplier.s_guidPortSupplier;
                vsDebugTargetInfo.guidProcessLanguage   = Guid.Empty;
                vsDebugTargetInfo.hStdError             = 0;
                vsDebugTargetInfo.hStdInput             = 0;
                vsDebugTargetInfo.hStdOutput            = 0;
                vsDebugTargetInfo.LaunchFlags           = grfLaunch;
                vsDebugTargetInfo.pDebugEngines         = IntPtr.Zero;
                vsDebugTargetInfo.pUnknown = null;

                if (fNoDebug)
                {
                    if (port.IsLocalPort)
                    {
                        processWin32 = new Process();

                        processWin32.StartInfo                  = new ProcessStartInfo();
                        processWin32.StartInfo.FileName         = vsDebugTargetInfo.bstrExe;
                        processWin32.StartInfo.Arguments        = vsDebugTargetInfo.bstrArg;
                        processWin32.StartInfo.WorkingDirectory = vsDebugTargetInfo.bstrCurDir;
                        processWin32.StartInfo.UseShellExecute  = false;
                        processWin32.Start();
                    }
                    else
                    {
                        RebootAndResumeExecution();
                    }
                }
                else
                {
                    byte * bpDebugTargetInfo = stackalloc byte[(int)vsDebugTargetInfo.cbSize];
                    IntPtr ipDebugTargetInfo = (IntPtr)bpDebugTargetInfo;
                    try
                    {
                        IVsDebugger2 iVsDebugger = ( IVsDebugger2 )ServiceProvider.GlobalProvider.GetService(typeof(IVsDebugger));
                        Marshal.StructureToPtr(vsDebugTargetInfo, ipDebugTargetInfo, false);
                        hRes = iVsDebugger.LaunchDebugTargets2(1, ipDebugTargetInfo);
                    }
                    finally
                    {
                        if (ipDebugTargetInfo != null)
                        {
                            Marshal.DestroyStructure(ipDebugTargetInfo, vsDebugTargetInfo.GetType());
                        }
                    }
                }

                return(hRes);
            }
            catch (Exception ex)
            {
                Utility.ShowMessageBox(String.Format("An exception occurred while attempting to launch the debugger: {0}", ex.Message));
                return(Utility.COM_HResults.E_FAIL);
            }
        }
Esempio n. 7
0
        public static void AttachToProcess(Process[] processes, ChildDebuggingMode mode)
        {
            List <VsDebugTargetInfo2> targetList = new List <VsDebugTargetInfo2>();
            IntPtr targetsBuffer = IntPtr.Zero;
            int    targetSize    = Marshal.SizeOf(typeof(VsDebugTargetInfo2));
            int    guidSize      = Marshal.SizeOf(typeof(Guid));

            try {
                foreach (Process process in processes)
                {
                    NtProcess           ntproc  = new NtProcess(process.Id);
                    VsDebugTargetInfo2  target  = new VsDebugTargetInfo2();
                    DebugProcessOptions options = new DebugProcessOptions {
                        ChildDebuggingMode = mode
                    };
                    target.dwDebugEngineCount = 1;
                    target.dwProcessId        = (uint)process.Id;
                    target.dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning;
                    if (process.Threads.Count == 1)
                    {
                        // If this is a suspended process, then using DLO_AttachToSuspendedLaunchProcess will
                        // bypass the initial loader breakpoint, causing a seamless and transparent attach.
                        // This is usually the desired behavior, as child processes frequently startup and
                        // shutdown, and it is intrusive to be constantly breaking into the debugger.
                        ProcessThread mainThread = process.Threads[0];
                        if (mainThread.ThreadState == ThreadState.Wait && mainThread.WaitReason == ThreadWaitReason.Suspended)
                        {
                            target.dlo |= (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AttachToSuspendedLaunchProcess;
                        }
                    }
                    target.bstrExe          = ntproc.Win32ProcessImagePath;
                    target.cbSize           = (uint)targetSize;
                    target.bstrCurDir       = null;
                    target.guidPortSupplier = DkmIntegration.Guids.PortSupplier.Default;
                    target.LaunchFlags      = (uint)(__VSDBGLAUNCHFLAGS.DBGLAUNCH_Silent | __VSDBGLAUNCHFLAGS.DBGLAUNCH_WaitForAttachComplete);
                    target.bstrOptions      = options.OptionsString;
                    target.pDebugEngines    = Marshal.AllocCoTaskMem(guidSize);
                    Marshal.StructureToPtr(DkmEngineId.NativeEng, target.pDebugEngines, false);
                    targetList.Add(target);
                }
                int elementSize = Marshal.SizeOf(typeof(VsDebugTargetInfo2));
                targetsBuffer = Marshal.AllocCoTaskMem(targetList.Count * elementSize);
                for (int i = 0; i < targetList.Count; ++i)
                {
                    IntPtr writeAddr = targetsBuffer + i * elementSize;
                    Marshal.StructureToPtr(targetList[i], writeAddr, false);
                }

                IVsDebugger2 debugger = (IVsDebugger2)VsPackage.GetGlobalService(typeof(SVsShellDebugger));
                Logger.LogInfo("Launching {0} debug targets", processes.Length);
                int hr = debugger.LaunchDebugTargets2((uint)processes.Length, targetsBuffer);
                if (hr != 0)
                {
                    IVsUIShell shell = (IVsUIShell)VsPackage.GetGlobalService(typeof(SVsUIShell));
                    string     error;
                    shell.GetErrorInfo(out error);
                    Logger.LogError("An error occured while attaching to process (hr = 0x{0:x}).  {1}", hr, error);
                }
            } finally {
                foreach (VsDebugTargetInfo2 target in targetList)
                {
                    if (target.pDebugEngines != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(target.pDebugEngines);
                    }
                }

                if (targetsBuffer != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(targetsBuffer);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// </summary>
        private void onStartDebugging(object sender, EventArgs e)
        {
            m_context |= (int)UIContext.AlcStart;

            DTE dte = (DTE)GetService(typeof(DTE));

            IVsOutputWindowPane pane = (IVsOutputWindowPane)Package.GetGlobalService(typeof(SVsGeneralOutputWindowPane));

            VCProjectW       vcproj;
            VCConfigurationW cfg;

            if (!ProjectUtil.getStartupProjectAndConfig(dte, out vcproj, out cfg))
            {
                return;
            }

            String exepath     = cfg.Evaluate("$(TargetPath)");
            String workdir     = cfg.Evaluate("$(LocalDebuggerWorkingDirectory)");
            String environment = cfg.Evaluate("$(LocalDebuggerEnvironment)");
            String platform    = cfg.Evaluate("$(Platform)");
            String addindir    = m_addindir;

            if (pane != null)
            {
                pane.OutputString(exepath);
            }

            if (!File.Exists(exepath))
            {
                ShowMessage("Alcantarea: Error", "Executabe " + exepath + " not found");
                return;
            }

            // プロセスを suspend で起動して DynamicPatcher を inject
            uint pid = AlcantareaHelper.ExecuteSuspended(exepath, workdir, addindir, environment, platform);

            if (pid != 0)
            {
                // デバッガを attach
                VsDebugTargetInfo2 info = new VsDebugTargetInfo2();
                info.cbSize  = (uint)Marshal.SizeOf(info);
                info.bstrExe = exepath;
                info.dlo     = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning;
                //info.dlo = (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AttachToSuspendedLaunchProcess; // somehow this makes debugger not work
                info.dwProcessId = pid;
                info.LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd | (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop;

                Guid   guidDbgEngine = VSConstants.DebugEnginesGuids.ManagedAndNative_guid;
                IntPtr pGuids        = Marshal.AllocCoTaskMem(Marshal.SizeOf(guidDbgEngine));
                Marshal.StructureToPtr(guidDbgEngine, pGuids, false);
                info.pDebugEngines      = pGuids;
                info.dwDebugEngineCount = 1;

                IVsDebugger2 idbg = (IVsDebugger2)Package.GetGlobalService(typeof(SVsShellDebugger));
                IntPtr       ptr  = Marshal.AllocCoTaskMem((int)info.cbSize);
                Marshal.StructureToPtr(info, ptr, false);
                int ret = idbg.LaunchDebugTargets2(1, ptr);

                // プロセスのスレッドを resume
                AlcantareaHelper.Resume(pid);
            }
        }