/// <summary> /// Check if we need to attach debugger and attach it. /// </summary> private void CheckAttachDebugger() { Debug.Assert(m_runConfig != null); if (m_runConfig.IsExecutedUnderDebugger) { Debug.Assert(m_vsIde != null); DebugTargetInfo debugInfo = new DebugTargetInfo(); debugInfo.ProcessId = m_vsIde.Process.Id; ExecutionUtilities.DebugTarget(m_runContext.ResultSink, m_runContext.RunConfig.TestRun.Id, debugInfo, s_debuggerTimeout); } }
private unsafe DebugTargetInfo CreateDebugTargetInfo( CommandStartInfo startInfo, IPythonProjectLaunchProperties props ) { var dti = new DebugTargetInfo(); var alwaysPause = startInfo.ExecuteInConsoleAndPause; // We only want to debug a web server in a console. startInfo.ExecuteIn = "console"; startInfo.AdjustArgumentsForProcessStartInfo(props.GetInterpreterPath(), handleConsoleAndPause: false); try { dti.Info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; dti.Info.bstrExe = startInfo.Filename; dti.Info.bstrCurDir = startInfo.WorkingDirectory; dti.Info.bstrRemoteMachine = null; dti.Info.fSendStdoutToOutputWindow = 0; if (!(props.GetIsNativeDebuggingEnabled() ?? false)) { dti.Info.bstrOptions = string.Join(";", GetGlobalDebuggerOptions(true, alwaysPause) .Concat(GetProjectDebuggerOptions()) .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s.Replace(";", ";;")) ); } if (startInfo.EnvironmentVariables != null && startInfo.EnvironmentVariables.Any()) { // Environment variables should be passed as a // null-terminated block of null-terminated strings. // Each string is in the following form:name=value\0 var buf = new StringBuilder(); foreach (var kv in startInfo.EnvironmentVariables) { buf.AppendFormat("{0}={1}\0", kv.Key, kv.Value); } buf.Append("\0"); dti.Info.bstrEnv = buf.ToString(); } dti.Info.bstrArg = startInfo.Arguments; if (props.GetIsNativeDebuggingEnabled() ?? false) { dti.Info.dwClsidCount = 2; dti.Info.pClsidList = Marshal.AllocCoTaskMem(sizeof(Guid) * 2); var engineGuids = (Guid *)dti.Info.pClsidList; engineGuids[0] = dti.Info.clsidCustom = DkmEngineId.NativeEng; engineGuids[1] = AD7Engine.DebugEngineGuid; } else { // Set the Python debugger dti.Info.clsidCustom = new Guid(AD7Engine.DebugEngineId); dti.Info.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd; } // Null out dti so that it is not disposed before we return. var result = dti; dti = null; return(result); } finally { if (dti != null) { dti.Dispose(); } } }
public static unsafe DebugTargetInfo CreateDebugTargetInfo(IServiceProvider provider, LaunchConfiguration config) { if (config.Interpreter.Version < new Version(2, 6) && config.Interpreter.Version > new Version(0, 0)) { // We don't support Python 2.5 now that our debugger needs the json module throw new NotSupportedException(Strings.DebuggerPythonVersionNotSupported); } var dti = new DebugTargetInfo(provider); try { dti.Info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; dti.Info.bstrExe = config.GetInterpreterPath(); dti.Info.bstrCurDir = string.IsNullOrEmpty(config.WorkingDirectory) ? PathUtils.GetParent(config.ScriptName) : config.WorkingDirectory; dti.Info.bstrRemoteMachine = null; dti.Info.fSendStdoutToOutputWindow = 0; bool nativeDebug = config.GetLaunchOption(PythonConstants.EnableNativeCodeDebugging).IsTrue(); if (!nativeDebug) { dti.Info.bstrOptions = GetOptions(provider, config); } // Environment variables should be passed as a // null-terminated block of null-terminated strings. // Each string is in the following form:name=value\0 var buf = new StringBuilder(); var fullEnvironment = provider.GetPythonToolsService().GetFullEnvironment(config); foreach (var kv in fullEnvironment) { buf.AppendFormat("{0}={1}\0", kv.Key, kv.Value); } if (buf.Length > 0) { buf.Append("\0"); dti.Info.bstrEnv = buf.ToString(); } dti.Info.bstrArg = GetArgs(config); if (nativeDebug) { dti.Info.dwClsidCount = 2; dti.Info.pClsidList = Marshal.AllocCoTaskMem(sizeof(Guid) * 2); var engineGuids = (Guid *)dti.Info.pClsidList; engineGuids[0] = dti.Info.clsidCustom = DkmEngineId.NativeEng; engineGuids[1] = AD7Engine.DebugEngineGuid; } else { var pyService = provider.GetPythonToolsService(); // Set the Python debugger dti.Info.clsidCustom = pyService.DebuggerOptions.UseLegacyDebugger ? AD7Engine.DebugEngineGuid : DebugAdapterLauncher.VSCodeDebugEngine; dti.Info.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd; if (!pyService.DebuggerOptions.UseLegacyDebugger) { dti.Info.bstrOptions = GetLaunchJsonForVsCodeDebugAdapter(provider, config, fullEnvironment); } } // Null out dti so that it is not disposed before we return. var result = dti; dti = null; return(result); } finally { if (dti != null) { dti.Dispose(); } } }
/// <summary> /// Check if we need to attach debugger and attach it. /// </summary> private void CheckAttachDebugger() { Contract.Assert(_runConfig != null); if (_runConfig.IsExecutedUnderDebugger) { Contract.Assert(_vsIde != null); DebugTargetInfo debugInfo = new DebugTargetInfo(); debugInfo.ProcessId = _vsIde.Process.Id; ExecutionUtilities.DebugTarget(_runContext.ResultSink, _runContext.RunConfig.TestRun.Id, debugInfo, _debuggerTimeout); } }
private unsafe DebugTargetInfo CreateDebugTargetInfo( CommandStartInfo startInfo, IPythonProjectLaunchProperties props ) { var dti = new DebugTargetInfo(); var alwaysPause = startInfo.ExecuteInConsoleAndPause; // We only want to debug a web server in a console. startInfo.ExecuteIn = "console"; startInfo.AdjustArgumentsForProcessStartInfo(props.GetInterpreterPath(), handleConsoleAndPause: false); try { dti.Info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; dti.Info.bstrExe = startInfo.Filename; dti.Info.bstrCurDir = startInfo.WorkingDirectory; dti.Info.bstrRemoteMachine = null; dti.Info.fSendStdoutToOutputWindow = 0; if (!(props.GetIsNativeDebuggingEnabled() ?? false)) { dti.Info.bstrOptions = string.Join(";", GetGlobalDebuggerOptions(true, alwaysPause) .Concat(GetProjectDebuggerOptions()) .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s.Replace(";", ";;")) ); } if (startInfo.EnvironmentVariables != null && startInfo.EnvironmentVariables.Any()) { // Environment variables should be passed as a // null-terminated block of null-terminated strings. // Each string is in the following form:name=value\0 var buf = new StringBuilder(); foreach (var kv in startInfo.EnvironmentVariables) { buf.AppendFormat("{0}={1}\0", kv.Key, kv.Value); } buf.Append("\0"); dti.Info.bstrEnv = buf.ToString(); } dti.Info.bstrArg = startInfo.Arguments; if (props.GetIsNativeDebuggingEnabled() ?? false) { dti.Info.dwClsidCount = 2; dti.Info.pClsidList = Marshal.AllocCoTaskMem(sizeof(Guid) * 2); var engineGuids = (Guid*)dti.Info.pClsidList; engineGuids[0] = dti.Info.clsidCustom = DkmEngineId.NativeEng; engineGuids[1] = AD7Engine.DebugEngineGuid; } else { // Set the Python debugger dti.Info.clsidCustom = new Guid(AD7Engine.DebugEngineId); dti.Info.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd; } // Null out dti so that it is not disposed before we return. var result = dti; dti = null; return result; } finally { if (dti != null) { dti.Dispose(); } } }
public override int DebugLaunch(uint grfLaunch) { DebugTargetInfo info = new DebugTargetInfo(); CommandLineBuilder commandLine = new CommandLineBuilder(); bool x64 = Platform.EndsWith("X64", StringComparison.OrdinalIgnoreCase) || (Platform.EndsWith("Any CPU", StringComparison.OrdinalIgnoreCase) && Environment.Is64BitOperatingSystem); string agentBaseFileName = "Tvl.Java.DebugHostWrapper"; if (x64) { agentBaseFileName += "X64"; } bool useDevelopmentEnvironment = (grfLaunch & (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_NoDebug) == 0; string debugAgentName = GetConfigurationProperty(JavaConfigConstants.DebugAgent, _PersistStorageType.PST_USER_FILE, false); bool useJdwp = string.Equals(DebugAgent.Jdwp.ToString(), debugAgentName, StringComparison.OrdinalIgnoreCase); if (useJdwp) { commandLine.AppendSwitch("-Xdebug"); string serverValue = useDevelopmentEnvironment ? "y" : "n"; commandLine.AppendSwitch("-Xrunjdwp:transport=dt_socket,server=" + serverValue + ",address=6777"); } else { string agentFolder = Path.GetDirectoryName(typeof(JavaProjectConfig).Assembly.Location); string agentFileName = agentBaseFileName + ".dll"; string agentPath = Path.GetFullPath(Path.Combine(agentFolder, agentFileName)); commandLine.AppendSwitchIfNotNull("-agentpath:", agentPath); string agentArguments = GetConfigurationProperty(JavaConfigConstants.DebugAgentArguments, _PersistStorageType.PST_USER_FILE, false); if (!string.IsNullOrEmpty(agentArguments)) { commandLine.AppendTextUnquoted("=" + agentArguments); } } switch (GetConfigurationProperty(JavaConfigConstants.DebugStartAction, _PersistStorageType.PST_USER_FILE, false)) { case "Class": string jvmArguments = GetConfigurationProperty(JavaConfigConstants.DebugJvmArguments, _PersistStorageType.PST_USER_FILE, false); if (!string.IsNullOrEmpty(jvmArguments)) { commandLine.AppendTextUnquoted(" " + jvmArguments); } commandLine.AppendSwitch("-cp"); commandLine.AppendFileNameIfNotNull(GetConfigurationProperty("TargetPath", _PersistStorageType.PST_PROJECT_FILE, false)); string startupObject = GetConfigurationProperty(JavaConfigConstants.DebugStartClass, _PersistStorageType.PST_USER_FILE, false); if (!string.IsNullOrEmpty(startupObject)) { commandLine.AppendFileNameIfNotNull(startupObject); } break; default: throw new NotImplementedException("This preview version of the Java debugger only supports starting execution in a named class; the class name may be configured in the project properties on the Debug tab."); } string debugArgs = GetConfigurationProperty(JavaConfigConstants.DebugExtraArgs, _PersistStorageType.PST_USER_FILE, false); if (!string.IsNullOrEmpty(debugArgs)) { commandLine.AppendTextUnquoted(" " + debugArgs); } string workingDirectory = GetConfigurationProperty(JavaConfigConstants.DebugWorkingDirectory, _PersistStorageType.PST_USER_FILE, false); if (string.IsNullOrEmpty(workingDirectory)) { workingDirectory = GetConfigurationProperty(JavaConfigConstants.OutputPath, _PersistStorageType.PST_PROJECT_FILE, false); } if (!Path.IsPathRooted(workingDirectory)) { workingDirectory = Path.GetFullPath(Path.Combine(this.ProjectManager.ProjectFolder, workingDirectory)); } // Pass the project references via the CLASSPATH environment variable List <string> classPathEntries = new List <string>(); IReferenceContainer referenceContainer = ProjectManager.GetReferenceContainer(); IList <ReferenceNode> references = referenceContainer.EnumReferences(); foreach (var referenceNode in references) { JarReferenceNode jarReferenceNode = referenceNode as JarReferenceNode; if (jarReferenceNode != null) { if (File.Exists(jarReferenceNode.InstalledFilePath) || Directory.Exists(jarReferenceNode.InstalledFilePath)) { classPathEntries.Add(jarReferenceNode.InstalledFilePath); } } } if (classPathEntries != null) { string classPath = string.Join(";", classPathEntries); info.Environment.Add("CLASSPATH", classPath); } //List<string> arguments = new List<string>(); //arguments.Add(@"-agentpath:C:\dev\SimpleC\Tvl.Java.DebugHost\bin\Debug\Tvl.Java.DebugHostWrapper.dll"); ////arguments.Add(@"-verbose:jni"); ////arguments.Add(@"-cp"); ////arguments.Add(@"C:\dev\JavaProjectTest\JavaProject\out\Debug"); //arguments.Add("tvl.school.ee382v.a3.problem1.program1"); ////arguments.Add(GetConfigurationProperty("OutputPath", true)); ////arguments.Add(GetConfigurationProperty(JavaConfigConstants.DebugStartClass, false, _PersistStorageType.PST_USER_FILE)); ////arguments.Add(GetConfigurationProperty(JavaConfigConstants.DebugExtraArgs, false, _PersistStorageType.PST_USER_FILE)); //info.Arguments = string.Join(" ", arguments); info.Arguments = commandLine.ToString(); info.Executable = FindJavaBinary("java.exe", useDevelopmentEnvironment); //info.CurrentDirectory = GetConfigurationProperty("WorkingDirectory", false, _PersistStorageType.PST_USER_FILE); info.CurrentDirectory = workingDirectory; info.SendToOutputWindow = false; info.DebugEngines = new Guid[] { typeof(JavaDebugEngine).GUID, //VSConstants.DebugEnginesGuids.ManagedOnly_guid, //VSConstants.DebugEnginesGuids.NativeOnly_guid, }; Guid localPortSupplier = new Guid("{708C1ECA-FF48-11D2-904F-00C04FA302A1}"); info.PortSupplier = localPortSupplier; info.LaunchOperation = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; info.LaunchFlags = (__VSDBGLAUNCHFLAGS)grfLaunch | (__VSDBGLAUNCHFLAGS)__VSDBGLAUNCHFLAGS2.DBGLAUNCH_MergeEnv; var debugger = (IVsDebugger2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsShellDebugger)); int result = debugger.LaunchDebugTargets(info); if (result != VSConstants.S_OK) { IVsUIShell uishell = (IVsUIShell)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsUIShell)); string message = uishell.GetErrorInfo(); } return(result); }