private IntPtr GetDebugInfo(DebugOptions debugOptions)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var startupAssemblyPath = GetStartupAssemblyPath();
            var targetExeFileName   = Path.GetFileName(startupAssemblyPath);
            var outputDirectory     = Path.GetDirectoryName(startupAssemblyPath);

            var info = new VsDebugTargetInfo()
            {
                //cbSize = (uint)Marshal.SizeOf(info),
                dlo               = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess,
                bstrExe           = targetExeFileName,
                bstrCurDir        = outputDirectory,
                bstrArg           = GetStartArguments(),
                bstrRemoteMachine = null,                                                  // debug locally
                grfLaunch         = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd, // When this process ends, debugging is stopped.
                //grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop, // Detaches instead of terminating when debugging stopped.
                fSendStdoutToOutputWindow = 0,
                clsidCustom = DebugEngineGuids.EngineGuid,
                //bstrEnv = "",
                bstrOptions       = debugOptions.SerializeToJson(), // add debug engine options
                bstrPortName      = "Mono",
                clsidPortSupplier = DebugEngineGuids.ProgramProviderGuid
            };

            info.cbSize = (uint)Marshal.SizeOf(info);

            IntPtr pInfo = Marshal.AllocCoTaskMem((int)info.cbSize);

            Marshal.StructureToPtr(info, pInfo, false);
            return(pInfo);
        }
        private void SetupDebugTargetInfoForNodeProtocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            var target = $"\"{vsDebugTargetInfo.bstrExe}\"";

            if (debugLaunchContext.LaunchConfiguration.TryGetValue <string>(ScriptArgsKey, out var scriptArgs) && !string.IsNullOrWhiteSpace(scriptArgs))
            {
                target += " " + scriptArgs;
            }
            vsDebugTargetInfo.bstrArg = target;

            vsDebugTargetInfo.bstrExe = nodeExe;
            if (debugLaunchContext.LaunchConfiguration.TryGetValue <string>(NodeArgsKey, out var nodeArgs) && !string.IsNullOrWhiteSpace(nodeArgs))
            {
                AppendOption(ref vsDebugTargetInfo, AD7Engine.InterpreterOptions, nodeArgs);
            }

            if (debugLaunchContext.LaunchConfiguration.TryGetValue <string>(DebuggerPortKey, out var debuggerPort) && !string.IsNullOrWhiteSpace(debuggerPort))
            {
                AppendOption(ref vsDebugTargetInfo, AD7Engine.DebuggerPort, debuggerPort);
            }
            AppendOption(ref vsDebugTargetInfo, AD7Engine.WaitOnNormalExitSetting, "true"); // todo: make this an option

            vsDebugTargetInfo.clsidCustom = AD7Engine.DebugEngineGuid;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;

            void AppendOption(ref VsDebugTargetInfo dbgInfo, string option, string value)
            {
                if (!string.IsNullOrWhiteSpace(dbgInfo.bstrOptions))
                {
                    dbgInfo.bstrOptions += ";";
                }

                dbgInfo.bstrOptions += option + "=" + HttpUtility.UrlEncode(value);
            }
        }
