/// <summary> /// Attaches the Visual Studio debugger to the given process ID. /// </summary> /// <param name="src">The parameter is not used.</param> /// <param name="args">Contains the process ID to attach to.</param> private void Attach(object src, PluginFoundEventArgs args) { foreach (EnvDTE.Process proc in Dte.Debugger.LocalProcesses) { if (proc.ProcessID == args.ProcessID) { proc.Attach(); break; } } }
/// <summary> /// Attaches the NaCl GDB debugger to the NaCl plug-in process. Handles loading symbols /// and breakpoints from Visual Studio. /// </summary> /// <param name="src">The parameter is not used.</param> /// <param name="args"> /// Contains the process ID to attach to, unused since debug stub is already attached. /// </param> private void Attach(object src, PluginFoundEventArgs args) { // Clean up any pre-existing GDB process (can happen if user reloads page). CleanUpGDBProcess(); // Create the initialization file to read in on GDB start. gdbInitFileName_ = Path.GetTempFileName(); StringBuilder contents = new StringBuilder(); if (!string.IsNullOrEmpty(manifestPath_)) { string manifestEscaped = manifestPath_.Replace("\\", "\\\\"); contents.AppendFormat("nacl-manifest {0}\n", manifestEscaped); } else { string pluginAssemblyEscaped = targetNexe_.Replace("\\", "\\\\"); contents.AppendFormat("file \"{0}\"\n", pluginAssemblyEscaped); } // irtPath_ could be null if the irt nexe was not found in the chrome // install. if (irtPath_ != null) { string irtPathEscaped = irtPath_.Replace("\\", "\\\\"); contents.AppendFormat("nacl-irt \"{0}\"\n", irtPathEscaped); } contents.AppendFormat("target remote localhost:{0}\n", 4014); // Insert breakpoints from Visual Studio project. if (Dte.Debugger.Breakpoints != null) { foreach (Breakpoint bp in Dte.Debugger.Breakpoints) { if (!bp.Enabled) { continue; } if (bp.LocationType == dbgBreakpointLocationType.dbgBreakpointLocationTypeFile) { contents.AppendFormat("b {0}:{1}\n", Path.GetFileName(bp.File), bp.FileLine); } else if (bp.LocationType == dbgBreakpointLocationType.dbgBreakpointLocationTypeFunction) { contents.AppendFormat("b {0}\n", bp.FunctionName); } else { Utility.WebServerWriteLine( Dte, string.Format(Strings.UnsupportedBreakpointTypeFormat, bp.LocationType.ToString())); } } } contents.AppendLine("continue"); File.WriteAllText(gdbInitFileName_, contents.ToString()); // Start NaCl-GDB. try { gdbProcess_ = new System.Diagnostics.Process(); gdbProcess_.StartInfo.UseShellExecute = true; gdbProcess_.StartInfo.FileName = gdbPath_; gdbProcess_.StartInfo.Arguments = string.Format("-x {0}", gdbInitFileName_); gdbProcess_.StartInfo.WorkingDirectory = projectDirectory_; gdbProcess_.Start(); } catch (Exception e) { MessageBox.Show( string.Format("NaCl-GDB Start Failed. {0}. Path: {1}", e.Message, gdbPath_)); } }