/// <summary> /// Sends the event. /// </summary> /// <param name="engine"> The AD7Engine object that represents the DE. </param> public static void Send(AD7Engine engine) { var xEvent = new AD7EntryPointEvent(); engine.Callback.Send(xEvent, IID, engine.currentThread()); }
public static void Send(AD7Engine engine) { var xEvent = new AD7EntryPointEvent(); engine.Callback.Send(xEvent, IID, engine.currentThread()); }
/// <summary> /// Attach the debug engine to a program. (http://msdn.microsoft.com/en-us/library/bb145136.aspx) /// </summary> /// <param name="rgpPrograms"> Represent programs to be attached to. These are port programs. </param> /// <param name="rgpProgramNodes"> Represent program nodes, one for each program. The program nodes in this array represent /// the same programs as in pProgram. The program nodes are given so that the DE can identify the programs to attach to. </param> /// <param name="aCeltPrograms"> Number of programs and/or program nodes in the pProgram and rgpProgramNodes arrays. </param> /// <param name="ad7Callback"> The IDebugEventCallback2 object to be used to send debug events to the SDM. </param> /// <param name="dwReason"> A value from the ATTACH_REASON enumeration that specifies the reason for attaching these programs. </param> /// <returns> If successful, returns S_OK; otherwise, returns an error code. </returns> int IDebugEngine2.Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint aCeltPrograms, IDebugEventCallback2 ad7Callback, enum_ATTACH_REASON dwReason) { if (aCeltPrograms != 1) { System.Diagnostics.Debug.Fail("VSNDK Debugger only supports one debug target at a time."); throw new ArgumentException(); } try { EngineUtils.RequireOk(rgpPrograms[0].GetProgramId(out m_programGUID)); m_program = rgpPrograms[0]; // It is NULL when the user attached the debugger to a running process (by using Attach to Process UI). When that // happens, some objects must be instantiated, as well as GDB must be launched. Those ones are instantiated/launched // by LaunchSuspended and ResumeProcess methods when debugging an open project. if (this.m_engineCallback == null) { VSNDK.Package.ControlDebugEngine.isDebugEngineRunning = true; m_engineCallback = new EngineCallback(this, ad7Callback); AD7ProgramNodeAttach pnt = (AD7ProgramNodeAttach)m_program; m_process = pnt.m_process; AD7Port port = pnt.m_process._portAttach; string publicKeyPath = Environment.GetEnvironmentVariable("AppData") + @"\BlackBerry\bbt_id_rsa.pub"; string progName = pnt.m_programName.Substring(pnt.m_programName.LastIndexOf('/') + 1); string exePath = ""; string processesPaths = ""; System.IO.StreamReader readProcessesPathsFile = null; // Read the file ProcessesPath.txt to try to get the file location of the executable file. try { readProcessesPathsFile = new System.IO.StreamReader(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Research In Motion\ProcessesPath.txt"); processesPaths = readProcessesPathsFile.ReadToEnd(); readProcessesPathsFile.Close(); } catch (Exception e) { processesPaths = ""; } string searchProgName = progName + "_" + port.m_isSimulator; int begin = processesPaths.IndexOf(searchProgName + ":>"); if (begin != -1) { begin += searchProgName.Length + 2; int end = processesPaths.IndexOf("\r\n", begin); exePath = processesPaths.Substring(begin, end - begin) + progName; } else { exePath = "CannotAttachToRunningProcess"; } exePath = exePath.Replace("\\", "\\\\\\\\"); if (GDBParser.LaunchProcess(pnt.m_programID, exePath, port.m_IP, port.m_isSimulator, port.m_toolsPath, publicKeyPath, port.m_password)) { if (exePath == "CannotAttachToRunningProcess") { MessageBox.Show(progName + " is attached to the debugger. However, to be able to debug your application, you must build and deploy it from this computer first.", "No executable file with symbols found.", MessageBoxButtons.OK, MessageBoxIcon.Warning); } m_eventDispatcher = new EventDispatcher(this); m_module = new AD7Module(); m_progNode = new AD7ProgramNode(m_process._processGUID, m_process._processID, exePath, new Guid(AD7Engine.Id)); AddThreadsToProgram(); } else { GDBParser.exitGDB(); VSNDK.Package.ControlDebugEngine.isDebugEngineRunning = false; return VSConstants.E_FAIL; } } AD7EngineCreateEvent.Send(this); AD7ProgramCreateEvent.Send(this); AD7ModuleLoadEvent.Send(this, m_module, true); AD7LoadCompleteEvent.Send(this, currentThread()); // If the reason for attaching is ATTACH_REASON_LAUNCH, the DE needs to send the IDebugEntryPointEvent2 event. // See http://msdn.microsoft.com/en-us/library/bb145136%28v=vs.100%29.aspx if (dwReason == enum_ATTACH_REASON.ATTACH_REASON_LAUNCH) { AD7EntryPointEvent ad7Event = new AD7EntryPointEvent(); Guid riidEvent = new Guid(AD7EntryPointEvent.IID); uint attributes = (uint)enum_EVENTATTRIBUTES.EVENT_STOPPING | (uint)enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS; int rc = ad7Callback.Event(this, null, m_program, currentThread(), ad7Event, ref riidEvent, attributes); Debug.Assert(rc == VSConstants.S_OK); } } catch (Exception e) { return EngineUtils.UnexpectedException(e); } return VSConstants.S_OK; }
// Attach the debug engine to a program. int IDebugEngine2.Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint aCeltPrograms, IDebugEventCallback2 ad7Callback, enum_ATTACH_REASON dwReason) { // Attach the debug engine to a program. // // Attach can either be called to attach to a new process, or to complete an attach // to a launched process. // So could we simplify and move code from LaunchSuspended to here and maybe even // eliminate the debughost? Although I supposed DebugHost has some other uses as well. if (aCeltPrograms != 1) { System.Diagnostics.Debug.Fail("Cosmos Debugger only supports one debug target at a time."); throw new ArgumentException(); } try { EngineUtils.RequireOk(rgpPrograms[0].GetProgramId(out m_programGUID)); m_program = rgpPrograms[0]; AD7EngineCreateEvent.Send(this); AD7ProgramCreateEvent.Send(this); AD7ModuleLoadEvent.Send(this, m_module, true); // Dummy main thread // We dont support threads yet, but the debugger expects threads. // So we create a dummy object to represente our only "thread". // m_thread = m_process._threads; // m_thread = new AD7Thread(this, m_process); AD7LoadCompleteEvent.Send(this, currentThread()); // If the reason for attaching is ATTACH_REASON_LAUNCH, the DE needs to send the IDebugEntryPointEvent2 event. // See http://msdn.microsoft.com/en-us/library/bb145136%28v=vs.100%29.aspx if (dwReason == enum_ATTACH_REASON.ATTACH_REASON_LAUNCH) { AD7EntryPointEvent ad7Event = new AD7EntryPointEvent(); Guid riidEvent = new Guid(AD7EntryPointEvent.IID); uint attributes = (uint)enum_EVENTATTRIBUTES.EVENT_STOPPING | (uint)enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS; int rc = ad7Callback.Event(this, null, m_program, currentThread(), ad7Event, ref riidEvent, attributes); Debug.Assert(rc == VSConstants.S_OK); } } catch (Exception e) { return EngineUtils.UnexpectedException(e); } return VSConstants.S_OK; }