Example #3
0
        /// <devdoc>
        /// Launch the debugger.
        /// </devdoc>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="info">A reference to a VsDebugTargetInfo object.</param>
        public static void LaunchDebugger(IServiceProvider serviceProvider, VsDebugTargetInfo info)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentException("serviceProvider");
            }

            info.cbSize = (uint)Marshal.SizeOf(info);
            IntPtr ptr = Marshal.AllocCoTaskMem((int)info.cbSize);

            Marshal.StructureToPtr(info, ptr, false);

            try
            {
                IVsDebugger d = serviceProvider.GetService(typeof(IVsDebugger)) as IVsDebugger;

                if (d == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(d.LaunchDebugTargets(1, ptr));
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
        }
        private void AppendOption(ref VsDebugTargetInfo dbgInfo, string option, string value) {
            if (!String.IsNullOrWhiteSpace(dbgInfo.bstrOptions)) {
                dbgInfo.bstrOptions += ";";
            }

            dbgInfo.bstrOptions += option + "=" + HttpUtility.UrlEncode(value);
        }
Example #5
0
        /// <summary>
        /// Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile)
        {
            VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();

            dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);
            IntPtr ptr = Marshal.AllocCoTaskMem((int)dbgInfo.cbSize);

            try {
                Marshal.StructureToPtr(dbgInfo, ptr, false);
                SetupDebugInfo(ref dbgInfo, startupFile);

                if (string.IsNullOrEmpty(dbgInfo.bstrExe))
                {
                    MessageBox.Show(
                        "The project cannot be debugged because its active Python environment does not have the interpreter executable specified.",
                        "Python Tools for Visual Studio", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                LaunchDebugger(_serviceProvider, dbgInfo);
            } finally {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile)
        {
            VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();

            try {
                dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);
                SetupDebugInfo(ref dbgInfo, startupFile);

                if (string.IsNullOrEmpty(dbgInfo.bstrExe))
                {
                    if (!NoInterpretersAvailable())
                    {
                        MessageBox.Show(
                            "The project cannot be debugged because its active Lua environment does not have the interpreter executable specified.",
                            "Lua Tools for Visual Studio", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return;
                }

                LaunchDebugger(BabePackage.Current, dbgInfo);
            } finally {
                if (dbgInfo.pClsidList != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(dbgInfo.pClsidList);
                }
            }
        }
Example #7
0
        private void SetupDebugTargetInfoForWebkitV2Protocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            // todo: refactor the debugging and process starting so we can re-use

            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = Path.GetDirectoryName(target); // Current working directory

            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", target),
                new JProperty("runtimeExecutable", nodeExe),
                new JProperty("cwd", cwd),
                new JProperty("console", "externalTerminal"),
                new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true));

            var jsonContent = configuration.ToString();

            vsDebugTargetInfo.dlo         = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.clsidCustom = NodejsProjectLauncher.WebKitDebuggerV2Guid;
            vsDebugTargetInfo.bstrExe     = target;
            vsDebugTargetInfo.bstrOptions = jsonContent;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
        //public static string ComputeHash(string file)
        //{
        //    using (FileStream stream = File.OpenRead(file))
        //    {
        //        var sha = new SHA256Managed();
        //        byte[] checksum = sha.ComputeHash(stream);
        //        return BitConverter.ToString(checksum).Replace("-", string.Empty);
        //    }
        //}

        private IntPtr GetDebugInfo(DebugOptions debugOptions)//string args, int debugPort, string targetExe, string outputDirectory)
        {
            var info = new VsDebugTargetInfo()
            {
                //cbSize = (uint)Marshal.SizeOf(info),
                dlo               = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess,
                bstrExe           = debugOptions.StartupAssemblyPath,
                bstrCurDir        = debugOptions.OutputDirectory,
                bstrArg           = debugOptions.StartArguments,
                bstrRemoteMachine = null,                                                  // debug locally
                grfLaunch         = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd, // When this process ends, debugging is stopped.
                //grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop, // Detaches instead of terminating when debugging stopped.
                fSendStdoutToOutputWindow = 0,
                clsidCustom = DebugEngineGuids.EngineGuid,
                //bstrEnv = "",
                bstrOptions = debugOptions.SerializeToJson() // add debug engine options
            };

            if (DebugEngineGuids.UseAD7Engine == EngineType.XamarinEngine)
            {
                info.bstrPortName      = "Mono";
                info.clsidPortSupplier = DebugEngineGuids.ProgramProviderGuid;
            }

            info.cbSize = (uint)Marshal.SizeOf(info);

            IntPtr pInfo = Marshal.AllocCoTaskMem((int)info.cbSize);

            Marshal.StructureToPtr(info, pInfo, false);
            return(pInfo);
        }
Example #9
0
        /// <devdoc>
        /// Launch the debugger.
        /// </devdoc>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="info">A reference to a VsDebugTargetInfo object.</param>
        public static void LaunchDebugger(IServiceProvider serviceProvider, VsDebugTargetInfo info)
        {
            if (serviceProvider == null)
                throw new ArgumentException("serviceProvider");

            info.cbSize = (uint)Marshal.SizeOf(info);
            IntPtr ptr = Marshal.AllocCoTaskMem((int)info.cbSize);
            Marshal.StructureToPtr(info, ptr, false);

            try
            {
                IVsDebugger d = serviceProvider.GetService(typeof(IVsDebugger)) as IVsDebugger;

                if (d == null)
                    throw new InvalidOperationException();

                ErrorHandler.ThrowOnFailure(d.LaunchDebugTargets(1, ptr));
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
        }
Example #10
0
        protected void LaunchDebugTarget()
        {
            Microsoft.VisualStudio.Shell.ServiceProvider sp =
                new Microsoft.VisualStudio.Shell.ServiceProvider((IOleServiceProvider)Dte);

            IVsDebugger dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));

            VsDebugTargetInfo info = new VsDebugTargetInfo();


            info.cbSize     = (uint)Marshal.SizeOf(info);
            info.dlo        = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            info.bstrExe    = Moniker;
            info.bstrCurDir = @"C:\";
            string connectionString = HierarchyAccessor.Connection.ConnectionSupport.ConnectionString + ";Allow User Variables=true;Allow Zero DateTime=true;";

            if (connectionString.IndexOf("password", StringComparison.OrdinalIgnoreCase) == -1)
            {
                var connection = (MySqlConnection)HierarchyAccessor.Connection.GetLockedProviderObject();
                try
                {
                    var settings = (MySqlConnectionStringBuilder)connection.GetType().GetProperty("Settings", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(connection, null);
                    connectionString += "password="******";Persist Security Info=true;";
                }
                finally
                {
                    HierarchyAccessor.Connection.UnlockProviderObject();
                }
            }
            info.bstrArg                   = connectionString;
            info.bstrRemoteMachine         = null;                                               // Environment.MachineName; // debug locally
            info.fSendStdoutToOutputWindow = 0;                                                  // Let stdout stay with the application.
            info.clsidCustom               = new Guid("{EEEE0740-10F7-4e5f-8BC4-1CC0AC9ED5B0}"); // Set the launching engine the sample engine guid
            info.grfLaunch                 = 0;

            IntPtr pInfo = Marshal.AllocCoTaskMem((int)info.cbSize);

            Marshal.StructureToPtr(info, pInfo, false);

            try
            {
                int result = dbg.LaunchDebugTargets(1, pInfo);
                if (result != 0 && result != VSConstants.E_ABORT)
                {
                    throw new ApplicationException("COM error " + result);
                }
            }
            catch (Exception ex)
            {
                InfoDialog.ShowDialog(InfoDialogProperties.GetErrorDialogProperties("Debugger Error", ex.GetBaseException().Message));
            }
            finally
            {
                if (pInfo != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pInfo);
                }
            }
        }
Example #11
0
        public override int DebugLaunch(uint grfLaunch)
        {
            Logger.Debug(string.Empty);

            var debugger = ProjectMgr.Site.GetService(typeof(SVsShellDebugger)) as IVsDebugger;
            var shell    = ProjectMgr.Site.GetService(typeof(SVsUIShell)) as IVsUIShell;

            var info = new VsDebugTargetInfo();

            info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            info.bstrExe                   = @"C:\script.ps1";
            info.bstrCurDir                = Path.GetDirectoryName(info.bstrExe);
            info.bstrArg                   = null;
            info.bstrRemoteMachine         = null;
            info.fSendStdoutToOutputWindow = 1;
            info.clsidCustom               = EngineGuids.PowerStudioEngineGuid;
            info.clsidPortSupplier         = typeof(DefaultPortSupplier).GUID;
            info.grfLaunch                 = 0; //grfLaunch;
            info.cbSize = (uint)Marshal.SizeOf(info);
            IntPtr pInfo = Marshal.AllocCoTaskMem((int)info.cbSize);

            try
            {
                Marshal.StructureToPtr(info, pInfo, false);
                var eventManager = new PowerShellDebuggerEvents();

                if (debugger.AdviseDebugEventCallback(eventManager) !=
                    VSConstants.S_OK)
                {
                    Trace.WriteLine("Failed to advise the UI of debug events.");
                    if (pInfo != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(pInfo);
                    }
                    return(VSConstants.E_UNEXPECTED);
                }

                debugger.LaunchDebugTargets(1, pInfo);
                //VsShellUtilities.LaunchDebugger(ProjectMgr.Site, info);

                string message;
                shell.GetErrorInfo(out message);

                if (!String.IsNullOrWhiteSpace(message))
                {
                    Logger.Error(message);
                }
            }
            finally
            {
                if (pInfo != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pInfo);
                }
            }

            return(VSConstants.S_OK);
        }
        public override int DebugLaunch( uint grfLaunch )
        {
            Logger.Debug( string.Empty );

            var debugger = ProjectMgr.Site.GetService( typeof (SVsShellDebugger) ) as IVsDebugger;
            var shell = ProjectMgr.Site.GetService( typeof (SVsUIShell) ) as IVsUIShell;

            var info = new VsDebugTargetInfo();

            info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            info.bstrExe = @"C:\script.ps1";
            info.bstrCurDir = Path.GetDirectoryName( info.bstrExe );
            info.bstrArg = null;
            info.bstrRemoteMachine = null;
            info.fSendStdoutToOutputWindow = 1;
            info.clsidCustom = EngineGuids.PowerStudioEngineGuid;
            info.clsidPortSupplier = typeof (DefaultPortSupplier).GUID;
            info.grfLaunch = 0; //grfLaunch;
            info.cbSize = (uint) Marshal.SizeOf( info );
            IntPtr pInfo = Marshal.AllocCoTaskMem( (int) info.cbSize );

            try
            {
                Marshal.StructureToPtr( info, pInfo, false );
                var eventManager = new PowerShellDebuggerEvents();

                if ( debugger.AdviseDebugEventCallback( eventManager ) !=
                     VSConstants.S_OK )
                {
                    Trace.WriteLine( "Failed to advise the UI of debug events." );
                    if ( pInfo != IntPtr.Zero )
                    {
                        Marshal.FreeCoTaskMem( pInfo );
                    }
                    return VSConstants.E_UNEXPECTED;
                }

                debugger.LaunchDebugTargets( 1, pInfo );
                //VsShellUtilities.LaunchDebugger(ProjectMgr.Site, info);

                string message;
                shell.GetErrorInfo( out message );

                if ( !String.IsNullOrWhiteSpace( message ) )
                {
                    Logger.Error( message );
                }
            }
            finally
            {
                if ( pInfo != IntPtr.Zero )
                {
                    Marshal.FreeCoTaskMem( pInfo );
                }
            }

            return VSConstants.S_OK;
        }
        /// <summary>
        /// Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile) {
            VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();
            dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);

            if (SetupDebugInfo(ref dbgInfo, startupFile)) {
                LaunchDebugger(_project.Site, dbgInfo);
            }
        }
Example #14
0
        public int LaunchSelection(string selection)
        {
            Log.Debug("PowerShellProjectLauncher.LaunchSelection");
            var debugger = (IVsDebugger)Package.GetGlobalService(typeof(IVsDebugger));
            var shell    = (IVsUIShell)Package.GetGlobalService(typeof(IVsUIShell));

            var info = new VsDebugTargetInfo();

            info.cbSize = (uint)Marshal.SizeOf(info);
            info.dlo    = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            info.bstrExe                   = "Selection";
            info.bstrCurDir                = Environment.CurrentDirectory;
            info.bstrOptions               = selection;
            info.bstrArg                   = null; // no command line parameters
            info.bstrRemoteMachine         = null; // debug locally
            info.fSendStdoutToOutputWindow = 0;    // Let stdout stay with the application.
            info.clsidCustom               = new Guid("{43ACAB74-8226-4920-B489-BFCF05372437}");
            // Set the launching engine the sample engine guid
            info.grfLaunch = 0;
            //info.clsidPortSupplier = new Guid("FEF0E138-4F86-467D-B5FB-46888D0D1A41");

            IntPtr pInfo = Marshal.AllocCoTaskMem((int)info.cbSize);

            Marshal.StructureToPtr(info, pInfo, false);

            var eventManager = new DebugEventManager(PowerShellToolsPackage.Debugger.Runspace);

            if (debugger.AdviseDebugEventCallback(eventManager) != VSConstants.S_OK)
            {
                Log.Debug("Failed to advise the UI of debug events.");
                if (pInfo != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pInfo);
                }
            }

            try
            {
                debugger.LaunchDebugTargets(1, pInfo);
                string outstr;
                shell.GetErrorInfo(out outstr);

                if (!String.IsNullOrWhiteSpace(outstr))
                {
                    Log.Debug("Error:" + outstr);
                }
            }
            finally
            {
                if (pInfo != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pInfo);
                }
            }

            return(VSConstants.S_OK);
        }
        public virtual int DebugLaunch(uint flags)
        {
            CCITracing.TraceCall();

            try
            {
                VsDebugTargetInfo info = new VsDebugTargetInfo();
                info.cbSize = (uint)Marshal.SizeOf(info);
                info.dlo    = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

                // On first call, reset the cache, following calls will use the cached values
                string property = GetConfigurationProperty("StartProgram", true);
                if (string.IsNullOrEmpty(property))
                {
                    info.bstrExe = this.project.GetOutputAssembly(this.ConfigName);
                }
                else
                {
                    info.bstrExe = property;
                }

                property = GetConfigurationProperty("WorkingDirectory", false);
                if (string.IsNullOrEmpty(property))
                {
                    info.bstrCurDir = Path.GetDirectoryName(info.bstrExe);
                }
                else
                {
                    info.bstrCurDir = property;
                }

                property = GetConfigurationProperty("CmdArgs", false);
                if (!string.IsNullOrEmpty(property))
                {
                    info.bstrArg = property;
                }

                property = GetConfigurationProperty("RemoteDebugMachine", false);
                if (property != null && property.Length > 0)
                {
                    info.bstrRemoteMachine = property;
                }

                info.fSendStdoutToOutputWindow = 0;
                info.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine;
                info.grfLaunch   = flags;
                VsShellUtilities.LaunchDebugger(this.project.Site, info);
            }
            catch (Exception e)
            {
                Trace.WriteLine("Exception : " + e.Message);

                return(Marshal.GetHRForException(e));
            }

            return(VSConstants.S_OK);
        }
