Exemple #1
0
/*!
    \brief Program the microcontroller.

    This function is called outside of debug context. It launches OpenOCD for the sole
    purpose of programming the target. A TCL progflash() routine inside the OpenOCD config
    file must exist, and this routine is executed via the TCL/telnet interface.

    \return Return value from Launch()
*/
int OpenOCDDriver::Program(void)
{
    int ret;

    ClearLog();
    CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_pLog);
    Manager::Get()->ProcessEvent(evtSwitch);

    Log(_T("Launching process..."));

    // Launch the process
    m_FirstErr = false;    // We want dialog box back
    ret = Launch();
    if (ret == 0) {

        // Let system know we are in programming state.
        m_rs = Programming;

        // Execute tcl script to program flash.
        Log(_T("Programming..."));
        m_ocdint->Program();

    }

    return ret;
}
Exemple #2
0
void CppCheck::AppendToLog(const wxString& Text)
{
    if (LogManager* LogMan = Manager::Get()->GetLogManager())
    {
        CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_CppCheckLog);
        Manager::Get()->ProcessEvent(evtSwitch);
        LogMan->Log(Text, m_LogPageIndex);
    }
}
Exemple #3
0
void CppCheck::DoCppCheckAnalysis(const wxString& Xml)
{
    // clear the list
    m_ListLog->Clear();

    TiXmlDocument Doc;
    Doc.Parse( Xml.ToAscii() );
    if ( Doc.Error() )
    {
        wxString msg = _("Failed to parse cppcheck XML file.\nProbably it's not produced correctly.");
        AppendToLog(msg);
        cbMessageBox(msg, _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
    }
    else
    {
        TiXmlHandle Handle(&Doc);
        Handle = Handle.FirstChildElement("results");

        bool ErrorsPresent = false;
        TiXmlElement* resultNode = Handle.ToElement();
        if (nullptr!=resultNode->Attribute("version"))
        {
            wxString Version = wxString::FromAscii(resultNode->Attribute("version"));
            if ( Version.IsSameAs(wxT("2")) )
                ErrorsPresent = DoCppCheckParseXMLv2(Handle);
            else
            {
                cbMessageBox(_("Unsupported XML file version of CppCheck."),
                             _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
            }
        }
        else
        {
            ErrorsPresent = DoCppCheckParseXMLv1(Handle);
        }

        if (ErrorsPresent)
        {
            if ( Manager::Get()->GetLogManager() )
            {
                CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_ListLog);
                Manager::Get()->ProcessEvent(evtSwitch);
            }
        }

        if ( !Doc.SaveFile("CppCheckResults.xml") )
        {
            cbMessageBox(_("Failed to create output file 'CppCheckResults.xml' for cppcheck.\nPlease check file/folder access rights."),
                         _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
        }
    }
}
Exemple #4
0
void Valgrind::AppendToLog(const wxString& Text)
{
    if(LogManager* LogMan = Manager::Get()->GetLogManager())
    {
		CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_ValgrindLog);
		Manager::Get()->ProcessEvent(evtSwitch);
	// maybe also show event needed ??
#if 0
CodeBlocksLogEvent evtShow(cbEVT_SHOW_LOG_MANAGER);
Manager::Get()->ProcessEvent(evtShow);
#endif
    	LogMan->Log(Text, m_LogPageIndex);
    }
} // end of AppendToLog
void CodeRefactoring::DoFindReferences()
{
    cbEditor* editor = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
    if (!editor)
        return;

    cbSearchResultsLog* searchLog = Manager::Get()->GetSearchResultLogger();
    if (!searchLog)
        return;

    const wxString focusFile = editor->GetFilename();
    const int focusLine = editor->GetControl()->GetCurrentLine() + 1;
    wxFileName fn(focusFile);
    const wxString basePath(fn.GetPath());
    size_t index = 0;
    size_t focusIndex = 0;

    searchLog->Clear();
    searchLog->SetBasePath(basePath);

    for (SearchDataMap::iterator it = m_SearchDataMap.begin(); it != m_SearchDataMap.end(); ++it)
    {
        for (SearchDataList::iterator itList = it->second.begin(); itList != it->second.end(); ++itList)
        {
            if (it->first == focusFile && itList->line == focusLine)
                focusIndex = index;

            wxArrayString values;
            wxFileName curFn(it->first);
            curFn.MakeRelativeTo(basePath);
            values.Add(curFn.GetFullPath());
            values.Add(wxString::Format(_T("%d"), itList->line));
            values.Add(itList->text);
            searchLog->Append(values, Logger::info);

            ++index;
        }
    }

    if (Manager::Get()->GetConfigManager(_T("message_manager"))->ReadBool(_T("/auto_show_search"), true))
    {
        CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, searchLog);
        CodeBlocksLogEvent evtShow(cbEVT_SHOW_LOG_MANAGER);
        Manager::Get()->ProcessEvent(evtSwitch);
        Manager::Get()->ProcessEvent(evtShow);
    }

    searchLog->FocusEntry(focusIndex);
}
Exemple #6
0
void CppCheck::DoVeraAnalysis(const wxArrayString& Result)
{
  wxRegEx reVera(_T("(.+):([0-9]+):(.+)"));

  bool ErrorsPresent = false;

  for (size_t idxCount = 0; idxCount < Result.GetCount(); ++idxCount)
  {
    wxString Res = Result[idxCount];
    if (reVera.Matches(Res))
    {
      wxString File = reVera.GetMatch(Res, 1);
      wxString Line = reVera.GetMatch(Res, 2);
      wxString Msg  = reVera.GetMatch(Res, 3);

      if (!File.IsEmpty() && !Line.IsEmpty() && !Msg.IsEmpty())
      {
          wxArrayString Arr;
          Arr.Add(File);
          Arr.Add(Line);
          Arr.Add(Msg);
          m_ListLog->Append(Arr);
          ErrorsPresent = true;
      }
      else if (!Msg.IsEmpty())
          AppendToLog(Msg); // might be something important like config not found...
    }
  }

  if (ErrorsPresent)
  {
      if ( Manager::Get()->GetLogManager() )
      {
          CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_ListLog);
          Manager::Get()->ProcessEvent(evtSwitch);
      }
  }
}
Exemple #7
0
void Valgrind::OnMemCheck(wxCommandEvent& )
{
	wxString ExeTarget;
	wxString CommandLineArguments;
	if(!CheckRequirements(ExeTarget, CommandLineArguments))
	{
		return;
	}
	long Version = DoValgrindVersion();
	const wxString XmlOutputFile = _T("ValgrindOut.xml");
	wxString XmlOutputCommand;
	if(Version >= 350)
	{
		XmlOutputCommand = _T(" --xml-file=") + XmlOutputFile;
	}
	const bool UseXml = true;
	wxString CommandLine = _T("valgrind --leak-check=yes --xml=yes") + XmlOutputCommand + _T(" \"")
		+ ExeTarget + _T("\" ") + CommandLineArguments;
//	CommandLine = _("valgrind --leak-check=yes \"") + ExeTarget + _("\" ") + CommandLineArguments;
	AppendToLog(CommandLine);
	wxArrayString Output, Errors;
	wxExecute(CommandLine, Output, Errors);
	size_t Count = Output.GetCount();
	for(size_t idxCount = 0; idxCount < Count; ++idxCount)
	{
		// EXTRA NOTE : it seems the output from valgrind comes on the error channel, not here !!!
		// it seems that all valgrind stuff starts with == (in case of not xml)
		// filter on that, so we can remove regular output from the tested exe
//		if(Output[idxCount].StartsWith(_("==")))
		{
			AppendToLog(Output[idxCount]);
		}
	} // end for : idx: idxCount
	wxString Xml;
	Count = Errors.GetCount();
	for(size_t idxCount = 0; idxCount < Count; ++idxCount)
	{
		Xml += Errors[idxCount];
		AppendToLog(Errors[idxCount]);
	} // end for : idx: idxCount
	if(UseXml)
	{
		TiXmlDocument Doc;
		if(Version >= 350)
		{
			Doc.LoadFile(XmlOutputFile.ToAscii());
		}
		else
		{
			Doc.Parse(Xml.ToAscii());
		}
		if(!Doc.Error())
		{
			bool ErrorsPresent = false;
			TiXmlHandle Handle(&Doc);
			Handle = Handle.FirstChildElement("valgrindoutput");
			for(const TiXmlElement* Error = Handle.FirstChildElement("error").ToElement(); Error;
					Error = Error->NextSiblingElement("error"))
			{
				ErrorsPresent = true;
				wxString WhatValue;
				if(const TiXmlElement* What = Error->FirstChildElement("xwhat"))
				{	// style use since Valgrind 3.5.0
					if(const TiXmlElement* Text = What->FirstChildElement("text"))
					{
						WhatValue = wxString::FromAscii(Text->GetText());
					}
				}
				else if(const TiXmlElement* What = Error->FirstChildElement("what"))
				{
					WhatValue = wxString::FromAscii(What->GetText());
				}
				// process the first stack
				if(const TiXmlElement* Stack = Error->FirstChildElement("stack"))
				{
					ProcessStack(*Stack, WhatValue);
				}
			} // end for
			if(ErrorsPresent)
			{
				if(Manager::Get()->GetLogManager())
				{
					CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_ListLog);
					Manager::Get()->ProcessEvent(evtSwitch);
				}
			}
		}
		// loop over the errors
	}
} // end of OnMemCheck
Exemple #8
0
void CppCheck::DoCppCheckAnalysis(const wxString& Xml)
{
    // clear the list
    m_ListLog->Clear();

    TiXmlDocument Doc;
    Doc.Parse( Xml.ToAscii() );
    if ( Doc.Error() )
    {
        wxString msg = _("Failed to parse cppcheck XML file.\nProbably it's not produced correctly.");
        AppendToLog(msg);
        cbMessageBox(msg, _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
    }
    else
    {
        bool ErrorsPresent = false;
        TiXmlHandle Handle(&Doc);
        Handle = Handle.FirstChildElement("results");
        for (const TiXmlElement* Error = Handle.FirstChildElement("error").ToElement(); Error;
                Error = Error->NextSiblingElement("error"))
        {
            wxString File;
            if (const char* FileValue = Error->Attribute("file"))
                File = wxString::FromAscii(FileValue);
            wxString Line;
            if (const char* LineValue = Error->Attribute("line"))
                Line = wxString::FromAscii(LineValue);
            wxString Id;
            if (const char* IdValue = Error->Attribute("id"))
                Id = wxString::FromAscii(IdValue);
            wxString Severity;
            if (const char* SeverityValue = Error->Attribute("severity"))
                Severity = wxString::FromAscii(SeverityValue);
            wxString Message;
            if (const char* MessageValue = Error->Attribute("msg"))
                Message = wxString::FromAscii(MessageValue);
            const wxString FullMessage = Id + _T(" : ") + Severity + _T(" : ") + Message;
            if (!File.IsEmpty() && !Line.IsEmpty() && !FullMessage.IsEmpty())
            {
                wxArrayString Arr;
                Arr.Add(File);
                Arr.Add(Line);
                Arr.Add(FullMessage);
                m_ListLog->Append(Arr);
                ErrorsPresent = true;
            }
            else if (!Message.IsEmpty())
                AppendToLog(Message); // might be something important like config not found...
        }
        if (ErrorsPresent)
        {
            if ( Manager::Get()->GetLogManager() )
            {
                CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_ListLog);
                Manager::Get()->ProcessEvent(evtSwitch);
            }
        }

        if ( !Doc.SaveFile("CppCheckResults.xml") )
        {
            cbMessageBox(_("Failed to create output file 'CppCheckResults.xml' for cppcheck.\nPlease check file/folder access rights."),
                         _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
        }
    }
}
void Valgrind::ParseMemCheckXML(TiXmlDocument &Doc)
{
    if (Doc.Error())
        return;
    m_ListLog->Clear();

    wxArrayString Arr;
    int Errors = 0;
    TiXmlHandle Handle(&Doc);
    Handle = Handle.FirstChildElement("valgrindoutput");
    for (const TiXmlElement* Error = Handle.FirstChildElement("error").ToElement(); Error;
            Error = Error->NextSiblingElement("error"), Errors++)
    {
        wxString WhatValue, KindValue;
        if (const TiXmlElement* XWhat = Error->FirstChildElement("xwhat"))
        {	// style use since Valgrind 3.5.0
            if (const TiXmlElement* Text = XWhat->FirstChildElement("text"))
            {
                WhatValue = wxString::FromAscii(Text->GetText());
            }
        }
        else if (const TiXmlElement* What = Error->FirstChildElement("what"))
        {
            WhatValue = wxString::FromAscii(What->GetText());
        }
        if (const TiXmlElement *Kind = Error->FirstChildElement("kind"))
            KindValue = wxString::FromAscii(Kind->GetText());

        Arr.Clear();
        Arr.Add(KindValue);
        Arr.Add(wxT("===="));
        Arr.Add(WhatValue);
        m_ListLog->Append(Arr, Logger::error);

        // process the first stack
        const TiXmlElement* Stack = Error->FirstChildElement("stack");
        if (Stack)
        {
            ProcessStack(*Stack, true);
            if (const TiXmlElement *AuxWhat = Error->FirstChildElement("auxwhat"))
            {
                Arr.Clear();
                Arr.Add(wxEmptyString);
                Arr.Add(wxEmptyString);
                Arr.Add(wxString::FromAscii(AuxWhat->GetText()));
                m_ListLog->Append(Arr, Logger::warning);
            }
            Stack = Stack->NextSiblingElement("stack");
            if (Stack)
                ProcessStack(*Stack, false);
        }

    } // end for
    if (Errors > 0)
    {
        Arr.Clear();
        Arr.Add(wxEmptyString);
        Arr.Add(wxEmptyString);
        Arr.Add(wxString::Format(_("Valgrind found %d errors!"), Errors));
        m_ListLog->Append(Arr, Logger::error);

        if (Manager::Get()->GetLogManager())
        {
            CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_ListLog);
            Manager::Get()->ProcessEvent(evtSwitch);
        }
        m_ListLog->Fit();
    }
}
bool ToolsManager::Execute(const cbTool* tool)
{
    if (m_pProcess)
    {
        cbMessageBox(_("Another tool is currently executing.\n"
                        "Please allow for it to finish before launching another tool..."),
                        _("Error"), wxICON_ERROR);
        return false;
    }

    if (!tool)
        return false;

    wxString cmdline;
    wxString cmd = tool->GetCommand();
    wxString params = tool->GetParams();
    wxString dir = tool->GetWorkingDir();

    // hack to force-update macros
    Manager::Get()->GetMacrosManager()->RecalcVars(0, 0, 0);

    Manager::Get()->GetMacrosManager()->ReplaceMacros(cmd);
    Manager::Get()->GetMacrosManager()->ReplaceMacros(params);
    Manager::Get()->GetMacrosManager()->ReplaceMacros(dir);

    if (tool->GetLaunchOption() == cbTool::LAUNCH_NEW_CONSOLE_WINDOW)
    {
#ifndef __WXMSW__
        // for non-win platforms, use m_ConsoleTerm to run the console app
        wxString term = Manager::Get()->GetConfigManager(_T("app"))->Read(_T("/console_terminal"), DEFAULT_CONSOLE_TERM);
        term.Replace(_T("$TITLE"), _T("'") + tool->GetName() + _T("'"));
        cmdline << term << _T(" ");
        #define CONSOLE_RUNNER "cb_console_runner"
#else
        #define CONSOLE_RUNNER "cb_console_runner.exe"
#endif
        wxString baseDir = ConfigManager::GetExecutableFolder();
        if (wxFileExists(baseDir + wxT("/" CONSOLE_RUNNER)))
            cmdline << baseDir << wxT("/" CONSOLE_RUNNER " ");
    }

    if (!cmdline.Replace(_T("$SCRIPT"), cmd << _T(" ") << params))
        // if they didn't specify $SCRIPT, append:
        cmdline << cmd;

    if(!(Manager::Get()->GetMacrosManager()))
        return false; // We cannot afford the Macros Manager to fail here!
                      // What if it failed already?
    wxSetWorkingDirectory(dir);

    // log info so user can troubleshoot
    dir = wxGetCwd(); // read in the actual working dir
    #if wxCHECK_VERSION(2, 9, 0)
    Manager::Get()->GetLogManager()->Log(F(_("Launching tool '%s': %s (in %s)"), tool->GetName().wx_str(), cmdline.wx_str(), dir.wx_str()));
    #else
    Manager::Get()->GetLogManager()->Log(F(_("Launching tool '%s': %s (in %s)"), tool->GetName().c_str(), cmdline.c_str(), dir.c_str()));
    #endif

    bool pipe = true;
    int flags = wxEXEC_ASYNC;

    switch (tool->GetLaunchOption())
    {
        case cbTool::LAUNCH_NEW_CONSOLE_WINDOW:
            pipe = false; // no need to pipe output channels...
            break;

        case cbTool::LAUNCH_HIDDEN:
            break; // use the default values of pipe and flags...

        case cbTool::LAUNCH_VISIBLE:
        case cbTool::LAUNCH_VISIBLE_DETACHED:
            flags |= wxEXEC_NOHIDE;
            pipe = false;
            break;
    }

    if (tool->GetLaunchOption() == cbTool::LAUNCH_VISIBLE_DETACHED)
    {
        int pid = wxExecute(cmdline, flags);

        if (!pid)
        {
            cbMessageBox(_("Couldn't execute tool. Check the log for details."), _("Error"), wxICON_ERROR);
            return false;
        }
        else
        {
            CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, LogManager::app_log);
            Manager::Get()->ProcessEvent(evtSwitch);        // switch to default log
         }
    }
    else
    {
        m_pProcess = new PipedProcess((void**)&m_pProcess, this, idToolProcess, pipe, dir);
        m_Pid = wxExecute(cmdline, flags, m_pProcess);

        if (!m_Pid)
        {
            cbMessageBox(_("Couldn't execute tool. Check the log for details."), _("Error"), wxICON_ERROR);
            delete m_pProcess;
            m_pProcess = 0;
            m_Pid = 0;
            return false;
        }
        else
        {
            CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, LogManager::app_log);
            Manager::Get()->ProcessEvent(evtSwitch);        // switch to default log
        }
    }

    return true;
} // end of Execute