Ejemplo n.º 1
0
bool CodeFormatter::AStyleBatchFOrmat(const std::vector<wxFileName>& files, const FormatOptions& options)
{
    wxString fmtOptions = options.AstyleOptionsAsString();

    wxProgressDialog dlg(
        _("Source Code Formatter"), _("Formatting files..."), (int)files.size(), m_mgr->GetTheApp()->GetTopWindow());
    for(size_t i = 0; i < files.size(); ++i) {

        wxString content;
        if(!FileUtils::ReadFileContent(files.at(i), content)) {
            CL_WARNING("Failed to read file content. File: %s", files.at(i).GetFullPath());
            continue;
        }

        wxString msg;
        msg << "[ " << i << " / " << files.size() << " ] " << files.at(i).GetFullName();
        dlg.Update(i, msg);

        // determine indentation method and amount
        bool useTabs = m_mgr->GetEditorSettings()->GetIndentUsesTabs();
        int tabWidth = m_mgr->GetEditorSettings()->GetTabWidth();
        int indentWidth = m_mgr->GetEditorSettings()->GetIndentWidth();
        fmtOptions << (useTabs && tabWidth == indentWidth ? wxT(" -t") : wxT(" -s")) << indentWidth;

        wxString output;
        AstyleFormat(content, fmtOptions, output);
        output << DoGetGlobalEOLString();

        // Replace the content of the file
        if(!FileUtils::WriteFileContent(files.at(i), output)) {
            CL_WARNING("Failed to write file content. File: %s", files.at(i).GetFullPath());
        }
    }
    return true;
}
Ejemplo n.º 2
0
bool ValgrindMemcheckProcessor::Process(const wxString & outputLogFileName)
{
    //CL_DEBUG1(PLUGIN_PREFIX("ValgrindMemcheckProcessor::Process()"));

    if (!outputLogFileName.IsEmpty())
        m_outputLogFileName = outputLogFileName;

    CL_DEBUG(PLUGIN_PREFIX("Processing file '%s'", m_outputLogFileName));

    wxXmlDocument doc;
    if (!doc.Load(m_outputLogFileName) || doc.GetRoot()->GetName() != wxT("valgrindoutput")) {
        CL_WARNING("Error while loading file '%s'", m_outputLogFileName);
        return false;
    }
    m_errorList.clear();

    int i = 0;
    wxXmlNode *errorNode = doc.GetRoot()->GetChildren();
    while (errorNode) {
        if (errorNode->GetName() == wxT("error")) {
            m_errorList.push_back(ProcessError(doc, errorNode));
        }
        errorNode = errorNode->GetNext();

        if (i < 1000)
            i++;
        else {
            i = 0;
            //ATTN  m_mgr->GetTheApp()
            wxTheApp->Yield();
        }
    }
    return true;
}
Ejemplo n.º 3
0
void ClangDriver::CodeCompletion(IEditor* editor)
{
    if(m_isBusy) {
        return;
    }

    CL_DEBUG(wxT(" ==========> ClangDriver::CodeCompletion() started <=============="));

    if(!editor) {
        CL_WARNING(wxT("ClangDriver::CodeCompletion() called with NULL editor!"));
        return;
    }

    m_activeEditor = editor;
    m_isBusy = true;
    ClangThreadRequest* request = DoMakeClangThreadRequest(m_activeEditor, GetContext());

    // Failed to prepare request?
    if(request == NULL) {
        m_isBusy = false;
        m_activeEditor = NULL;
        return;
    }

    /////////////////////////////////////////////////////////////////
    // Put a request on the parsing thread
    //
    m_pchMakerThread.Add(request);
}
void MemCheckOutputView::ShowPageView(size_t page)
{
    // CL_DEBUG1(PLUGIN_PREFIX("MemCheckOutputView::ShowPage()"));

    if(page < 1)
        m_currentPage = 1;
    else if(page > m_pageMax)
        m_currentPage = m_pageMax;
    else
        m_currentPage = page;

    if(m_currentPage == 0)
        m_textCtrlPageNumber->Clear();
    else
        pageValidator.TransferToWindow(); // it sets m_textCtrlPageNumber

    m_currentPageIsEmptyView = true;
    m_currentItem = wxDataViewItem(0);
    m_onValueChangedLocked = false;
    m_markedErrorsCount = 0;
    m_dataViewCtrlErrorsModel->Clear();

    if(m_totalErrorsView == 0) return;

    ErrorList& errorList = m_plugin->GetProcessor()->GetErrors();
    long iStart = (long)(m_currentPage - 1) * m_plugin->GetSettings()->GetResultPageSize();
    long iStop =
        (long)std::min(m_totalErrorsView - 1, m_currentPage * m_plugin->GetSettings()->GetResultPageSize() - 1);
    // CL_DEBUG1(PLUGIN_PREFIX("start - stop = %lu - %lu", iStart, iStop));
    m_currentPageIsEmptyView = (iStop - iStart) < 0;

    // this should never happen if m_totalErrorsView > 0, but...
    if(m_currentPageIsEmptyView) return;

    wxWindowDisabler disableAll;
    wxBusyInfo wait(wxT(BUSY_MESSAGE));
    m_mgr->GetTheApp()->Yield();

    unsigned int flags = 0;
    if(m_plugin->GetSettings()->GetOmitNonWorkspace()) flags |= MC_IT_OMIT_NONWORKSPACE;
    if(m_plugin->GetSettings()->GetOmitDuplications()) flags |= MC_IT_OMIT_DUPLICATIONS;
    if(m_plugin->GetSettings()->GetOmitSuppressed()) flags |= MC_IT_OMIT_SUPPRESSED;
    size_t i = 0;
    MemCheckIterTools::ErrorListIterator it = MemCheckIterTools::Factory(errorList, m_workspacePath, flags);
    for(; i < iStart && it != errorList.end(); ++i, ++it)
        ; // skipping item before start
    // CL_DEBUG1(PLUGIN_PREFIX("items skiped"));
    m_mgr->GetTheApp()->Yield();
    for(; i <= iStop; ++i, ++it) {
        if(it == errorList.end()) {
            CL_WARNING(PLUGIN_PREFIX("Some items skiped. Total errors count mismatches the iterator."));
            break;
        }
        AddTree(wxDataViewItem(0), *it); // CL_DEBUG1(PLUGIN_PREFIX("adding %lu", i));
        if(!(i % WAIT_UPDATE_PER_ITEMS)) m_mgr->GetTheApp()->Yield();
    }
}
void FileUtils::OSXOpenDebuggerTerminalAndGetTTY(const wxString& path, wxString& tty, long& pid)
{
    tty.Clear();
    wxString command;
    wxString tmpfile;
    wxString escapedPath = path;
    if(escapedPath.Contains(" ")) {
        escapedPath.Prepend("\"").Append("\"");
    }
    tmpfile << "/tmp/terminal.tty." << ::wxGetProcessId();
    command << "osascript -e 'tell app \"Terminal\" to do script \"tty > " << tmpfile << " && clear && sleep 12345\"'";
    CL_DEBUG("Executing: %s", command);
    long res = ::wxExecute(command);
    if(res == 0) {
        CL_WARNING("Failed to execute command:\n%s", command);
        return;
    }

    // Read the tty from the file, wait for it up to 10 seconds
    wxFileName ttyFile(tmpfile);
    pid = wxNOT_FOUND;
    for(size_t i = 0; i < 10; ++i) {
        if(!ttyFile.Exists()) {
            ::wxSleep(1);
            continue;
        }
        ReadFileContent(ttyFile, tty);
        tty.Trim().Trim(false);

        // Remove the file
        wxLogNull noLog;
        ::wxRemoveFile(ttyFile.GetFullPath());

        // Get the parent process ID (we want the parent PID and not
        // the sleep command PID)
        wxString psCommand;
        psCommand << "ps -A -o ppid,command";
        wxString psOutput = ProcUtils::SafeExecuteCommand(psCommand);
        CL_DEBUG("PS output:\n%s\n", psOutput);
        wxArrayString lines = ::wxStringTokenize(psOutput, "\n", wxTOKEN_STRTOK);
        for(size_t u = 0; u < lines.GetCount(); ++u) {
            wxString l = lines.Item(u);
            l.Trim().Trim(false);
            if(l.Contains("sleep") && l.Contains("12345")) {
                // we got a match
                CL_DEBUG("Got a match!");
                wxString ppidString = l.BeforeFirst(' ');
                ppidString.ToCLong(&pid);
                break;
            }
        }
        break;
    }
    CL_DEBUG("PID is: %d\n", (int)pid);
    CL_DEBUG("TTY is: %s\n", tty);
}
Ejemplo n.º 6
0
bool LLDBConnector::ConnectToRemoteDebugger(const wxString& ip, int port, LLDBConnectReturnObject& ret, int timeout)
{
    m_socket.reset( NULL );
    clSocketClient *client = new clSocketClient();
    m_socket.reset( client );
    CL_DEBUG("Connecting to codelite-lldb on %s:%d", ip, port);
    
    try {
        bool would_block = false;
        if ( !client->ConnectRemote( ip, port, would_block, true ) ) {
            // select the socket
            if (  !would_block ) {
                m_socket.reset( NULL );
                return false;
            }
            
            try {
                if ( client->SelectWrite(timeout) == clSocketBase::kTimeout ) {
                    m_socket.reset( NULL );
                    return false;
                }
            } catch (clSocketException &e) {
                CL_DEBUG("SelectWrite error: %s", e.what());
            }
        }
        
        // Connected!
        // Read the negotiation packet (part of the protocol only when doing remote connection)
        wxString message;
        if ( m_socket->ReadMessage( message, 2 ) != clSocketBase::kSuccess ) {
            m_socket.reset( NULL );
            return false;
        }
        
        LLDBRemoteHandshakePacket handshake( message );
        ret.SetRemoteHostName( handshake.GetHost() );
        ret.SetPivotNeeded( handshake.GetHost() != ::wxGetHostName() );

    } catch (clSocketException &e) {
        CL_WARNING("LLDBConnector::ConnectToRemoteDebugger: %s", e.what());
        m_socket.reset( NULL );
        return false;
    }
    CL_DEBUG("Successfully connected to codelite-lldb");
    return true;
}
bool DbgGdb::WriteCommand(const wxString& command, DbgCmdHandler* handler)
{
    wxString cmd;
    wxString id = MakeId();
    cmd << id << command;

    // Support for reverse debugging
    if(IsReverseDebuggingEnabled() && m_reversableCommands.count(command)) {
        cmd << " --reverse";
    }

    if(!ExecuteCmd(cmd)) {
        CL_WARNING("Failed to send command: %s", cmd);
        return false;
    }
    RegisterHandler(id, handler);
    return true;
}
Ejemplo n.º 8
0
void PHPEntityFunctionAlias::Store(wxSQLite3Database& db)
{
    try {
        wxSQLite3Statement statement = db.PrepareStatement(
                                           "INSERT OR REPLACE INTO FUNCTION_ALIAS_TABLE VALUES(NULL, :SCOPE_ID, :NAME, :REALNAME, :FULLNAME, :SCOPE, "
                                           ":LINE_NUMBER, :FILE_NAME)");
        statement.Bind(statement.GetParamIndex(":SCOPE_ID"), Parent()->GetDbId());
        statement.Bind(statement.GetParamIndex(":NAME"), GetShortName());
        statement.Bind(statement.GetParamIndex(":REALNAME"), GetRealname());
        statement.Bind(statement.GetParamIndex(":FULLNAME"), GetFullName());
        statement.Bind(statement.GetParamIndex(":SCOPE"), GetScope());
        statement.Bind(statement.GetParamIndex(":LINE_NUMBER"), GetLine());
        statement.Bind(statement.GetParamIndex(":FILE_NAME"), GetFilename().GetFullPath());
        statement.ExecuteUpdate();
        SetDbId(db.GetLastRowId());

    } catch(wxSQLite3Exception& exc) {
        CL_WARNING("PHPEntityFunctionAlias::Store: %s", exc.GetMessage());
    }
}
Ejemplo n.º 9
0
bool LLDBConnector::ConnectToLocalDebugger(LLDBConnectReturnObject& ret, int timeout)
{
    
#ifndef __WXMSW__
    clSocketClient *client = new clSocketClient();
    m_socket.reset( client );
    CL_DEBUG("Connecting to codelite-lldb on %s", GetDebugServerPath());
    
    long msTimeout = timeout * 1000;
    long retriesCount = msTimeout / 250; // We try every 250 ms to connect
    bool connected = false;
    for(long i=0; i<retriesCount; ++i) {
        if ( !client->ConnectLocal( GetDebugServerPath() ) ) {
            wxThread::Sleep(250);
            continue;
        }
        connected = true;
        break;
    }
    
    if ( !connected ) {
        return false;
    }
    
    // Start the lldb event thread
    // and start a listener thread which will read replies
    // from codelite-lldb and convert them into LLDBEvent
    socket_t fd = m_socket->GetSocket();
    m_pivot.Clear();
    m_thread = new LLDBNetworkListenerThread(this, m_pivot, fd);
    m_thread->Start();
    CL_DEBUG("Successfully connected to codelite-lldb");
    return true;
#else
    CL_WARNING("LLDB Debugger: can't connect to local debugger - this is not support on MSW");
    return false;
#endif
}
Ejemplo n.º 10
0
void PluginManager::Load()
{
    wxString ext;
#if defined(__WXGTK__)
    ext = wxT("so");

#elif defined(__WXMAC__)
    ext = wxT("dylib");

#else
    ext = wxT("dll");
#endif

    wxString fileSpec(wxT("*.") + ext);
    clConfig conf("plugins.conf");

    conf.ReadItem(&m_pluginsData);

    // set the managers
    // this code assures us that the shared objects will see the same instances as the application
    // does
    LanguageST::Get()->SetTagsManager(GetTagsManager());
    TagsManagerST::Get()->SetLanguage(LanguageST::Get());

    // Plugin loading policy
    CodeLiteApp* app = static_cast<CodeLiteApp*>(GetTheApp());
    CodeLiteApp::PluginPolicy pp = app->GetPluginLoadPolicy();
    wxArrayString allowedPlugins;
    if(pp == CodeLiteApp::PP_None) {
        return;
    }

    else if(pp == CodeLiteApp::PP_FromList)
        allowedPlugins = app->GetAllowedPlugins();

    wxString pluginsDir = clStandardPaths::Get().GetPluginsDirectory();
    if(wxDir::Exists(pluginsDir)) {
        // get list of dlls
        wxArrayString files;
        wxDir::GetAllFiles(pluginsDir, &files, fileSpec, wxDIR_FILES);

        // Sort the plugins by A-Z
        std::sort(files.begin(), files.end());
        for(size_t i = 0; i < files.GetCount(); i++) {

            wxString fileName(files.Item(i));
#if defined(__WXMSW__) && !defined(NDEBUG)

            // Under MSW loading a release plugin while in debug mode will cause a crash
            if(!fileName.EndsWith("-dbg.dll")) {
                continue;
            }
#elif defined(__WXMSW__)

            // filter debug plugins
            if(fileName.EndsWith("-dbg.dll")) {
                continue;
            }
#endif

#ifdef __WXGTK__
            wxFileName fnDLL(fileName);
            if(fnDLL.GetFullName().StartsWith("lib")) {
                // don't attempt to load a library
                continue;
            }
#endif

            clDynamicLibrary* dl = new clDynamicLibrary();
            if(!dl->Load(fileName)) {
                CL_ERROR(wxT("Failed to load plugin's dll: ") + fileName);
                if(!dl->GetError().IsEmpty()) {
                    CL_ERROR(dl->GetError());
                }
                continue;
            }

            bool success(false);
            GET_PLUGIN_INFO_FUNC pfnGetPluginInfo = (GET_PLUGIN_INFO_FUNC)dl->GetSymbol(wxT("GetPluginInfo"), &success);
            if(!success) {
                continue;
            }

            // load the plugin version method
            // if the methods does not exist, handle it as if it has value of 100 (lowest version API)
            int interface_version(100);
            GET_PLUGIN_INTERFACE_VERSION_FUNC pfnInterfaceVersion =
                (GET_PLUGIN_INTERFACE_VERSION_FUNC)dl->GetSymbol(wxT("GetPluginInterfaceVersion"), &success);
            if(success) {
                interface_version = pfnInterfaceVersion();
            } else {
                CL_WARNING(wxT("Failed to find GetPluginInterfaceVersion() in dll: ") + fileName);
                if(!dl->GetError().IsEmpty()) {
                    CL_WARNING(dl->GetError());
                }
            }

            if(interface_version != PLUGIN_INTERFACE_VERSION) {
                CL_WARNING(wxString::Format(wxT("Version interface mismatch error for plugin '%s'. Plugin's interface "
                                                "version is '%d', CodeLite interface version is '%d'"),
                                            fileName.c_str(),
                                            interface_version,
                                            PLUGIN_INTERFACE_VERSION));
                continue;
            }

            // Check if this dll can be loaded
            PluginInfo pluginInfo = pfnGetPluginInfo();

            wxString pname = pluginInfo.GetName();
            pname.MakeLower().Trim().Trim(false);

            // Check the policy
            if(pp == CodeLiteApp::PP_FromList && allowedPlugins.Index(pname) == wxNOT_FOUND) {
                // Policy is set to 'from list' and this plugin does not match any plugins from
                // the list, don't allow it to be loaded
                continue;
            }

            // Add the plugin information
            m_pluginsData.AddPlugin(pluginInfo);

            // Can we load it?
            if(!m_pluginsData.CanLoad(pluginInfo.GetName())) {
                CL_WARNING(wxT("Plugin ") + pluginInfo.GetName() + wxT(" is not enabled"));
                continue;
            }

            // try and load the plugin
            GET_PLUGIN_CREATE_FUNC pfn = (GET_PLUGIN_CREATE_FUNC)dl->GetSymbol(wxT("CreatePlugin"), &success);
            if(!success) {
                CL_WARNING(wxT("Failed to find CreatePlugin() in dll: ") + fileName);
                if(!dl->GetError().IsEmpty()) {
                    CL_WARNING(dl->GetError());
                }

                m_pluginsData.DisablePlugin(pluginInfo.GetName());
                continue;
            }

            // Construct the plugin
            IPlugin* plugin = pfn((IManager*)this);
            CL_DEBUG(wxT("Loaded plugin: ") + plugin->GetLongName());
            m_plugins[plugin->GetShortName()] = plugin;

            // Load the toolbar
            clToolBar* tb = plugin->CreateToolBar((wxWindow*)clMainFrame::Get());
            if(tb) {
#if USE_AUI_TOOLBAR
                // When using AUI toolbars, use our own custom art-provider
                tb->SetArtProvider(new CLMainAuiTBArt());
#endif
                clMainFrame::Get()->GetDockingManager().AddPane(tb,
                                                                wxAuiPaneInfo()
                                                                    .Name(plugin->GetShortName())
                                                                    .LeftDockable(true)
                                                                    .RightDockable(true)
                                                                    .Caption(plugin->GetShortName())
                                                                    .ToolbarPane()
                                                                    .Top()
                                                                    .Row(0));

                // Add menu entry at the 'View->Toolbars' menu for this toolbar
                wxMenuItem* item = clMainFrame::Get()->GetMenuBar()->FindItem(XRCID("toolbars_menu"));
                if(item) {
                    wxMenu* submenu = NULL;
                    submenu = item->GetSubMenu();
                    // add the new toolbar entry at the end of this menu

                    int id = wxNewId();
                    wxString text(plugin->GetShortName());
                    text << _(" ToolBar");
                    wxMenuItem* newItem = new wxMenuItem(submenu, id, text, wxEmptyString, wxITEM_CHECK);
                    submenu->Append(newItem);
                    clMainFrame::Get()->RegisterToolbar(id, plugin->GetShortName());
                }
            }

            // Keep the dynamic load library
            m_dl.push_back(dl);
        }
        clMainFrame::Get()->GetDockingManager().Update();

        // Let the plugins plug their menu in the 'Plugins' menu at the menu bar
        // the create menu will be placed as a sub menu of the 'Plugin' menu
        wxMenu* pluginsMenu = NULL;
        wxMenuItem* menuitem = clMainFrame::Get()->GetMenuBar()->FindItem(XRCID("manage_plugins"), &pluginsMenu);
        if(pluginsMenu && menuitem) {
            std::map<wxString, IPlugin*>::iterator iter = m_plugins.begin();
            for(; iter != m_plugins.end(); ++iter) {
                IPlugin* plugin = iter->second;
                plugin->CreatePluginMenu(pluginsMenu);
            }
        }

        // save the plugins data
        conf.WriteItem(&m_pluginsData);
    }

    // Now that all the plugins are loaded, load from the configuration file
    // list of visible tabs
    static wxArrayString DefaultArray;
    if(DefaultArray.IsEmpty()) {
        DefaultArray.Add("NOT-FOUND");
    }
    {
        const wxArrayString& tabs = GetWorkspaceTabs();
        wxArrayString visibleTabs = clConfig::Get().Read("VisibleWorkspaceTabs", DefaultArray);
        if(!((visibleTabs.size() == 1) && (visibleTabs.Item(0) == "NOT-FOUND"))) {
            for(size_t i = 0; i < tabs.size(); ++i) {
                if(visibleTabs.Index(tabs.Item(i)) == wxNOT_FOUND) {
                    // hidden tab - post an event
                    clCommandEvent eventHide(wxEVT_SHOW_WORKSPACE_TAB);
                    eventHide.SetSelected(false).SetString(tabs.Item(i));
                    EventNotifier::Get()->AddPendingEvent(eventHide);
                }
            }
        }
    }

    {
        const wxArrayString& tabs = GetOutputTabs();
        wxArrayString visibleTabs = clConfig::Get().Read("VisibleOutputTabs", DefaultArray);
        if(!((visibleTabs.size() == 1) && (visibleTabs.Item(0) == "NOT-FOUND"))) {
            for(size_t i = 0; i < tabs.size(); ++i) {
                if(visibleTabs.Index(tabs.Item(i)) == wxNOT_FOUND) {
                    // hidden tab - post an event
                    clCommandEvent eventHide(wxEVT_SHOW_OUTPUT_TAB);
                    eventHide.SetSelected(false).SetString(tabs.Item(i));
                    EventNotifier::Get()->AddPendingEvent(eventHide);
                }
            }
        }
    }
}
void* LLDBNetworkListenerThread::Entry()
{
    while ( !TestDestroy() ) {
        wxString msg;
        try {
            if ( m_socket->ReadMessage(msg, 1) == clSocketBase::kSuccess ) {
                LLDBReply reply(msg);
                reply.UpdatePaths( m_pivot );
                switch( reply.GetReplyType() ) {
                case kReplyTypeDebuggerStartedSuccessfully: {
                    // notify debugger started successfully
                    LLDBEvent event(wxEVT_LLDB_STARTED);
                    event.SetSessionType( reply.GetDebugSessionType() );
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeDebuggerExited: {
                    // notify debugger exited
                    LLDBEvent event(wxEVT_LLDB_EXITED);
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeDebuggerStopped: {
                    // notify debugger exited
                    LLDBEvent event(wxEVT_LLDB_STOPPED);
                    event.SetFileName( reply.GetFilename() );
                    event.SetLinenumber( reply.GetLine() );
                    event.SetInterruptReason( reply.GetInterruptResaon() );
                    event.SetBacktrace( reply.GetBacktrace() );
                    event.SetThreads( reply.GetThreads() );
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeDebuggerRunning: {
                    // notify debugger exited
                    LLDBEvent event(wxEVT_LLDB_RUNNING);
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeDebuggerStoppedOnFirstEntry: {
                    // notify debugger exited
                    LLDBEvent event(wxEVT_LLDB_STOPPED_ON_FIRST_ENTRY);
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeAllBreakpointsDeleted: {
                    LLDBEvent event(wxEVT_LLDB_BREAKPOINTS_DELETED_ALL);
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeBreakpointsUpdated: {
                    LLDBEvent event(wxEVT_LLDB_BREAKPOINTS_UPDATED);
                    event.SetBreakpoints( reply.GetBreakpoints() );
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeLocalsUpdated: {
                    LLDBEvent event(wxEVT_LLDB_LOCALS_UPDATED);
                    event.SetVariables( reply.GetVariables() );
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeVariableExpanded: {
                    LLDBEvent event(wxEVT_LLDB_VARIABLE_EXPANDED);
                    event.SetVariables( reply.GetVariables() );
                    event.SetVariableId( reply.GetLldbId() );
                    m_owner->AddPendingEvent( event );
                    break;
                }

                case kReplyTypeExprEvaluated: {
                    LLDBEvent event(wxEVT_LLDB_EXPRESSION_EVALUATED);
                    event.SetVariables( reply.GetVariables() );
                    event.SetExpression( reply.GetExpression() );
                    m_owner->AddPendingEvent( event );
                    break;
                }
                }
            }
        } catch (clSocketException &e) {
            CL_WARNING("Seems like we lost conneciton to codelite-lldb (probably crashed): %s", e.what().c_str());
            LLDBEvent event(wxEVT_LLDB_CRASHED);
            m_owner->AddPendingEvent( event );
            
            // exit the main loop
            break;
        }
    }
    return NULL;
}
Ejemplo n.º 12
0
PhpPlugin::PhpPlugin(IManager* manager)
    : IPlugin(manager)
    , m_clangOldFlag(false)
    , m_browser(NULL)
    , m_debuggerPane(NULL)
    , m_xdebugLocalsView(NULL)
    , m_xdebugEvalPane(NULL)
    , m_showWelcomePage(false)
{
    m_longName = wxT("PHP Plugin for the codelite IDE");
    m_shortName = wxT("PHP");

    // Instantiate the bitmaps, we do this so they will be populated in wxXmlResource
    // Sigleton class
    PHPImages images;
    PHPWorkspace::Get()->SetPluginManager(m_mgr);
    XDebugManager::Initialize(this);

    // Add our UI
    // create tab (possibly detached)
    Notebook* book = m_mgr->GetWorkspacePaneNotebook();
    if(IsWorkspaceViewDetached()) {
        // Make the window child of the main panel (which is the grand parent of the notebook)
        DockablePane* cp = new DockablePane(
            book->GetParent()->GetParent(), book, PHPStrings::PHP_WORKSPACE_VIEW_TITLE, wxNullBitmap, wxSize(200, 200));
        m_workspaceView = new PHPWorkspaceView(cp, m_mgr);
        cp->SetChildNoReparent(m_workspaceView);

    } else {
        m_workspaceView = new PHPWorkspaceView(book, m_mgr);
        book->InsertPage(0, m_workspaceView, PHPStrings::PHP_WORKSPACE_VIEW_TITLE, true);
    }

    PHPCodeCompletion::Instance()->SetManager(m_mgr);

    PHPEditorContextMenu::Instance()->ConnectEvents();
    PHPParserThread::Instance()->Start();

    // Pass the manager class to the context menu manager
    PHPEditorContextMenu::Instance()->SetManager(m_mgr);

    // Connect events
    EventNotifier::Get()->Connect(
        wxEVT_CC_SHOW_QUICK_OUTLINE, clCodeCompletionEventHandler(PhpPlugin::OnShowQuickOutline), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_DBG_UI_DELTE_ALL_BREAKPOINTS, clDebugEventHandler(PhpPlugin::OnXDebugDeleteAllBreakpoints), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_CREATE_NEW_WORKSPACE, wxCommandEventHandler(PhpPlugin::OnNewWorkspace), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_NEW_PROJECT_WIZARD_SHOWING, clNewProjectEventHandler(PhpPlugin::OnNewProject), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_NEW_PROJECT_WIZARD_FINISHED, clNewProjectEventHandler(PhpPlugin::OnNewProjectFinish), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_IS_WORKSPACE_OPEN, clCommandEventHandler(PhpPlugin::OnIsWorkspaceOpen), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_CLOSE_WORKSPACE, clCommandEventHandler(PhpPlugin::OnCloseWorkspace), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_OPEN_WORKSPACE, clCommandEventHandler(PhpPlugin::OnOpenWorkspace), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_RELOAD_WORKSPACE, clCommandEventHandler(PhpPlugin::OnReloadWorkspace), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_OPEN_RESOURCE, wxCommandEventHandler(PhpPlugin::OnOpenResource), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_GET_WORKSPACE_FILES, wxCommandEventHandler(PhpPlugin::OnGetWorkspaceFiles), NULL, this);
    EventNotifier::Get()->Connect(wxEVT_CMD_GET_CURRENT_FILE_PROJECT_FILES,
                                  wxCommandEventHandler(PhpPlugin::OnGetCurrentFileProjectFiles),
                                  NULL,
                                  this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_GET_ACTIVE_PROJECT_FILES, wxCommandEventHandler(PhpPlugin::OnGetActiveProjectFiles), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_GET_FIND_IN_FILES_MASK, clCommandEventHandler(PhpPlugin::OnGetFiFMask), NULL, this);
    EventNotifier::Get()->Connect(wxEVT_FILE_SAVED, clCommandEventHandler(PhpPlugin::OnFileSaved), NULL, this);
    EventNotifier::Get()->Connect(wxEVT_PHP_LOAD_URL, PHPEventHandler(PhpPlugin::OnLoadURL), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_ALL_EDITORS_CLOSED, wxCommandEventHandler(PhpPlugin::OnAllEditorsClosed), NULL, this);

    EventNotifier::Get()->Bind(wxEVT_XDEBUG_CONNECTED, &PhpPlugin::OnDebugSatrted, this);
    EventNotifier::Get()->Bind(wxEVT_XDEBUG_SESSION_ENDED, &PhpPlugin::OnDebugEnded, this);
    
    EventNotifier::Get()->Connect(wxEVT_GOING_DOWN, clCommandEventHandler(PhpPlugin::OnGoingDown), NULL, this);
    CallAfter(&PhpPlugin::DoCreateDebuggerPanes);

    // Extract all CC files from PHP.zip into the folder ~/.codelite/php-plugin/cc
    wxFileName phpResources(clStandardPaths::Get().GetDataDir(), "PHP.zip");
    if(phpResources.Exists()) {

        clZipReader zipReader(phpResources);
        wxFileName targetDir(clStandardPaths::Get().GetUserDataDir(), "");
        targetDir.AppendDir("php-plugin");

        // Don't extract the zip if one of the files on disk is newer or equal to the zip timestamp
        wxFileName fnSampleFile(targetDir.GetPath(), "basic.php");
        fnSampleFile.AppendDir("cc");
        if(!fnSampleFile.Exists() || // the sample file does not exists
                                     // Or the resource file (PHP.zip) is newer than the sample file
           (phpResources.GetModificationTime().GetTicks() > fnSampleFile.GetModificationTime().GetTicks())) {

            targetDir.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
            zipReader.Extract("*", targetDir.GetPath());

            // Make sure we add this path to the general PHP settings
            targetDir.AppendDir("cc"); // the CC files are located under an internal folder named "cc" (lowercase)
            PHPConfigurationData config;
            if(config.Load().GetCcIncludePath().Index(targetDir.GetPath()) == wxNOT_FOUND) {
                config.Load().GetCcIncludePath().Add(targetDir.GetPath());
                config.Save();
            }
        }
    } else {
        CL_WARNING("PHP: Could not locate PHP resources 'PHP.zip' => '%s'", phpResources.GetFullPath());
    }
}
Ejemplo n.º 13
0
void
CMake::StoreIntoDatabase()
{
    if (!m_dbInitialized) {
        CL_WARNING("CMake: can't store data into database. Database was not initialized properly");
        return;
    }

    try
    {
        /// Open database only for writing
        wxSQLite3Database db;

        // Open
        db.Open(GetDatabaseFileName().GetFullPath());

        // Not opened
        if (!db.IsOpen())
            return;

        db.Begin();

        // Commands
        {
            db.ExecuteUpdate("DELETE FROM commands");
            wxSQLite3Statement stmt = db.PrepareStatement("INSERT INTO commands (name, desc) VALUES(?, ?)");
            for (HelpMap::const_iterator it = m_commands.begin(), ite = m_commands.end(); it != ite; ++it) {
                stmt.Bind(1, it->first);
                stmt.Bind(2, it->second);
                stmt.ExecuteUpdate();
            }
        }

        // Modules
        {
            db.ExecuteUpdate("DELETE FROM modules");
            wxSQLite3Statement stmt = db.PrepareStatement("INSERT INTO modules (name, desc) VALUES(?, ?)");
            for (HelpMap::const_iterator it = m_modules.begin(), ite = m_modules.end(); it != ite; ++it) {
                stmt.Bind(1, it->first);
                stmt.Bind(2, it->second);
                stmt.ExecuteUpdate();
            }
        }

        // Properties
        {
            db.ExecuteUpdate("DELETE FROM properties");
            wxSQLite3Statement stmt = db.PrepareStatement("INSERT INTO properties (name, desc) VALUES(?, ?)");
            for (HelpMap::const_iterator it = m_properties.begin(), ite = m_properties.end(); it != ite; ++it) {
                stmt.Bind(1, it->first);
                stmt.Bind(2, it->second);
                stmt.ExecuteUpdate();
            }
        }

        // Variables
        {
            db.ExecuteUpdate("DELETE FROM variables");
            wxSQLite3Statement stmt = db.PrepareStatement("INSERT INTO variables (name, desc) VALUES(?, ?)");
            for (HelpMap::const_iterator it = m_variables.begin(), ite = m_variables.end(); it != ite; ++it) {
                stmt.Bind(1, it->first);
                stmt.Bind(2, it->second);
                stmt.ExecuteUpdate();
            }
        }

        // Strings - Version
        {
            wxSQLite3Statement stmt = db.PrepareStatement("REPLACE INTO strings (name, desc) VALUES('version', ?)");
            stmt.Bind(1, m_version);
            stmt.ExecuteUpdate();
        }

        db.Commit();

    } catch (wxSQLite3Exception &e) {
        CL_ERROR("An error occured while storing CMake data into database: %s", e.GetMessage());
    }
}
bool DebuggerMgr::LoadDebuggers()
{
    wxString ext;

#if defined(__WXMSW__)
    ext = wxT("dll");

#elif defined(__WXMAC__)
    ext = wxT("dylib");

#else
    ext = wxT("so");

#endif

    wxString fileSpec(wxT("*.") + ext);

    // get list of dlls
    wxArrayString files;
#ifdef __WXGTK__
    wxString debuggersPath(PLUGINS_DIR, wxConvUTF8);
    debuggersPath += wxT("/debuggers");
#elif defined(__WXMSW__)
#ifdef USE_POSIX_LAYOUT
    wxString debuggersPath(clStandardPaths::Get().GetPluginsDirectory() + wxT("/debuggers"));
#else
    wxString debuggersPath(m_baseDir + wxT("/debuggers"));
#endif
#else
    // OSX
    wxFileName debuggersFolder(clStandardPaths::Get().GetDataDir(), "");
    debuggersFolder.AppendDir("debuggers");
    wxString debuggersPath(debuggersFolder.GetPath());
#endif

    CL_DEBUG("Loading debuggers from: %s", debuggersPath);
    wxDir::GetAllFiles(debuggersPath, &files, fileSpec, wxDIR_FILES);

    for(size_t i = 0; i < files.GetCount(); i++) {
        clDynamicLibrary* dl = new clDynamicLibrary();
        wxString fileName(files.Item(i));
        CL_DEBUG("Attempting to load debugger: %s", fileName);
#if defined(__WXMSW__) && !defined(NDEBUG)
        // Under MSW loading a release plugin while in debug mode will cause a crash
        if(!fileName.EndsWith("-dbg.dll")) {
            continue;
        }
#elif defined(__WXMSW__)

        // filter debug plugins
        if(fileName.EndsWith("-dbg.dll")) {
            continue;
        }
#endif
        if(!dl->Load(fileName)) {
            CL_WARNING("Failed to load debugger: %s", fileName);
            if(!dl->GetError().IsEmpty()) {
                CL_WARNING("%s", dl->GetError());
            }
            delete dl;
            continue;
        }

        bool success(false);
        GET_DBG_INFO_FUNC pfn = (GET_DBG_INFO_FUNC)dl->GetSymbol(wxT("GetDebuggerInfo"), &success);
        if(!success) {
            wxLogMessage(wxT("Failed to find GetDebuggerInfo() in dll: ") + fileName);
            if(!dl->GetError().IsEmpty()) {
                wxLogMessage(dl->GetError());
            }
            // dl->Unload();
            delete dl;
            continue;
        }

        DebuggerInfo info = pfn();
        // Call the init method to create an instance of the debugger
        success = false;
        GET_DBG_CREATE_FUNC pfnInitDbg = (GET_DBG_CREATE_FUNC)dl->GetSymbol(info.initFuncName, &success);
        if(!success) {
            wxLogMessage(wxT("Failed to find init function in dll: ") + fileName);
            if(!dl->GetError().IsEmpty()) {
                wxLogMessage(dl->GetError());
            }
            dl->Detach();
            delete dl;
            continue;
        }

        wxLogMessage(wxT("Loaded debugger: ") + info.name + wxT(", Version: ") + info.version);
        IDebugger* dbg = pfnInitDbg();

        // set the environment
        dbg->SetEnvironment(m_env);

        m_debuggers[info.name] = dbg;

        // keep the dynamic load library
        m_dl.push_back(dl);
    }

    // Load all debuggers in the form of plugin (i.e. they dont implement the IDebugger interface)
    // and append them to a special list
    clDebugEvent queryPlugins(wxEVT_DBG_IS_PLUGIN_DEBUGGER);
    EventNotifier::Get()->ProcessEvent(queryPlugins);
    m_pluginsDebuggers.swap(queryPlugins.GetStrings());
    return true;
}
Ejemplo n.º 15
0
PhpPlugin::PhpPlugin(IManager* manager)
    : IPlugin(manager)
    , m_clangOldFlag(false)
    , m_browser(NULL)
    , m_debuggerPane(NULL)
    , m_xdebugLocalsView(NULL)
    , m_xdebugEvalPane(NULL)
    , m_showWelcomePage(false)
    , m_toggleToolbar(false)
{
    m_lint.Reset(new PHPLint(this));

    // Add new workspace type
    clWorkspaceManager::Get().RegisterWorkspace(new PHPWorkspace());

    m_longName = _("PHP Plugin for the codelite IDE");
    m_shortName = wxT("PHP");

    // Instantiate the bitmaps, we do this so they will be populated in wxXmlResource
    // Sigleton class
    PHPWorkspace::Get()->SetPluginManager(m_mgr);
    XDebugManager::Initialize(this);

    // BitmapLoader::RegisterImage(FileExtManager::TypeWorkspacePHP, images.Bitmap("m_bmpPhpWorkspace"));

    // Add our UI
    // create tab (possibly detached)
    m_workspaceView = new PHPWorkspaceView(m_mgr->GetWorkspaceView()->GetBook(), m_mgr);
    m_mgr->GetWorkspaceView()->AddPage(m_workspaceView, PHPStrings::PHP_WORKSPACE_VIEW_LABEL);

    PHPCodeCompletion::Instance()->SetManager(m_mgr);
    PHPEditorContextMenu::Instance()->ConnectEvents();
    PHPParserThread::Instance()->Start();

    // Pass the manager class to the context menu manager
    PHPEditorContextMenu::Instance()->SetManager(m_mgr);

    // Connect events
    EventNotifier::Get()->Connect(
        wxEVT_CC_SHOW_QUICK_OUTLINE, clCodeCompletionEventHandler(PhpPlugin::OnShowQuickOutline), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_DBG_UI_DELTE_ALL_BREAKPOINTS, clDebugEventHandler(PhpPlugin::OnXDebugDeleteAllBreakpoints), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_CREATE_NEW_WORKSPACE, clCommandEventHandler(PhpPlugin::OnNewWorkspace), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_NEW_PROJECT_WIZARD_SHOWING, clNewProjectEventHandler(PhpPlugin::OnNewProject), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_NEW_PROJECT_WIZARD_FINISHED, clNewProjectEventHandler(PhpPlugin::OnNewProjectFinish), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_IS_WORKSPACE_OPEN, clCommandEventHandler(PhpPlugin::OnIsWorkspaceOpen), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_CLOSE_WORKSPACE, clCommandEventHandler(PhpPlugin::OnCloseWorkspace), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_OPEN_WORKSPACE, clCommandEventHandler(PhpPlugin::OnOpenWorkspace), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_RELOAD_WORKSPACE, clCommandEventHandler(PhpPlugin::OnReloadWorkspace), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_OPEN_RESOURCE, wxCommandEventHandler(PhpPlugin::OnOpenResource), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_GET_WORKSPACE_FILES, wxCommandEventHandler(PhpPlugin::OnGetWorkspaceFiles), NULL, this);
    EventNotifier::Get()->Connect(wxEVT_CMD_GET_CURRENT_FILE_PROJECT_FILES,
                                  wxCommandEventHandler(PhpPlugin::OnGetCurrentFileProjectFiles),
                                  NULL,
                                  this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_GET_ACTIVE_PROJECT_FILES, wxCommandEventHandler(PhpPlugin::OnGetActiveProjectFiles), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_CMD_FIND_IN_FILES_DISMISSED, clCommandEventHandler(PhpPlugin::OnFindInFilesDismissed), NULL, this);

    EventNotifier::Get()->Connect(wxEVT_FILE_SAVED, clCommandEventHandler(PhpPlugin::OnFileSaved), NULL, this);
    EventNotifier::Get()->Bind(wxEVT_FILES_MODIFIED_REPLACE_IN_FILES, &PhpPlugin::OnReplaceInFiles, this);
    EventNotifier::Get()->Connect(wxEVT_PHP_LOAD_URL, PHPEventHandler(PhpPlugin::OnLoadURL), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_ALL_EDITORS_CLOSED, wxCommandEventHandler(PhpPlugin::OnAllEditorsClosed), NULL, this);

    EventNotifier::Get()->Bind(wxEVT_XDEBUG_SESSION_STARTED, &PhpPlugin::OnDebugStarted, this);
    EventNotifier::Get()->Bind(wxEVT_XDEBUG_SESSION_ENDED, &PhpPlugin::OnDebugEnded, this);

    EventNotifier::Get()->Connect(wxEVT_GOING_DOWN, clCommandEventHandler(PhpPlugin::OnGoingDown), NULL, this);
    EventNotifier::Get()->Bind(wxEVT_FILE_SYSTEM_UPDATED, &PhpPlugin::OnFileSysetmUpdated, this);
    EventNotifier::Get()->Bind(wxEVT_SAVE_SESSION_NEEDED, &PhpPlugin::OnSaveSession, this);
    CallAfter(&PhpPlugin::FinalizeStartup);

    // Extract all CC files from PHP.zip into the folder ~/.codelite/php-plugin/cc
    wxFileName phpResources(clStandardPaths::Get().GetDataDir(), "PHP.zip");
    if(phpResources.Exists()) {

        clZipReader zipReader(phpResources);
        wxFileName targetDir(clStandardPaths::Get().GetUserDataDir(), "");
        targetDir.AppendDir("php-plugin");

        // Don't extract the zip if one of the files on disk is newer or equal to the zip timestamp
        wxFileName fnSampleFile(targetDir.GetPath(), "basic.php");
        fnSampleFile.AppendDir("cc");
        PHPConfigurationData config;
        if(!fnSampleFile.Exists() || // the sample file does not exists
                                     // Or the resource file (PHP.zip) is newer than the sample file
           (phpResources.GetModificationTime().GetTicks() > fnSampleFile.GetModificationTime().GetTicks())) {

            targetDir.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
            zipReader.Extract("*", targetDir.GetPath());

            // Make sure we add this path to the general PHP settings
            targetDir.AppendDir("cc"); // the CC files are located under an internal folder named "cc" (lowercase)

            if(config.Load().GetCcIncludePath().Index(targetDir.GetPath()) == wxNOT_FOUND) {
                config.Load().GetCcIncludePath().Add(targetDir.GetPath());
                config.Save();
            }
        } else if(fnSampleFile.Exists()) {
            // Ensure that we have the core PHP code completion methods
            if(config.Load().GetCcIncludePath().Index(fnSampleFile.GetPath()) == wxNOT_FOUND) {
                config.Load().GetCcIncludePath().Add(fnSampleFile.GetPath());
                config.Save();
            }
        }
    } else {
        CL_WARNING("PHP: Could not locate PHP resources 'PHP.zip' => '%s'", phpResources.GetFullPath());
    }
}