Example #16
0
        /// <summary>
        ///     Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile)
        {
            var dbgInfo = new VsDebugTargetInfo();

            dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);

            SetupDebugInfo(ref dbgInfo, startupFile);
            LaunchDebugger(_project.Package, dbgInfo);
        }
 private void LaunchDebugger(IServiceProvider provider, VsDebugTargetInfo dbgInfo) {
     if (!Directory.Exists(dbgInfo.bstrCurDir)) {
         MessageBox.Show(String.Format("Working directory \"{0}\" does not exist.", dbgInfo.bstrCurDir), SR.ProductName);
     } else if (!File.Exists(dbgInfo.bstrExe)) {
         MessageBox.Show(String.Format("Interpreter \"{0}\" does not exist.", dbgInfo.bstrExe), SR.ProductName);
     } else if (DoesProjectSupportDebugging()) {
         VsShellUtilities.LaunchDebugger(provider, dbgInfo);
     }
 }
Example #18
0
        private void SetupDebugTargetInfoForWebkitV2Protocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            // todo: refactor the debugging and process starting so we can re-use

            var setupConfiguration = new SetupConfiguration();
            var setupInstance      = setupConfiguration.GetInstanceForCurrentProcess();
            var visualStudioInstallationInstanceID = setupInstance.GetInstanceId();

            // The Node2Adapter depends on features only in Node v6+, so the old v5.4 version of node will not suffice for this scenario
            // This node.exe will be the one used by the node2 debug adapter, not the one used to host the user code.
            var pathToNodeExe = Path.Combine(setupInstance.GetInstallationPath(), "JavaScript\\Node.JS\\v6.4.0_x86\\Node.exe");

            // We check the registry to see if any parameters for the node.exe invocation have been specified (like "--inspect"), and append them if we find them.
            var nodeParams = NodejsProjectLauncher.CheckForRegistrySpecifiedNodeParams();

            if (!string.IsNullOrEmpty(nodeParams))
            {
                pathToNodeExe = pathToNodeExe + " " + nodeParams;
            }

            var pathToNode2DebugAdapterRuntime = Environment.ExpandEnvironmentVariables(@"""%ALLUSERSPROFILE%\" +
                                                                                        $@"Microsoft\VisualStudio\NodeAdapter\{visualStudioInstallationInstanceID}\extension\out\src\nodeDebug.js""");

            string trimmedPathToNode2DebugAdapter = pathToNode2DebugAdapterRuntime.Replace("\"", "");

            if (!File.Exists(trimmedPathToNode2DebugAdapter))
            {
                pathToNode2DebugAdapterRuntime = Environment.ExpandEnvironmentVariables(@"""%ALLUSERSPROFILE%\" +
                                                                                        $@"Microsoft\VisualStudio\NodeAdapter\{visualStudioInstallationInstanceID}\out\src\nodeDebug.js""");
            }

            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = Path.GetDirectoryName(target); // Current working directory

            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", target),
                new JProperty("runtimeExecutable", nodeExe),
                new JProperty("cwd", cwd),
                new JProperty("console", "externalTerminal"),
                new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true),
                new JProperty("$adapter", pathToNodeExe),
                new JProperty("$adapterArgs", pathToNode2DebugAdapterRuntime));

            var jsonContent = configuration.ToString();

            vsDebugTargetInfo.dlo         = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.clsidCustom = NodejsProjectLauncher.WebKitDebuggerV2Guid;
            vsDebugTargetInfo.bstrExe     = target;
            vsDebugTargetInfo.bstrOptions = jsonContent;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Example #19
0
        /// <summary>
        /// Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile)
        {
            VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();

            dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);

            SetupDebugInfo(ref dbgInfo, startupFile);

            LaunchDebugger(PythonToolsPackage.Instance, dbgInfo);
        }
