Ejemplo n.º 1
0
        public static void SendCommand(String command)
        {
            if (!AlcantareaHelper.SendCommand(command))
            {
                ShowMessage("Alcantarea: Error",
                            @"Failed to send command to program. Possible reason:
- Program was not started by 'Alcantarea->Start'
- Failed to start TCP server
  The port was already used, blocked by firewall, etc.
- Server port and client port are different
  'Alcantarea->Option->TCP Connection' to reset"
                            );
            }
        }
Ejemplo n.º 2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            AlcantareaHelper.SymGlobalIgnore = ((BindingList <alcGlobalSymFilterColumn>)dataGridViewSymIgnore.DataSource).ToList();
            AlcantareaHelper.HookLoadLibrary = checkBoxHook.Checked;
            try
            {
                AlcantareaHelper.TCPPort = Convert.ToUInt16(textBoxTCPPort.Text);
            }
            catch (Exception)
            { }

            AlcantareaHelper.SaveConfig();
            Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// </summary>
        private void onAttachToDebugee(object sender, EventArgs e)
        {
            DTE dte = (DTE)GetService(typeof(DTE));

            EnvDTE.Debugger debugger = dte.Debugger;
            if (debugger.DebuggedProcesses.Count > 0)
            {
                EnvDTE.Process process = debugger.DebuggedProcesses.Item(1);
                if (AlcantareaHelper.InjectCoreDLL((uint)process.ProcessID, m_addindir))
                {
                    onUIContext((int)UIContext.AlcDebugging, 1);
                }
            }
        }
Ejemplo n.º 4
0
        public static List <alcSymbolFilterColumn> GetDefaultFilter(String path_to_obj, bool show_error = true)
        {
            List <alcSymbolFilterColumn> ret = null;

            try
            {
                ret = AlcantareaHelper.GetDefaultSymbolFilter(path_to_obj, true);
            }
            catch (Exception e)
            {
                if (show_error)
                {
                    AlcantareaPackage.ShowMessage("Alcantarea: Error", e.Message);
                }
            }
            return(ret);
        }
Ejemplo n.º 5
0
 public static bool SaveConfig(String ConfigFilePath, List <alcSymbolFilterColumn> Filter)
 {
     try
     {
         StreamWriter writer = new StreamWriter(ConfigFilePath);
         try
         {
             XmlSerializer serializer = new XmlSerializer(typeof(List <alcSymbolFilterColumn>));
             serializer.Serialize(writer, AlcantareaHelper.ApplyIgnorePattern(Filter));
         }
         catch (Exception) { }
         writer.Close();
         return(true);
     }
     catch (Exception)
     {
     }
     return(false);
 }
