int IDebugEngine2.ContinueFromSynchronousEvent(IDebugEvent2 aEvent) { // Called by the SDM to indicate that a synchronous debug event, previously sent by the DE to the SDM, // was received and processed. The only event the engine sends in this fashion is Program Destroy. // It responds to that event by shutting down the engine. // // This is used in some cases - I set a BP here and it does get hit sometime during breakpoints // being triggered for example. try { if (aEvent is AD7ProgramDestroyEvent) { mEngineCallback = null; mProgramID = Guid.Empty; mThread = null; mProgNode = null; } else { System.Diagnostics.Debug.Fail("Unknown synchronious event"); } } catch (Exception e) { return(EngineUtils.UnexpectedException(e)); } return(VSConstants.S_OK); }
public void SetUp() { // Whole bunch of setup code. XmlElement taskNode = new XmlDocument().CreateElement("MockTask"); LoadedType taskClass = new LoadedType(typeof(MockTask), new AssemblyLoadInfo(typeof(MockTask).Assembly.FullName, null)); engine = new Engine(@"c:\"); Project project = new Project(engine); EngineCallback engineCallback = new EngineCallback(engine); taskExecutionModule = new MockTaskExecutionModule(engineCallback); int handleId = engineCallback.CreateTaskContext(project, null, null, taskNode, EngineCallback.inProcNode, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId)); TaskEngine taskEngine = new TaskEngine ( taskNode, null, /* host object */ "In Memory", project.FullFileName, engine.LoggingServices, handleId, taskExecutionModule, null ); taskEngine.TaskClass = taskClass; engineProxy = new EngineProxy(taskExecutionModule, handleId, project.FullFileName, project.FullFileName, engine.LoggingServices, null); taskExecutionModule2 = new MockTaskExecutionModule(engineCallback, TaskExecutionModule.TaskExecutionModuleMode.MultiProcFullNodeMode); engineProxy2 = new EngineProxy(taskExecutionModule2, handleId, project.FullFileName, project.FullFileName, engine.LoggingServices, null); }
public DebuggedProcess(AD7Engine engine, IPAddress ipAddress, EngineCallback callback) { _engine = engine; _ipAddress = ipAddress; Instance = this; // we do NOT have real Win32 process IDs, so we use a guid AD_PROCESS_ID pid = new AD_PROCESS_ID(); pid.ProcessIdType = (int)enum_AD_PROCESS_ID.AD_PROCESS_ID_GUID; pid.guidProcessId = Guid.NewGuid(); this.Id = pid; _callback = callback; }
// During startup these methods are called in this order: // -LaunchSuspended // -ResumeProcess // -Attach - Triggered by Attach int IDebugEngineLaunch2.LaunchSuspended(string aPszServer, IDebugPort2 aPort, string aDebugInfo , string aArgs, string aDir, string aEnv, string aOptions, enum_LAUNCH_FLAGS aLaunchFlags , uint aStdInputHandle, uint aStdOutputHandle, uint hStdError, IDebugEventCallback2 aAD7Callback , out IDebugProcess2 oProcess) { // Launches a process by means of the debug engine. // Normally, Visual Studio launches a program using the IDebugPortEx2::LaunchSuspended method and then attaches the debugger // to the suspended program. However, there are circumstances in which the debug engine may need to launch a program // (for example, if the debug engine is part of an interpreter and the program being debugged is an interpreted language), // in which case Visual Studio uses the IDebugEngineLaunch2::LaunchSuspended method // The IDebugEngineLaunch2::ResumeProcess method is called to start the process after the process has been successfully launched in a suspended state. oProcess = null; try { mEngineCallback = new EngineCallback(this, aAD7Callback); var xDebugInfo = new Dictionary <string, string>(); DictionaryHelper.LoadFromString(xDebugInfo, aDebugInfo); //TODO: In the future we might support command line args for kernel etc //string xCmdLine = EngineUtils.BuildCommandLine(exe, args); //var processLaunchInfo = new ProcessLaunchInfo(exe, xCmdLine, dir, env, options, launchFlags, hStdInput, hStdOutput, hStdError); AD7EngineCreateEvent.Send(this); oProcess = mProcess = new AD7Process(xDebugInfo, mEngineCallback, this, aPort); // We only support one process, so just use its ID for the program ID mProgramID = mProcess.ID; //AD7ThreadCreateEvent.Send(this, xProcess.Thread); mModule = new AD7Module(); mProgNode = new AD7ProgramNode(mProcess.PhysID); } catch (NotSupportedException) { return(VSConstants.S_FALSE); } catch (Exception e) { return(EngineUtils.UnexpectedException(e)); } return(VSConstants.S_OK); }
public int LaunchSuspended(string pszServer, IDebugPort2 port, string exe, string args, string dir, string env, string options, enum_LAUNCH_FLAGS launchFlags, uint hStdInput, uint hStdOutput, uint hStdError, IDebugEventCallback2 ad7Callback, out IDebugProcess2 process) { DebugHelper.TraceEnteringMethod(); Callback = new EngineCallback(this, ad7Callback); DebuggedProcess = new DebuggedProcess(this, IPAddress.Parse(args), Callback); DebuggedProcess.ApplicationClosed += _debuggedProcess_ApplicationClosed; DebuggedProcess.StartDebugging(); process = RemoteProcess = new MonoProcess(port); return VSConstants.S_OK; }
/// <summary> /// Return a pointer to the unamanged version of this callback. /// </summary> /// <param name="callback">The callback.</param> /// <returns>A pointer to a shadow c++ callback</returns> public static IntPtr ToIntPtr(EngineCallback callback) { return ToIntPtr<EngineCallback>(callback); }
public void TargetInProgressStateCustomSerialization() { Engine engine = new Engine(@"c:\"); Project project = ObjectModelHelpers.CreateInMemoryProject(@" <Project DefaultTargets=`t` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <PropertyGroup> <OutputPath>bin\Debug\</OutputPath> <AssemblyName>MyAssembly</AssemblyName> <OutputType>Exe</OutputType> <Configuration>Debug</Configuration> </PropertyGroup> <ItemGroup> <Compile Include=`Class1.cs` /> <EmbeddedResource Include=`Resource1.txt` /> <EmbeddedResource Include=`Resource2.resx` /> </ItemGroup> <Target Name='t' DependsOnTargets='Build'/> <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.Targets` /> </Project> "); EngineCallback engineCallback = new EngineCallback(engine); Target build = project.Targets["Build"]; List <ProjectBuildState> waitingBuildStates = null; int handleId = 1; string projectFileName = "ProjectFileName"; string[] targetNames = new string[] { "t" }; Dictionary <string, string> dictionary = null; int requestId = 1; BuildRequest request = new BuildRequest(handleId, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false); ArrayList targetNamesToBuild = new ArrayList(); targetNamesToBuild.Add("t"); ProjectBuildState initiatingRequest = new ProjectBuildState(request, targetNamesToBuild, new BuildEventContext(1, 2, 2, 2)); initiatingRequest.AddBlockingTarget("Build"); BuildRequest [] outstandingBuildRequests = null; string projectName = "SuperTestProject"; TargetInProgessState targetInProgress1 = new TargetInProgessState( engineCallback, build, waitingBuildStates, initiatingRequest, outstandingBuildRequests, projectName ); targetInProgress1.ParentTargetsForBuildRequests = null; Assertion.AssertNull(targetInProgress1.ParentTargetsForBuildRequests); Assertion.Assert(!targetInProgress1.RequestedByHost); build = project.Targets["t"]; request = new BuildRequest(handleId, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false); request.IsExternalRequest = true; targetNamesToBuild.Add("t"); initiatingRequest = new ProjectBuildState(request, targetNamesToBuild, new BuildEventContext(1, 2, 2, 2)); outstandingBuildRequests = new BuildRequest[] { new BuildRequest(1, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false), new BuildRequest(2, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false), new BuildRequest(3, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false), new BuildRequest(4, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false) }; TargetInProgessState.TargetIdWrapper originalWrapper = new TargetInProgessState.TargetIdWrapper(); originalWrapper.id = 1; originalWrapper.name = "Wrapper"; originalWrapper.nodeId = 4; originalWrapper.projectId = 6; waitingBuildStates = new List <ProjectBuildState>(); waitingBuildStates.Add(initiatingRequest); TargetInProgessState targetInProgress3 = new TargetInProgessState( engineCallback, build, waitingBuildStates, initiatingRequest, outstandingBuildRequests, projectName ); targetInProgress3.ParentTargetsForBuildRequests = new TargetInProgessState.TargetIdWrapper[] { originalWrapper }; // Stream, writer and reader where the events will be serialized and deserialized from MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); BinaryReader reader = new BinaryReader(stream); try { stream.Position = 0; // Serialize targetInProgress3.WriteToStream(writer); // Get position of stream after write so it can be compared to the position after read long streamWriteEndPosition = stream.Position; // Deserialize and Verify stream.Position = 0; TargetInProgessState newInProgressState = new TargetInProgessState(); newInProgressState.CreateFromStream(reader); long streamReadEndPosition = stream.Position; Assert.IsTrue(string.Compare(newInProgressState.ProjectName, projectName, StringComparison.OrdinalIgnoreCase) == 0); Assert.IsTrue(string.Compare(newInProgressState.TargetId.name, "t", StringComparison.OrdinalIgnoreCase) == 0); Assert.IsNotNull(newInProgressState.ParentTargets); Assert.IsTrue(newInProgressState.OutstandingBuildRequests.Length == 4); Assert.IsNotNull(newInProgressState.ParentBuildRequests); Assert.IsNotNull(newInProgressState.ParentTargetsForBuildRequests.Length == 1); stream.Position = 0; // Serialize targetInProgress1.WriteToStream(writer); // Get position of stream after write so it can be compared to the position after read streamWriteEndPosition = stream.Position; // Deserialize and Verify stream.Position = 0; newInProgressState = new TargetInProgessState(); newInProgressState.CreateFromStream(reader); streamReadEndPosition = stream.Position; Assert.IsTrue(string.Compare(newInProgressState.ProjectName, projectName, StringComparison.OrdinalIgnoreCase) == 0); Assert.IsTrue(string.Compare(newInProgressState.TargetId.name, "Build", StringComparison.OrdinalIgnoreCase) == 0); Assert.IsNotNull(newInProgressState.ParentTargets); Assert.IsNull(newInProgressState.OutstandingBuildRequests); Assert.IsNotNull(newInProgressState.ParentBuildRequests); TargetInProgessState targetInProgress2 = new TargetInProgessState(); stream.Position = 0; // Serialize targetInProgress2.WriteToStream(writer); // Get position of stream after write so it can be compared to the position after read streamWriteEndPosition = stream.Position; // Deserialize and Verify stream.Position = 0; newInProgressState = new TargetInProgessState(); newInProgressState.CreateFromStream(reader); streamReadEndPosition = stream.Position; Assert.IsNull(newInProgressState.ProjectName); Assert.IsNull(newInProgressState.TargetId); Assert.IsNull(newInProgressState.ParentTargets); Assert.IsNull(newInProgressState.OutstandingBuildRequests); Assert.IsNull(newInProgressState.ParentBuildRequests); } finally { // Close will close the writer/reader and the underlying stream writer.Close(); reader.Close(); reader = null; stream = null; writer = null; } }
/// <summary> /// Return a pointer to the unamanged version of this callback. /// </summary> /// <param name="callback">The callback.</param> /// <returns>A pointer to a shadow c++ callback</returns> public static IntPtr ToIntPtr(EngineCallback callback) { return(ToCallbackPtr <EngineCallback>(callback)); }
public MockTaskExecutionModule(EngineCallback nodeProxy, TaskExecutionModule.TaskExecutionModuleMode moduleMode) : base(nodeProxy, moduleMode, false) { }
public MockTaskExecutionModule(EngineCallback nodeProxy) : base(nodeProxy, TaskExecutionModule.TaskExecutionModuleMode.SingleProcMode, false) { }
internal AD7Process(Dictionary <string, string> aDebugInfo, EngineCallback aCallback, AD7Engine aEngine, IDebugPort2 aPort) { mCallback = aCallback; mDebugInfo = aDebugInfo; mLaunch = (LaunchType)Enum.Parse(typeof(LaunchType), aDebugInfo[BuildPropertyNames.LaunchString]); if (mDebugDownPipe == null) { mDebugDownPipe = new PipeClient(Pipes.DownName); mDebugUpPipe = new PipeServer(Pipes.UpName); mDebugUpPipe.DataPacketReceived += mDebugUpPipe_DataPacketReceived; mDebugUpPipe.Start(); } else { mDebugUpPipe.CleanHandlers(); mDebugUpPipe.DataPacketReceived += mDebugUpPipe_DataPacketReceived; } // Must be after mDebugDownPipe is initialized OutputClear(); OutputText("Debugger process initialized."); mISO = mDebugInfo["ISOFile"]; OutputText("Using ISO file " + mISO + "."); mProjectFile = mDebugInfo["ProjectFile"]; // bool xUseGDB = string.Equals(mDebugInfo[BuildPropertyNames.EnableGDBString], "true", StringComparison.InvariantCultureIgnoreCase); OutputText("GDB " + (xUseGDB ? "Enabled" : "Disabled") + "."); // var xGDBClient = false; Boolean.TryParse(mDebugInfo[BuildPropertyNames.StartCosmosGDBString], out xGDBClient); switch (mLaunch) { case LaunchType.VMware: #region CheckIfHyperVServiceIsRunning using (System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("vmms")) { try { if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Running) { AD7Util.MessageBox( "The Hyper-V Virtual Machine Management Service will be stopped. This is needed to allow to run VMware. If you press \"No\" the debug will stop.", "Question"); sc.Stop(); } } catch (InvalidOperationException) { // service not present } } #endregion CheckIfHyperVServiceIsRunning mHost = new VMware(mDebugInfo, xUseGDB); break; #if SERIAL_PORT case LaunchType.Slave: mHost = new Slave(mDebugInfo, xUseGDB); break; #endif case LaunchType.Bochs: // The project has been created on another machine or Bochs has been uninstalled since the project has // been created. if (!BochsSupport.BochsEnabled) { throw new Exception(Resources.BochsIsNotInstalled); } string bochsConfigurationFileName; mDebugInfo.TryGetValue(BuildProperties.BochsEmulatorConfigurationFileString, out bochsConfigurationFileName); if (string.IsNullOrEmpty(bochsConfigurationFileName)) { bochsConfigurationFileName = BuildProperties.BochsDefaultConfigurationFileName; } if (!Path.IsPathRooted(bochsConfigurationFileName)) { // Assume the configuration file name is relative to project output path. bochsConfigurationFileName = Path.Combine(new FileInfo(mDebugInfo["ProjectFile"]).Directory.FullName, mDebugInfo["OutputPath"], bochsConfigurationFileName); } FileInfo bochsConfigurationFile = new FileInfo(bochsConfigurationFileName); // TODO : What if the configuration file doesn't exist ? This will throw a FileNotFoundException in // the Bochs class constructor. Is this appropriate behavior ? mHost = new Bochs(mDebugInfo, xUseGDB, bochsConfigurationFile); //((Host.Bochs)mHost).FixBochsConfiguration(new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("IsoFileName", mISO) }); break; case LaunchType.IntelEdison: mHost = new IntelEdison(mDebugInfo, false); break; case LaunchType.HyperV: mHost = new HyperV(mDebugInfo, false); break; default: throw new Exception("Invalid Launch value: '" + mLaunch + "'."); } mHost.OnShutDown += HostShutdown; string xDbPath = Path.ChangeExtension(mISO, "cdb"); if (!File.Exists(xDbPath)) { throw new Exception("Debug data file " + xDbPath + " not found. Could be a omitted build process of Cosmos project so that not created."); } mDebugInfoDb = new DebugInfo(xDbPath); mDebugInfoDb.LoadLookups(); CreateDebugConnector(); aEngine.BPMgr.SetDebugConnector(mDbgConnector); mEngine = aEngine; mThread = new AD7Thread(aEngine, this); mCallback.OnThreadStart(mThread); mPort = aPort; if (xUseGDB && xGDBClient) { LaunchGdbClient(); } }