Example #20
0
        public virtual void DebugLaunch(uint flags)
        {
            CCITracing.TraceCall();


            try {
                IVsDebugger d = (IVsDebugger)project.QueryService(typeof(IVsDebugger).GUID, typeof(IVsDebugger));

                VsDebugTargetInfo info = new VsDebugTargetInfo();
                info.cbSize = (uint)Marshal.SizeOf(info);
                info.dlo    = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
                if (this.node.HasAttribute("StartProgram") && this.node.GetAttribute("StartProgram").Length > 0)
                {
                    info.bstrExe = this.node.GetAttribute("StartProgram");
                }
                else
                {
                    info.bstrExe = this.project.GetOutputAssembly(node);
                }

                if (this.node.HasAttribute("WorkingDirectory") && this.node.GetAttribute("WorkingDirectory").Length > 0)
                {
                    info.bstrCurDir = this.node.GetAttribute("WorkingDirectory");
                }
                else
                {
                    info.bstrCurDir = Path.GetDirectoryName(info.bstrExe);
                }

                if (this.node.HasAttribute("CmdArgs") && this.node.GetAttribute("CmdArgs").Length > 0)
                {
                    info.bstrArg = this.node.GetAttribute("CmdArgs");
                }
                if (this.node.HasAttribute("RemoteDebugMachine") && this.node.GetAttribute("RemoteDebugMachine").Length > 0)
                {
                    info.bstrRemoteMachine = this.node.GetAttribute("RemoteDebugMachine");
                }

                info.fSendStdoutToOutputWindow = 0;
                info.clsidCustom = CLSID_ComPlusOnlyDebugEngine;
                info.grfLaunch   = flags;

                IntPtr ptr = Marshal.AllocCoTaskMem((int)info.cbSize);
                Marshal.StructureToPtr(info, ptr, false);
                try {
                    d.LaunchDebugTargets(1, ptr);
                } finally{
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
            catch (Exception e) {
                throw new SystemException("Could not launch debugger - " + e.Message);
            }
        }
        private void SetupDebugTargetInfoForInspectProtocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = vsDebugTargetInfo.bstrCurDir;

            var jsonContent = GetJsonConfigurationForInspectProtocol(target, cwd, nodeExe, debugLaunchContext);

            vsDebugTargetInfo.dlo         = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.clsidCustom = NodejsProjectLauncher.WebKitDebuggerV2Guid;
            vsDebugTargetInfo.bstrOptions = jsonContent;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Example #22
0
        /// <summary>
        ///     Sets up debugger information.
        /// </summary>
        private void SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile)
        {
            dbgInfo.dlo                       = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            dbgInfo.bstrExe                   = _pathResolver.FindFilePath(Executable);
            dbgInfo.bstrCurDir                = _project.ProjectFolder;
            dbgInfo.bstrArg                   = CreateArgumentsDebug(startupFile);
            dbgInfo.bstrRemoteMachine         = null;
            dbgInfo.fSendStdoutToOutputWindow = 0;

            // Set the Node debugger
            dbgInfo.clsidCustom = Guids.DebugEngine;
            dbgInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Example #23
0
        public void StartInBrowser(string url, Guid?debugEngine)
        {
            if (debugEngine.HasValue)
            {
                // launch via VS debugger, it'll take care of figuring out the browsers
                VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();
                dbgInfo.dlo         = (DEBUG_LAUNCH_OPERATION)_DEBUG_LAUNCH_OPERATION3.DLO_LaunchBrowser;
                dbgInfo.bstrExe     = url;
                dbgInfo.clsidCustom = debugEngine.Value;
                dbgInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd | (uint)__VSDBGLAUNCHFLAGS4.DBGLAUNCH_UseDefaultBrowser;
                dbgInfo.cbSize      = (uint)Marshal.SizeOf(dbgInfo);

                VsShellUtilities.LaunchDebugger(_serviceProvider, dbgInfo);
            }
            else
            {
                // run the users default browser
                var handler    = GetBrowserHandlerProgId();
                var browserCmd = (string)Registry.ClassesRoot.OpenSubKey(handler).OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command").GetValue("");

                if (browserCmd.IndexOf("%1") != -1)
                {
                    browserCmd = browserCmd.Replace("%1", url);
                }
                else
                {
                    browserCmd = browserCmd + " " + url;
                }
                bool   inQuote = false;
                string cmdLine = null;
                for (int i = 0; i < browserCmd.Length; i++)
                {
                    if (browserCmd[i] == '"')
                    {
                        inQuote = !inQuote;
                    }

                    if (browserCmd[i] == ' ' && !inQuote)
                    {
                        cmdLine = browserCmd.Substring(0, i);
                        break;
                    }
                }
                if (cmdLine == null)
                {
                    cmdLine = browserCmd;
                }

                Process.Start(cmdLine, browserCmd.Substring(cmdLine.Length));
            }
        }
Example #24
0
		private static VsDebugTargetInfo CreateExecutableLaunchInfo(LaunchParameters launchParameters)
		{
			var info = new VsDebugTargetInfo();
			info.cbSize = (uint)Marshal.SizeOf(info);
			info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
			info.bstrExe = Path.Combine(launchParameters.ApplicationPath, launchParameters.StartupFile);
			info.bstrCurDir = launchParameters.ApplicationPath;
			info.fSendStdoutToOutputWindow = 0;
			info.grfLaunch = (uint)__VSDBGLAUNCHFLAGS2.DBGLAUNCH_MergeEnv;
			info.bstrArg = launchParameters.StartupArguments;
			info.bstrRemoteMachine = launchParameters.RemoteDebugMachine;
			info.clsidCustom = launchParameters.DebugType;
			return info;
		}
Example #25
0
 private static VsDebugTargetInfo CreateClojureLaunchInfo(LaunchParameters launchParameters, uint grfLaunch)
 {
     var info = new VsDebugTargetInfo();
     info.cbSize = (uint) Marshal.SizeOf(info);
     info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
     info.bstrExe = launchParameters.RunnerPath;
     info.bstrCurDir = launchParameters.ApplicationPath;
     info.fSendStdoutToOutputWindow = 0;
     info.grfLaunch = grfLaunch;
     info.bstrArg = "-i " + launchParameters.StartupFile;
     info.bstrRemoteMachine = launchParameters.RemoteDebugMachine;
     info.clsidCustom = launchParameters.DebugType;
     return info;
 }
 private void LaunchDebugger(IServiceProvider provider, VsDebugTargetInfo dbgInfo)
 {
     if (!Directory.Exists(UnquotePath(dbgInfo.bstrCurDir)))
     {
         MessageBox.Show(String.Format("Working directory \"{0}\" does not exist.", dbgInfo.bstrCurDir), "Node.js Tools for Visual Studio");
     }
     else if (!File.Exists(UnquotePath(dbgInfo.bstrExe)))
     {
         MessageBox.Show(String.Format("Interpreter \"{0}\" does not exist.", dbgInfo.bstrExe), "Node.js Tools for Visual Studio");
     }
     else if (DoesProjectSupportDebugging())
     {
         VsShellUtilities.LaunchDebugger(provider, dbgInfo);
     }
 }
        public void SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext) {
            string target = vsDebugTargetInfo.bstrExe;
            vsDebugTargetInfo.bstrExe = debugLaunchContext.LaunchConfiguration.GetValue<string>(NodeExeKey, Nodejs.GetPathToNodeExecutableFromEnvironment());
            string nodeJsArgs = vsDebugTargetInfo.bstrArg;
            vsDebugTargetInfo.bstrArg = "\"" + target + "\"";
            if (!string.IsNullOrEmpty(nodeJsArgs))
            {
                vsDebugTargetInfo.bstrArg += " ";
                vsDebugTargetInfo.bstrArg += nodeJsArgs;
            }

            vsDebugTargetInfo.clsidCustom = DebugEngine.AD7Engine.DebugEngineGuid;
            vsDebugTargetInfo.bstrOptions = "WAIT_ON_ABNORMAL_EXIT=true";
            vsDebugTargetInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Example #28
0
 private static VsDebugTargetInfo CreateExecutableLaunchInfo(LaunchParameters launchParameters, uint grfLaunch)
 {
     var info = new VsDebugTargetInfo();
     info.cbSize = (uint) Marshal.SizeOf(info);
     info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
     info.bstrExe = launchParameters.ApplicationPath + "\\" + launchParameters.StartupFile;
     info.bstrCurDir = launchParameters.ApplicationPath;
     info.fSendStdoutToOutputWindow = 0;
     info.grfLaunch = grfLaunch;
     info.bstrArg = launchParameters.StartupArguments;
     info.bstrRemoteMachine = launchParameters.RemoteDebugMachine;
     info.bstrEnv = "clojure.load.path=" + launchParameters.FrameworkPath + ";" + launchParameters.ClojureLoadPath + "\0";
     info.clsidCustom = launchParameters.DebugType;
     return info;
 }
Example #29
0
 private static void LaunchDebugger(IServiceProvider provider, VsDebugTargetInfo dbgInfo)
 {
     if (!Directory.Exists(UnquotePath(dbgInfo.bstrCurDir)))
     {
         MessageBox.Show(String.Format("Working directory \"{0}\" does not exist.", dbgInfo.bstrCurDir));
     }
     else if (!File.Exists(UnquotePath(dbgInfo.bstrExe)))
     {
         MessageBox.Show(String.Format("Interpreter \"{0}\" does not exist.", dbgInfo.bstrExe));
     }
     else
     {
         VsShellUtilities.LaunchDebugger(provider, dbgInfo);
     }
 }
Example #30
0
        private static VsDebugTargetInfo CreateClojureLaunchInfo(LaunchParameters launchParameters, uint grfLaunch)
        {
            var info = new VsDebugTargetInfo();

            info.cbSize     = (uint)Marshal.SizeOf(info);
            info.dlo        = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            info.bstrExe    = launchParameters.RunnerPath;
            info.bstrCurDir = launchParameters.ApplicationPath;
            info.fSendStdoutToOutputWindow = 0;
            info.grfLaunch         = grfLaunch;
            info.bstrArg           = "-i " + launchParameters.StartupFile;
            info.bstrRemoteMachine = launchParameters.RemoteDebugMachine;
            info.clsidCustom       = launchParameters.DebugType;
            return(info);
        }
Example #31
0
 private void LaunchDebugger(IServiceProvider provider, VsDebugTargetInfo dbgInfo)
 {
     if (!Directory.Exists(dbgInfo.bstrCurDir))
     {
         MessageBox.Show(string.Format(CultureInfo.CurrentCulture, Resources.DebugWorkingDirectoryDoesNotExistErrorMessage, dbgInfo.bstrCurDir), SR.ProductName);
     }
     else if (!File.Exists(dbgInfo.bstrExe))
     {
         MessageBox.Show(string.Format(CultureInfo.CurrentCulture, Resources.DebugInterpreterDoesNotExistErrorMessage, dbgInfo.bstrExe), SR.ProductName);
     }
     else if (DoesProjectSupportDebugging())
     {
         VsShellUtilities.LaunchDebugger(provider, dbgInfo);
     }
 }
Example #32
0
        private static VsDebugTargetInfo CreateExecutableLaunchInfo(LaunchParameters launchParameters)
        {
            var info = new VsDebugTargetInfo();

            info.cbSize     = (uint)Marshal.SizeOf(info);
            info.dlo        = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            info.bstrExe    = Path.Combine(launchParameters.ApplicationPath, launchParameters.StartupFile);
            info.bstrCurDir = launchParameters.ApplicationPath;
            info.fSendStdoutToOutputWindow = 0;
            info.grfLaunch         = (uint)__VSDBGLAUNCHFLAGS2.DBGLAUNCH_MergeEnv;
            info.bstrArg           = launchParameters.StartupArguments;
            info.bstrRemoteMachine = launchParameters.RemoteDebugMachine;
            info.clsidCustom       = launchParameters.DebugType;
            return(info);
        }
        /// <summary>
        /// Sets up debugger information.
        /// </summary>
        private bool SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile)
        {
            dbgInfo.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            dbgInfo.bstrExe           = GetNodePath();
            dbgInfo.bstrCurDir        = _project.GetWorkingDirectory();
            dbgInfo.bstrArg           = GetFullArguments(startupFile, includeNodeArgs: false); // we need to supply node args via options
            dbgInfo.bstrRemoteMachine = null;
            var nodeArgs = _project.GetProjectProperty(NodeProjectProperty.NodeExeArguments);

            if (!String.IsNullOrWhiteSpace(nodeArgs))
            {
                AppendOption(ref dbgInfo, AD7Engine.InterpreterOptions, nodeArgs);
            }

            var url = GetFullUrl();

            if (ShouldStartBrowser() && !String.IsNullOrWhiteSpace(url))
            {
                AppendOption(ref dbgInfo, AD7Engine.WebBrowserUrl, url);
            }

            var debuggerPort = _project.GetProjectProperty(NodeProjectProperty.DebuggerPort);

            if (!String.IsNullOrWhiteSpace(debuggerPort))
            {
                AppendOption(ref dbgInfo, AD7Engine.DebuggerPort, debuggerPort);
            }

            if (NodejsPackage.Instance.GeneralOptionsPage.WaitOnAbnormalExit)
            {
                AppendOption(ref dbgInfo, AD7Engine.WaitOnAbnormalExitSetting, "true");
            }

            if (NodejsPackage.Instance.GeneralOptionsPage.WaitOnNormalExit)
            {
                AppendOption(ref dbgInfo, AD7Engine.WaitOnNormalExitSetting, "true");
            }

            dbgInfo.fSendStdoutToOutputWindow = 0;
            dbgInfo.bstrEnv = GetEnvironmentVariablesString(url);


            // Set the Node  debugger
            dbgInfo.clsidCustom = AD7Engine.DebugEngineGuid;
            dbgInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
            return(true);
        }
Example #34
0
        /// <summary>
        /// Sets up debugger information.
        /// </summary>
        private void SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile)
        {
            dbgInfo.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            bool isWindows;

            dbgInfo.bstrExe           = GetInterpreterExecutableInternal(out isWindows);
            dbgInfo.bstrCurDir        = _project.GetWorkingDirectory();
            dbgInfo.bstrArg           = CreateCommandLineDebug(startupFile);
            dbgInfo.bstrRemoteMachine = null;

            dbgInfo.fSendStdoutToOutputWindow = 0;
            StringDictionary env = new StringDictionary();

            dbgInfo.bstrOptions = AD7Engine.VersionSetting + "=" + _project.GetInterpreterFactory().GetLanguageVersion().ToString();
            if (!isWindows && PythonToolsPackage.Instance.OptionsPage.WaitOnExit)
            {
                dbgInfo.bstrOptions += ";" + AD7Engine.WaitOnAbnormalExitSetting + "=True";
            }

            SetupEnvironment(env);
            if (env.Count > 0)
            {
                // add any inherited env vars
                var variables = Environment.GetEnvironmentVariables();
                foreach (var key in variables.Keys)
                {
                    string strKey = (string)key;
                    if (!env.ContainsKey(strKey))
                    {
                        env.Add(strKey, (string)variables[key]);
                    }
                }

                //Environemnt variables should be passed as a
                //null-terminated block of null-terminated strings.
                //Each string is in the following form:name=value\0
                StringBuilder buf = new StringBuilder();
                foreach (DictionaryEntry entry in env)
                {
                    buf.AppendFormat("{0}={1}\0", entry.Key, entry.Value);
                }
                buf.Append("\0");
                dbgInfo.bstrEnv = buf.ToString();
            }
            // Set the Python debugger
            dbgInfo.clsidCustom = new Guid(AD7Engine.DebugEngineId);
            dbgInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Example #35
0
        private static VsDebugTargetInfo CreateExecutableLaunchInfo(LaunchParameters launchParameters, uint grfLaunch)
        {
            var info = new VsDebugTargetInfo();

            info.cbSize     = (uint)Marshal.SizeOf(info);
            info.dlo        = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            info.bstrExe    = launchParameters.ApplicationPath + "\\" + launchParameters.StartupFile;
            info.bstrCurDir = launchParameters.ApplicationPath;
            info.fSendStdoutToOutputWindow = 0;
            info.grfLaunch         = grfLaunch;
            info.bstrArg           = launchParameters.StartupArguments;
            info.bstrRemoteMachine = launchParameters.RemoteDebugMachine;
            info.bstrEnv           = "clojure.load.path=" + launchParameters.FrameworkPath + ";" + launchParameters.ClojureLoadPath + "\0";
            info.clsidCustom       = launchParameters.DebugType;
            return(info);
        }
        void IVsDebugLaunchTargetProvider.SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            var nodeExe = CheckNodeInstalledAndWarn(debugLaunchContext);

            var nodeVersion = Nodejs.GetNodeVersion(nodeExe);

            if (nodeVersion >= new Version(8, 0))
            {
                this.SetupDebugTargetInfoForInspectProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);
            }
            else
            {
                this.SetupDebugTargetInfoForNodeProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString(), isProject: false);
            }
        }