Ejemplo n.º 6
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (!NeedsSave)
                {
                    File.Delete(ConfigFilePath);
                }
                else
                {
                    SymbolFilterUtil.SaveConfig(ConfigFilePath, FilterData.ToList());
                }
            }
            catch (Exception)
            {
            }

            AlcantareaHelper.RequestSetSymbolFilter(TargetFilePath, FilterData.ToList());
            Close();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Default constructor of the package.
        /// Inside this method you can place any initialization code that does not require
        /// any Visual Studio service because at this point the package object is created but
        /// not sited yet inside Visual Studio environment. The place to do all the other
        /// initialization is the Initialize method.
        /// </summary>
        public AlcantareaPackage()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));

            Instance   = this;
            m_addindir = Path.GetDirectoryName(typeof(AlcantareaPackage).Assembly.Location);
            try
            {
                AlcantareaHelper.Startup(m_addindir);
            }
            catch (Exception er)
            {
                ShowMessage("Alcantarea: Notice", er.Message);
            }

            Guid cmdset = GuidList.guidAlcantareaCmdSet;

            m_commands = new CommandData[] {
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcStartDebugging), onStartDebugging, (int c) => { return((c & (int)UIContext.Debugging) == 0); }),
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcAttachToDebugee), onAttachToDebugee, (int c) => { return((c & (int)UIContext.AlcDebugging) == (int)UIContext.Debugging); }),
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcApplyChange), onApplyChange, (int c) => { return((c & (int)UIContext.AlcDebugging) == (int)UIContext.AlcDebugging); }),
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcSymbolFilter), onSymbolFilter, (int c) => { return((c & (int)UIContext.AlcDebugging) == (int)UIContext.AlcDebugging); }),
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcToggleSuspend), onToggleSuspend, (int c) => { return((c & (int)UIContext.AlcDebugging) == (int)UIContext.AlcDebugging); }),
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcReloadSymbols), onLoadSymbols, (int c) => { return((c & (int)UIContext.AlcDebugging) == (int)UIContext.AlcDebugging); }),
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcLoadObjFiles), onLoadObjFiles, (int c) => { return((c & (int)UIContext.AlcDebugging) == (int)UIContext.AlcDebugging); }),
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcReloadObjFiles), onReloadObjFiles, (int c) => {
                    return((c & (int)UIContext.Debugging) != 0 &&
                           AlcantareaPackage.Instance.LastLoadedObjFiles != null &&
                           AlcantareaPackage.Instance.LastLoadedObjFiles.Length > 0);
                }),
                new CommandData(new CommandID(cmdset, (int)PkgCmdIDList.alcOptions), onOptions, (int c) => { return(true); }),
            };

            m_uichandler = new UIContextHandler(this);
            GlobalConfig = new alcGlobalConfig();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// </summary>
        private void onApplyChange(object sender, EventArgs e)
        {
            DTE            dte   = (DTE)GetService(typeof(DTE));
            VCDocumentInfo vcdoc = new VCDocumentInfo(dte);

            if (!vcdoc.IsValid())
            {
                return;
            }

            dte.ActiveDocument.Save();

            List <String>    cur_func = ProjectUtil.GetFunctionsInCurrentPosition(dte);
            VCFileW          vcfile   = vcdoc.VCFile;
            VCConfigurationW vcconf   = vcdoc.VCConfiguration;

            Dictionary <String, String> properties = new Dictionary <String, String>();

            properties.Add("Configuration", vcconf.Evaluate("$(Configuration)"));
            properties.Add("Platform", vcconf.Evaluate("$(Platform)"));
            properties.Add("SelectedFiles", vcdoc.FileRelpath);
            properties.Add("BuildProjectReferences", "false");
            properties.Add("SolutionDir", vcconf.Evaluate("$(SolutionDir)"));
            properties.Add("SolutionExt", vcconf.Evaluate("$(SolutionExt)"));
            properties.Add("SolutionName", vcconf.Evaluate("$(SolutionName)"));
            properties.Add("SolutionFileName", vcconf.Evaluate("$(SolutionFileName)"));
            properties.Add("SolutionPath", vcconf.Evaluate("$(SolutionPath)"));

            RunBuild(vcdoc.ProjPath, vcfile.ItemType, properties, (BuildLogger logger) =>
            {
                if (vcfile.ItemType == "ClCompile")
                {
                    List <alcSymbolFilterColumn> filter = SymbolFilterUtil.GetDefaultFilter(vcdoc.ObjPath, true);
                    {
                        List <alcSymbolFilterColumn> loaded_filter = SymbolFilterUtil.LoadFromConfigFile(vcdoc.ObjFilterPath);
                        if (loaded_filter != null)
                        {
                            filter = SymbolFilterUtil.MergeFilter(filter, loaded_filter);
                        }
                    }

                    if (filter != null && cur_func.Count > 0)
                    {
                        bool changed = false;
                        foreach (alcSymbolFilterColumn c in filter)
                        {
                            foreach (String f in cur_func)
                            {
                                if (c.Name == f)
                                {
                                    c.FlagUpdate = true;
                                    changed      = true;
                                }
                            }
                        }
                        if (changed)
                        {
                            SymbolFilterUtil.SaveConfig(vcdoc.ObjFilterPath, filter);
                        }
                    }
                    else
                    {
                        logger.Write(String.Format("Alcantarea warning: could not get cursor's current position function\n"));
                    }
                    AlcantareaHelper.RequestSetSymbolFilter(vcdoc.ObjPath, filter);
                    SendCommand("dpLoadBinary\n" + vcdoc.ObjPath + "\n\n");
                }
            });
        }
Ejemplo n.º 9
0
        /// <summary>
        /// </summary>
        private void onStartDebugging(object sender, EventArgs e)
        {
            m_context |= (int)UIContext.AlcStart;

            DTE dte = (DTE)GetService(typeof(DTE));

            IVsOutputWindowPane pane = (IVsOutputWindowPane)Package.GetGlobalService(typeof(SVsGeneralOutputWindowPane));

            VCProjectW       vcproj;
            VCConfigurationW cfg;

            if (!ProjectUtil.getStartupProjectAndConfig(dte, out vcproj, out cfg))
            {
                return;
            }

            String exepath     = cfg.Evaluate("$(TargetPath)");
            String workdir     = cfg.Evaluate("$(LocalDebuggerWorkingDirectory)");
            String environment = cfg.Evaluate("$(LocalDebuggerEnvironment)");
            String platform    = cfg.Evaluate("$(Platform)");
            String addindir    = m_addindir;

            if (pane != null)
            {
                pane.OutputString(exepath);
            }

            if (!File.Exists(exepath))
            {
                ShowMessage("Alcantarea: Error", "Executabe " + exepath + " not found");
                return;
            }

            // プロセスを suspend で起動して DynamicPatcher を inject
            uint pid = AlcantareaHelper.ExecuteSuspended(exepath, workdir, addindir, environment, platform);

            if (pid != 0)
            {
                // デバッガを attach
                VsDebugTargetInfo2 info = new VsDebugTargetInfo2();
                info.cbSize  = (uint)Marshal.SizeOf(info);
                info.bstrExe = exepath;
                info.dlo     = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning;
                //info.dlo = (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AttachToSuspendedLaunchProcess; // somehow this makes debugger not work
                info.dwProcessId = pid;
                info.LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd | (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop;

                Guid   guidDbgEngine = VSConstants.DebugEnginesGuids.ManagedAndNative_guid;
                IntPtr pGuids        = Marshal.AllocCoTaskMem(Marshal.SizeOf(guidDbgEngine));
                Marshal.StructureToPtr(guidDbgEngine, pGuids, false);
                info.pDebugEngines      = pGuids;
                info.dwDebugEngineCount = 1;

                IVsDebugger2 idbg = (IVsDebugger2)Package.GetGlobalService(typeof(SVsShellDebugger));
                IntPtr       ptr  = Marshal.AllocCoTaskMem((int)info.cbSize);
                Marshal.StructureToPtr(info, ptr, false);
                int ret = idbg.LaunchDebugTargets2(1, ptr);

                // プロセスのスレッドを resume
                AlcantareaHelper.Resume(pid);
            }
        }