Example #37
0
        public override bool Execute()
        {
            System.Diagnostics.Debugger.Launch();
            //CoInitializeEx(NULL, COINIT_MULTITHREADED);
            //enum comEnum = {COINIT_MULTITHREADED=0};
            //CoInitializeEx((IntPtr)null, (uint)0);

            _applicationObject = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0");

            Microsoft.VisualStudio.Shell.ServiceProvider sp =
                new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_applicationObject);

            IVsDebugger dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));

            VsDebugTargetInfo info = new VsDebugTargetInfo();
            info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
            info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            info.bstrExe = _filePath;
            info.bstrCurDir = System.IO.Path.GetDirectoryName(info.bstrExe);
            info.bstrArg = null; // no command line parameters
            info.bstrRemoteMachine = null; // debug locally
            info.fSendStdoutToOutputWindow = 0; // Let stdout stay with the application.
            info.clsidCustom = new Guid("{D951924A-4999-42a0-9217-1EB5233D1D5A}"); // Set the launching engine the sample engine guid
            info.grfLaunch = 0;

            IntPtr pInfo = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)info.cbSize);
            System.Runtime.InteropServices.Marshal.StructureToPtr(info, pInfo, false);

            try
            {
                dbg.LaunchDebugTargets(1, pInfo);
            }
            finally
            {
                if (pInfo != IntPtr.Zero)
                {
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pInfo);
                }
            }

            return true;
        }
Example #38
0
        /// <summary>
        /// Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile) {
            VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();
            dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);
            IntPtr ptr = Marshal.AllocCoTaskMem((int)dbgInfo.cbSize);
            try {
                Marshal.StructureToPtr(dbgInfo, ptr, false);
                SetupDebugInfo(ref dbgInfo, startupFile);

                if (string.IsNullOrEmpty(dbgInfo.bstrExe)) {
                    MessageBox.Show(
                        "The project cannot be debugged because its active Python environment does not have the interpreter executable specified.",
                        "Python Tools for Visual Studio", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                LaunchDebugger(_serviceProvider, dbgInfo);
            } finally {
                if (ptr != IntPtr.Zero) {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
        }
        /// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.LaunchDebugger"]/*' />
        /// <devdoc>
        /// Launch the debugger.
        /// </devdoc>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="info">A reference to a VsDebugTargetInfo object.</param>
        public static void LaunchDebugger(IServiceProvider serviceProvider, VsDebugTargetInfo info)
        {
            Debug.Assert(serviceProvider != null, "Cannot launch the debugger on an empty service provider");
            if (serviceProvider == null)
            {
                throw new ArgumentException("serviceProvider");
            }

            info.cbSize = (uint)Marshal.SizeOf(info);
            IntPtr ptr = Marshal.AllocCoTaskMem((int)info.cbSize);
            Marshal.StructureToPtr(info, ptr, false);
            try
            {
                IVsDebugger d = serviceProvider.GetService(typeof(IVsDebugger)) as IVsDebugger;
                Debug.Assert(d != null, "Could not retrieve IVsDebugger from " + serviceProvider.GetType().Name);

                if (d == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(d.LaunchDebugTargets(1, ptr));
            }
            catch (COMException e)
            {
                Trace.WriteLine("Exception : " + e.Message);
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
        }
        private void AppendOption(ref VsDebugTargetInfo dbgInfo, string option, string value) {
            if (!String.IsNullOrWhiteSpace(dbgInfo.bstrOptions)) {
                dbgInfo.bstrOptions += ";";
            }

            dbgInfo.bstrOptions += option + "=" + HttpUtility.UrlEncode(value);
        }
        /// <summary>
        /// Sets up debugger information.
        /// </summary>
        private bool SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile) {
            dbgInfo.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            dbgInfo.bstrExe = GetNodePath();
            dbgInfo.bstrCurDir = _project.GetWorkingDirectory();
            dbgInfo.bstrArg = GetFullArguments(startupFile, includeNodeArgs: false);    // we need to supply node args via options
            dbgInfo.bstrRemoteMachine = null;
            var nodeArgs = _project.GetProjectProperty(NodeProjectProperty.NodeExeArguments);
            if (!String.IsNullOrWhiteSpace(nodeArgs)) {
                AppendOption(ref dbgInfo, AD7Engine.InterpreterOptions, nodeArgs);
            }

            var url = GetFullUrl();
            if (ShouldStartBrowser() && !String.IsNullOrWhiteSpace(url)) {
                AppendOption(ref dbgInfo, AD7Engine.WebBrowserUrl, url);
            }

            var debuggerPort = _project.GetProjectProperty(NodeProjectProperty.DebuggerPort);
            if (!String.IsNullOrWhiteSpace(debuggerPort)) {
                AppendOption(ref dbgInfo, AD7Engine.DebuggerPort, debuggerPort);
            }

            if (NodejsPackage.Instance.GeneralOptionsPage.WaitOnAbnormalExit) {
                AppendOption(ref dbgInfo, AD7Engine.WaitOnAbnormalExitSetting, "true");
            }

            if (NodejsPackage.Instance.GeneralOptionsPage.WaitOnNormalExit) {
                AppendOption(ref dbgInfo, AD7Engine.WaitOnNormalExitSetting, "true");
            }

            dbgInfo.fSendStdoutToOutputWindow = 0;

            StringDictionary env = new StringDictionary();
            if (!String.IsNullOrWhiteSpace(url)) {
                Uri webUrl = new Uri(url);
                env["PORT"] = webUrl.Port.ToString();
            }

            foreach (var nameValue in GetEnvironmentVariables()) {
                env[nameValue.Key] = nameValue.Value;
            }

            if (env.Count > 0) {
                // add any inherited env vars
                var variables = Environment.GetEnvironmentVariables();
                foreach (var key in variables.Keys) {
                    string strKey = (string)key;
                    if (!env.ContainsKey(strKey)) {
                        env.Add(strKey, (string)variables[key]);
                    }
                }

                //Environemnt variables should be passed as a
                //null-terminated block of null-terminated strings. 
                //Each string is in the following form:name=value\0
                StringBuilder buf = new StringBuilder();
                foreach (DictionaryEntry entry in env) {
                    buf.AppendFormat("{0}={1}\0", entry.Key, entry.Value);
                }
                buf.Append("\0");
                dbgInfo.bstrEnv = buf.ToString();
            }

            // Set the Node  debugger
            dbgInfo.clsidCustom = AD7Engine.DebugEngineGuid;
            dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
            return true;
        }
        private IntPtr GetDebugInfo(string args, string targetExe, string outputDirectory)
        {
            var info = new VsDebugTargetInfo();
            info.cbSize = (uint) Marshal.SizeOf(info);
            info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            info.bstrExe = Path.Combine(outputDirectory, targetExe);
            info.bstrCurDir = outputDirectory;
            info.bstrArg = args; // no command line parameters
            info.bstrRemoteMachine = null; // debug locally
            info.grfLaunch = (uint) __VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
            info.fSendStdoutToOutputWindow = 0;
            info.clsidCustom = AD7Guids.EngineGuid;
            info.grfLaunch = 0;

            IntPtr pInfo = Marshal.AllocCoTaskMem((int) info.cbSize);
            Marshal.StructureToPtr(info, pInfo, false);
            return pInfo;
        }
Example #43
0
 public DebugTargetInfo(IServiceProvider provider)
 {
     _provider = provider;
     Info = new VsDebugTargetInfo();
     Info.cbSize = (uint)Marshal.SizeOf(Info);
 }
        /// <summary> 
        /// Launch an executable using the VSNDK debug engine. 
        /// </summary>
        /// <param name="pidString"> Process ID in string format. </param>
        /// <returns> TRUE if successful, False if not. </returns>
        private bool LaunchDebugTarget(string pidString, string toolsPath, string publicKeyPath, string targetIP, string password, string executablePath)
        {
            Microsoft.VisualStudio.Shell.ServiceProvider sp =
                 new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_dte);

            IVsDebugger dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));

            VsDebugTargetInfo info = new VsDebugTargetInfo();

            info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
            info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            // Store all debugger arguments in a string
            var nvc = new NameValueCollection();
            nvc.Add("pid", pidString);
            nvc.Add("targetIP", targetIP); // The device (IP address)
            info.bstrExe = executablePath; // The executable path
            nvc.Add("isSimulator", _isSimulator.ToString());
            nvc.Add("ToolsPath", toolsPath);
            nvc.Add("PublicKeyPath", publicKeyPath);
            nvc.Add("Password", password);

            info.bstrArg = NameValueCollectionHelper.DumpToString(nvc);

            info.bstrRemoteMachine = null; // debug locally
            info.fSendStdoutToOutputWindow = 0; // Let stdout stay with the application.
            info.clsidCustom = new Guid("{E5A37609-2F43-4830-AA85-D94CFA035DD2}"); // Set the launching engine the VSNDK engine guid
            info.grfLaunch = 0;

            IntPtr pInfo = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)info.cbSize);
            System.Runtime.InteropServices.Marshal.StructureToPtr(info, pInfo, false);

            try
            {
                int result = dbg.LaunchDebugTargets(1, pInfo);

                if (result != VSConstants.S_OK)
                {
                    string msg;
                    IVsUIShell sh = (IVsUIShell)sp.GetService(typeof(SVsUIShell));
                    sh.GetErrorInfo(out msg);
                    Debug.WriteLine("LaunchDebugTargets: " + msg);

                    return true;
                }
            }
            finally
            {
                if (pInfo != IntPtr.Zero)
                {
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pInfo);
                }
            }

            return false;
        }
Example #45
0
        /// <summary>
        /// Default implementation of the "Start Debugging" command.
        /// </summary>
        protected virtual void StartWithDebugger(CommonProjectNode project, string startupFile)
        {
            VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();
            dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);
            IntPtr ptr = Marshal.AllocCoTaskMem((int)dbgInfo.cbSize);
            try {
                Marshal.StructureToPtr(dbgInfo, ptr, false);
                SetupDebugInfo(ref dbgInfo, project, startupFile);

                LaunchDebugger(_serviceProvider, dbgInfo);
            } finally {
                if (ptr != IntPtr.Zero) {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }
        }
Example #46
0
        //TODO: this method should be protected, but due to IPy bug #19649
        //we keep it temporary public.
        /// <summary>
        /// Sets up debugger information.
        /// </summary>
        public virtual void SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, 
            CommonProjectNode project, string startupFile)
        {
            dbgInfo.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            dbgInfo.bstrExe = GetInterpreterExecutableInternal(project);
            dbgInfo.bstrCurDir = project != null ?
                project.GetWorkingDirectory() :
                Path.GetDirectoryName(startupFile);
            dbgInfo.bstrArg = CreateCommandLineDebug(project, startupFile);
            dbgInfo.bstrRemoteMachine = null;
            dbgInfo.fSendStdoutToOutputWindow = 0;
            StringDictionary env = new StringDictionary();

            SetupEnvironment(project, env);
            if (env.Count > 0) {
                // add any inherited env vars
                var variables = Environment.GetEnvironmentVariables();
                foreach (var key in variables.Keys) {
                    string strKey = (string)key;
                    if (!env.ContainsKey(strKey)) {
                        env.Add(strKey, (string)variables[key]);
                    }
                }

                //Environemnt variables should be passed as a
                //null-terminated block of null-terminated strings.
                //Each string is in the following form:name=value\0
                StringBuilder buf = new StringBuilder();
                foreach (DictionaryEntry entry in env) {
                    buf.AppendFormat("{0}={1}\0", entry.Key, entry.Value);
                }
                buf.Append("\0");
                dbgInfo.bstrEnv = buf.ToString();
            }
            //Set the managed debugger
            dbgInfo.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine;
            dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
    protected void LaunchDebugTarget()
    {
      Microsoft.VisualStudio.Shell.ServiceProvider sp =
           new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)Dte);

      IVsDebugger dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));

      VsDebugTargetInfo info = new VsDebugTargetInfo();     
      

      info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
      info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
      info.bstrExe = Moniker;
      info.bstrCurDir = @"C:\";
      string connectionString = HierarchyAccessor.Connection.ConnectionSupport.ConnectionString + ";Allow User Variables=true;Allow Zero DateTime=true;";
      if (connectionString.IndexOf("password", StringComparison.OrdinalIgnoreCase) == -1)
      {
        MySql.Data.MySqlClient.MySqlConnection connection = ((MySql.Data.MySqlClient.MySqlConnection)HierarchyAccessor.Connection.GetLockedProviderObject());
        try
        {
          MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings = (MySql.Data.MySqlClient.MySqlConnectionStringBuilder)connection.GetType().GetProperty("Settings", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(connection, null);
          connectionString += "password="******";Persist Security Info=true;";
        }
        finally
        {
          HierarchyAccessor.Connection.UnlockProviderObject();
        }
      }
      info.bstrArg = connectionString;
      info.bstrRemoteMachine = null; // Environment.MachineName; // debug locally
      info.fSendStdoutToOutputWindow = 0; // Let stdout stay with the application.
      info.clsidCustom = new Guid("{EEEE0740-10F7-4e5f-8BC4-1CC0AC9ED5B0}"); // Set the launching engine the sample engine guid
      info.grfLaunch = 0;

      IntPtr pInfo = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)info.cbSize);
      System.Runtime.InteropServices.Marshal.StructureToPtr(info, pInfo, false);

      try
      {
        int result = dbg.LaunchDebugTargets(1, pInfo);
        if (result != 0 && result != VSConstants.E_ABORT)
          throw new ApplicationException("COM error " + result);
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.GetBaseException().Message, "Debugger Error");
      }
      finally
      {
        if (pInfo != IntPtr.Zero)
        {
          System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pInfo);
        }
      }
    }
Example #48
0
        /// <summary>
        /// Launch an executable using the sample debug engine.
        /// </summary>
        public void LaunchDebugTarget(string command, string arguments, string workingDir)
        {
            Microsoft.VisualStudio.Shell.ServiceProvider sp =
                new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_applicationObject);

            IVsDebugger dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger));

            VsDebugTargetInfo info = new VsDebugTargetInfo();
            info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
            info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            info.bstrExe = command;
            info.bstrCurDir = String.IsNullOrEmpty(workingDir) ? System.IO.Path.GetDirectoryName(info.bstrExe) : workingDir;
            info.bstrArg = arguments; // command line parameters
            info.bstrRemoteMachine = null; // debug locally
            info.fSendStdoutToOutputWindow = 0; // Let stdout stay with the application.
            info.clsidCustom = new Guid("{D951924A-4999-42a0-9217-1EB5233D1D5A}"); // Set the launching engine the sample engine guid
            info.grfLaunch = 0;

            IntPtr pInfo = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)info.cbSize);
            System.Runtime.InteropServices.Marshal.StructureToPtr(info, pInfo, false);

            try
            {
                dbg.LaunchDebugTargets(1, pInfo);
            }
            finally
            {
                if (pInfo != IntPtr.Zero)
                {
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pInfo);
                }
            }
        }
Example #49
0
        /// <summary>
        /// Called by the vs shell to start debugging (managed or unmanaged).
        /// Override this method to support other debug engines.
        /// </summary>
        /// <param name="grfLaunch">A flag that determines the conditions under which to start the debugger. For valid grfLaunch values, see __VSDBGLAUNCHFLAGS</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code</returns>
        public virtual int DebugLaunch(uint grfLaunch)
        {
            CCITracing.TraceCall();

            try
            {
                VsDebugTargetInfo info = new VsDebugTargetInfo();
                info.cbSize = (uint)Marshal.SizeOf(info);
                info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

                // On first call, reset the cache, following calls will use the cached values
                string property = GetConfigurationProperty("StartProgram", true);
                if (string.IsNullOrEmpty(property))
                {
                    info.bstrExe = this.project.GetOutputAssembly(this.ConfigName);
                }
                else
                {
                    info.bstrExe = property;
                }

                property = GetConfigurationProperty("WorkingDirectory", false);
                if (string.IsNullOrEmpty(property))
                {
                    info.bstrCurDir = Path.GetDirectoryName(info.bstrExe);
                }
                else
                {
                    info.bstrCurDir = property;
                }

                property = GetConfigurationProperty("CmdArgs", false);
                if (!string.IsNullOrEmpty(property))
                {
                    info.bstrArg = property;
                }

                property = GetConfigurationProperty("RemoteDebugMachine", false);
                if (property != null && property.Length > 0)
                {
                    info.bstrRemoteMachine = property;
                }

                info.fSendStdoutToOutputWindow = 0;

                property = GetConfigurationProperty("EnableUnmanagedDebugging", false);
                if (property != null && string.Compare(property, "true", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    //Set the unmanged debugger
                    //TODO change to vsconstant when it is available in VsConstants (guidNativeOnlyEng was the old name, maybe it has got a new name)
                    info.clsidCustom = new Guid("{3B476D35-A401-11D2-AAD4-00C04F990171}");
                }
                else
                {
                    //Set the managed debugger
                    info.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine;
                }
                info.grfLaunch = grfLaunch;
                VsShellUtilities.LaunchDebugger(this.project.Site, info);
            }
            catch (Exception e)
            {
                Trace.WriteLine("Exception : " + e.Message);

                return Marshal.GetHRForException(e);
            }

            return VSConstants.S_OK;
        }
Example #50
0
        /// <summary>
        ///     Launches a debugger with provided parameters.
        /// </summary>
        /// <param name="provider">Service provider.</param>
        /// <param name="dbgInfo">Debugger information.</param>
        private static void LaunchDebugger(IServiceProvider provider, VsDebugTargetInfo dbgInfo)
        {
            if (!Directory.Exists(UnquotePath(dbgInfo.bstrCurDir)))
            {
                string message = string.Format("Working directory \"{0}\" does not exist.", dbgInfo.bstrCurDir);
                MessageBox.Show(message, Resources.NodeToolsTitle);
                return;
            }

            if (!File.Exists(UnquotePath(dbgInfo.bstrExe)))
            {
                string message = String.Format("Unable to find \"{0}\" executable location.\nPlease setup node.js directory in the project settings.", dbgInfo.bstrExe);
                MessageBox.Show(message, Resources.NodeToolsTitle);
                return;
            }

            VsShellUtilities.LaunchDebugger(provider, dbgInfo);
        }
Example #51
0
        public void StartInBrowser(string url, Guid? debugEngine)
        {
            if (debugEngine.HasValue) {
                // launch via VS debugger, it'll take care of figuring out the browsers
                VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();
                dbgInfo.dlo = (DEBUG_LAUNCH_OPERATION)_DEBUG_LAUNCH_OPERATION3.DLO_LaunchBrowser;
                dbgInfo.bstrExe = url;
                dbgInfo.clsidCustom = debugEngine.Value;
                dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd | (uint)__VSDBGLAUNCHFLAGS4.DBGLAUNCH_UseDefaultBrowser;
                dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);
                VsShellUtilities.LaunchDebugger(_serviceProvider, dbgInfo);
            } else {
                // run the users default browser
                var handler = GetBrowserHandlerProgId();
                var browserCmd = (string)Registry.ClassesRoot.OpenSubKey(handler).OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command").GetValue("");

                if (browserCmd.IndexOf("%1") != -1) {
                    browserCmd = browserCmd.Replace("%1", url);
                } else {
                    browserCmd = browserCmd + " " + url;
                }
                bool inQuote = false;
                string cmdLine = null;
                for (int i = 0; i < browserCmd.Length; i++) {
                    if (browserCmd[i] == '"') {
                        inQuote = !inQuote;
                    }

                    if (browserCmd[i] == ' ' && !inQuote) {
                        cmdLine = browserCmd.Substring(0, i);
                        break;
                    }
                }
                if (cmdLine == null) {
                    cmdLine = browserCmd;
                }

                Process.Start(cmdLine, browserCmd.Substring(cmdLine.Length));
            }
        }
Example #52
0
        /// <summary>
        ///     Sets up debugger information.
        /// </summary>
        private void SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile)
        {
            dbgInfo.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            dbgInfo.bstrExe = _pathResolver.FindFilePath(Executable);
            dbgInfo.bstrCurDir = _project.ProjectFolder;
            dbgInfo.bstrArg = CreateArgumentsDebug(startupFile);
            dbgInfo.bstrRemoteMachine = null;
            dbgInfo.fSendStdoutToOutputWindow = 0;

            // Set the Node debugger
            dbgInfo.clsidCustom = Guids.DebugEngine;
            dbgInfo.grfLaunch = (uint) __VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Example #53
0
        private VsDebugTargetInfo GetDebugTargetInfo(uint grfLaunch, bool forLaunch)
        {
            VsDebugTargetInfo info = new VsDebugTargetInfo();
            info.cbSize = (uint)Marshal.SizeOf(info);
            info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

            // On first call, reset the cache, following calls will use the cached values
            string property = GetConfigurationProperty("StartAction", true);

            // Set the debug target
            if (0 == System.String.Compare("Program", property, StringComparison.OrdinalIgnoreCase))
            {
                string startProgram = StartProgram;
                if (!string.IsNullOrEmpty(startProgram))
                    info.bstrExe = startProgram;
            }
            else
            // property is either null or "Project"
            // we're ignoring "URL" for now
            {
                string outputType = project.GetProjectProperty(ProjectFileConstants.OutputType, false);
                if (forLaunch && 0 == string.Compare("library", outputType, StringComparison.OrdinalIgnoreCase))
                    throw new ClassLibraryCannotBeStartedDirectlyException();
                info.bstrExe = this.project.GetOutputAssembly(this.configCanonicalName);
            }

            property = GetConfigurationProperty("RemoteDebugMachine", false);
            if (property != null && property.Length > 0)
            {
                info.bstrRemoteMachine = property;
            }
            bool isRemoteDebug = (info.bstrRemoteMachine != null);

            property = GetConfigurationProperty("StartWorkingDirectory", false);
            if (string.IsNullOrEmpty(property))
            {
                // 3273: aligning with C#
                info.bstrCurDir = Path.GetDirectoryName(this.project.GetOutputAssembly(this.configCanonicalName));
            }
            else 
            {
                if (isRemoteDebug)
                {
                    info.bstrCurDir = property;
                }
                else
                {
                    string fullPath;
                    if (Path.IsPathRooted(property))
                    {
                        fullPath = property;
                    }
                    else
                    {
                        // use project folder as a base part when computing full path from given relative
                        var currentDir = Path.GetDirectoryName(this.project.GetOutputAssembly(this.configCanonicalName));
                        fullPath = Path.Combine(currentDir, property);
                    }

                    if (!Directory.Exists(fullPath))
                        throw new WorkingDirectoryNotExistsException(fullPath);
                    
                    info.bstrCurDir = fullPath;
                }
            }

            property = GetConfigurationProperty("StartArguments", false);
            if (!string.IsNullOrEmpty(property))
            {
                info.bstrArg = property;
            }

            info.fSendStdoutToOutputWindow = 0;

            property = GetConfigurationProperty("EnableUnmanagedDebugging", false);
            if (property != null && string.Compare(property, "true", StringComparison.OrdinalIgnoreCase) == 0)
            {
                //Set the unmanged debugger
                //TODO change to vsconstant when it is available in VsConstants. It should be guidCOMPlusNativeEng
                info.clsidCustom = new Guid("{92EF0900-2251-11D2-B72E-0000F87572EF}");
            }
            else
            {
                //Set the managed debugger
                info.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine;
            }
            info.grfLaunch = grfLaunch;
            bool isConsoleApp = string.Compare("exe",
                project.GetProjectProperty(ProjectFileConstants.OutputType, false),
                StringComparison.OrdinalIgnoreCase) == 0;

            bool noDebug = ((uint)(((__VSDBGLAUNCHFLAGS)info.grfLaunch) & __VSDBGLAUNCHFLAGS.DBGLAUNCH_NoDebug)) != 0;
            // Do not use cmd.exe to get "Press any key to continue." when remote debugging
            if (isConsoleApp && noDebug && !isRemoteDebug)
            {
                // VSWhidbey 573404: escape the characters ^<>& so that they are passed to the application rather than interpreted by cmd.exe.
                System.Text.StringBuilder newArg = new System.Text.StringBuilder(info.bstrArg);
                newArg.Replace("^", "^^")
                      .Replace("<", "^<")
                      .Replace(">", "^>")
                      .Replace("&", "^&");
                newArg.Insert(0, "\" ");
                newArg.Insert(0, info.bstrExe);
                newArg.Insert(0, "/c \"\"");
                newArg.Append(" & pause\"");
                string newExe = Path.Combine(Environment.SystemDirectory, "cmd.exe");

                info.bstrArg = newArg.ToString();
                info.bstrExe = newExe;
            }
            return info;
        }
Example #54
0
        /// <summary>
        ///     Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile)
        {
            var dbgInfo = new VsDebugTargetInfo();
            dbgInfo.cbSize = (uint) Marshal.SizeOf(dbgInfo);

            SetupDebugInfo(ref dbgInfo, startupFile);
            LaunchDebugger(_project.Package, dbgInfo);
        }
        /// <summary>
        /// Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile) {
            VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();
            dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);

            if (SetupDebugInfo(ref dbgInfo, startupFile)) {
                LaunchDebugger(_project.Site, dbgInfo);
            }
        }
 private void LaunchDebugger(IServiceProvider provider, VsDebugTargetInfo dbgInfo) {
     if (!Directory.Exists(dbgInfo.bstrCurDir)) {
         MessageBox.Show(string.Format(CultureInfo.CurrentCulture, Resources.DebugWorkingDirectoryDoesNotExistErrorMessage, dbgInfo.bstrCurDir), SR.ProductName);
     } else if (!File.Exists(dbgInfo.bstrExe)) {
         MessageBox.Show(string.Format(CultureInfo.CurrentCulture, Resources.DebugInterpreterDoesNotExistErrorMessage, dbgInfo.bstrExe), SR.ProductName);
     } else if (DoesProjectSupportDebugging()) {
         VsShellUtilities.LaunchDebugger(provider, dbgInfo);
     }
 }
Example #57
0
 private static void LaunchDebugger(IServiceProvider provider, VsDebugTargetInfo dbgInfo)
 {
     if (!Directory.Exists(UnquotePath(dbgInfo.bstrCurDir))) {
         MessageBox.Show(String.Format("Working directory \"{0}\" does not exist.", dbgInfo.bstrCurDir), "J Tools for Visual Studio");
     } else if (!File.Exists(UnquotePath(dbgInfo.bstrExe))) {
         MessageBox.Show(String.Format("Interpreter \"{0}\" does not exist.", dbgInfo.bstrExe), "J Tools for Visual Studio");
     } else {
         VsShellUtilities.LaunchDebugger(provider, dbgInfo);
     }
 }
Example #58
0
        /// <summary>
        /// Sets up debugger information.
        /// </summary>
        private void SetupDebugInfo(ref VsDebugTargetInfo dbgInfo, string startupFile)
        {
            dbgInfo.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            bool isWindows;
            dbgInfo.bstrExe = GetInterpreterExecutableInternal(out isWindows);
            dbgInfo.bstrCurDir = _project.GetWorkingDirectory();
            dbgInfo.bstrArg = CreateCommandLineDebug(startupFile);
            dbgInfo.bstrRemoteMachine = null;

            dbgInfo.fSendStdoutToOutputWindow = 0;
            StringDictionary env = new StringDictionary();
            string interpArgs = _project.GetProperty(CommonConstants.InterpreterArguments);
            dbgInfo.bstrOptions = AD7Engine.VersionSetting + "=" + _project.GetInterpreterFactory().GetLanguageVersion().ToString();
            if (!isWindows) {
                if (JToolsPackage.Instance.OptionsPage.WaitOnAbnormalExit) {
                    dbgInfo.bstrOptions += ";" + AD7Engine.WaitOnAbnormalExitSetting + "=True";
                }
                if (JToolsPackage.Instance.OptionsPage.WaitOnNormalExit) {
                    dbgInfo.bstrOptions += ";" + AD7Engine.WaitOnNormalExitSetting + "=True";
                }
            }
            if (JToolsPackage.Instance.OptionsPage.TeeStandardOutput) {
                dbgInfo.bstrOptions += ";" + AD7Engine.RedirectOutputSetting + "=True";
            }
            if (JToolsPackage.Instance.OptionsPage.BreakOnSystemExitZero) {
                dbgInfo.bstrOptions += ";" + AD7Engine.BreakSystemExitZero + "=True";
            }
            if (JToolsPackage.Instance.OptionsPage.DebugStdLib) {
                dbgInfo.bstrOptions += ";" + AD7Engine.DebugStdLib + "=True";
            }
            if (!String.IsNullOrWhiteSpace(interpArgs)) {
                dbgInfo.bstrOptions += ";" + AD7Engine.InterpreterOptions + "=" + interpArgs.Replace(";", ";;");
            }
            var djangoDebugging = _project.GetProperty("DjangoDebugging");
            bool enableDjango;
            if (!String.IsNullOrWhiteSpace(djangoDebugging) && Boolean.TryParse(djangoDebugging, out enableDjango)) {
                dbgInfo.bstrOptions += ";" + AD7Engine.EnableDjangoDebugging + "=True";
            }

            SetupEnvironment(env);
            if (env.Count > 0) {
                // add any inherited env vars
                var variables = Environment.GetEnvironmentVariables();
                foreach (var key in variables.Keys) {
                    string strKey = (string)key;
                    if (!env.ContainsKey(strKey)) {
                        env.Add(strKey, (string)variables[key]);
                    }
                }

                //Environemnt variables should be passed as a
                //null-terminated block of null-terminated strings.
                //Each string is in the following form:name=value\0
                StringBuilder buf = new StringBuilder();
                foreach (DictionaryEntry entry in env) {
                    buf.AppendFormat("{0}={1}\0", entry.Key, entry.Value);
                }
                buf.Append("\0");
                dbgInfo.bstrEnv = buf.ToString();
            }
            // Set the J debugger
            dbgInfo.clsidCustom = new Guid(AD7Engine.DebugEngineId);
            dbgInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Example #59
0
        /// <summary>
        /// Default implementation of the "Start Debugging" command.
        /// </summary>
        private void StartWithDebugger(string startupFile)
        {
            VsDebugTargetInfo dbgInfo = new VsDebugTargetInfo();
            dbgInfo.cbSize = (uint)Marshal.SizeOf(dbgInfo);

            SetupDebugInfo(ref dbgInfo, startupFile);

            LaunchDebugger(JToolsPackage.Instance, dbgInfo);
        }
Example #60
0
        /// <include file='doc\ProjectConfig.uex' path='docs/doc[@for="ProjectConfig.DebugLaunch"]/*' />
        public virtual int DebugLaunch(uint flags)
        {
            CCITracing.TraceCall();

            try
            {
                VsDebugTargetInfo info = new VsDebugTargetInfo();
                info.cbSize = (uint)Marshal.SizeOf(info);
                info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

                // On first call, reset the cache, following calls will use the cached values
                string property = GetConfigurationProperty("StartProgram", true);
                if (property != null && property.Length > 0)
                {
                    info.bstrExe = property;
                }
                else
                {
                    info.bstrExe = this.project.GetOutputAssembly(this.ConfigName);
                }

                property = GetConfigurationProperty("WorkingDirectory", false);
                if (property != null && property.Length > 0)
                {
                    info.bstrCurDir = property;
                }
                else
                {
                    info.bstrCurDir = Path.GetDirectoryName(info.bstrExe);
                }

                property = GetConfigurationProperty("CmdArgs", false);
                if (property != null && property.Length > 0)
                {
                    info.bstrArg = property;
                }

                property = GetConfigurationProperty("RemoteDebugMachine", false);
                if (property != null && property.Length > 0)
                {
                    info.bstrRemoteMachine = property;
                }

                info.fSendStdoutToOutputWindow = 0;
                info.clsidCustom = CLSID_ComPlusOnlyDebugEngine;
                info.grfLaunch = flags;
                this.project.LaunchDebugger(info);
            }
            catch
            {
                return NativeMethods.E_FAIL;
            }

            return NativeMethods.S_OK;
        }