48 #include <sys/types.h> 55 SetEvtHandlerEnabled(
false);
70 window->PushEventHandler(
this);
74 SetEvtHandlerEnabled(
true);
77 event.SetPlugin(
this);
87 SetEvtHandlerEnabled(
false);
91 event.SetPlugin(
this);
105 window->RemoveEventHandler(
this);
129 m_WaitingCompilerToFinish(false),
130 m_StartType(StartTypeUnknown),
133 m_lastLineWasNormal(true),
135 m_settingsName(settingsName)
189 selected_text.
Trim(
true);
190 selected_text.
Trim(
false);
195 selected_text.
Remove(pos, selected_text.
length() - pos);
196 selected_text.
Trim(
true);
197 selected_text.
Trim(
false);
207 else if (startPos <= mousePos && mousePos <= endPos)
208 return selected_text;
213 return selected_text;
229 return selected_text;
241 if (active_plugin !=
this)
270 DebuggerManager::RegisteredPlugins::iterator it = allPlugins.find(
this);
271 if (it == allPlugins.end())
275 return *it->second.GetConfigurations().front();
363 for (
int ii = 0; ii < count; ++ii)
365 const cb::shared_ptr<cbBreakpoint> &b = plugin.
GetBreakpoint(ii);
367 if (b->GetLocation() == filename && b->GetLine() == line)
377 if (!editor || lines == 0)
382 std::vector<int> breakpoints_for_file;
384 for (
int ii = 0; ii < count; ++ii)
388 if (b->GetLocation() == filename)
390 breakpoints_for_file.push_back(ii);
399 int endline = startline + lines - 1;
401 std::vector<cb::shared_ptr<cbBreakpoint> > to_remove;
403 for (std::vector<int>::iterator it = breakpoints_for_file.begin(); it != breakpoints_for_file.end(); ++it)
406 if (b->GetLine() > endline)
408 else if (b->GetLine() >= startline && b->GetLine() <= endline)
409 to_remove.push_back(b);
412 for (std::vector<cb::shared_ptr<cbBreakpoint> >::iterator it = to_remove.begin(); it != to_remove.end(); ++it)
417 for (std::vector<int>::iterator it = breakpoints_for_file.begin(); it != breakpoints_for_file.end(); ++it)
420 if (b->GetLine() > startline)
461 if(
this !=
Manager::Get()->GetDebuggerManager()->GetActiveDebugger())
471 wxString msg =
_(
"You can't change the active project while you 're actively debugging another.\n" 472 "Do you want to stop debugging?\n\n" 473 "Click \"Yes\" to stop debugging now or click \"No\" to re-activate the debuggee.");
490 if(
this !=
Manager::Get()->GetDebuggerManager()->GetActiveDebugger())
502 _(
"The project you were debugging has closed.\n" 503 "(The application most likely just finished.)\n" 504 "The debugging session will terminate immediately."),
583 perspectiveName =
_(
"Debugging");
629 Log(
_(
"Adding file: ") + out);
639 cbMessageBox(
_(
"You must select a host application to \"run\" a library..."));
644 Log(
_(
"Adding file: ") + out);
650 Log(
_(
"Unsupported target type (Project -> Properties -> Build Targets -> Type)"),
Logger::error);
666 pathToDebuggee = out;
688 if (compilers.empty())
697 Log(
_(
"Compiler in use..."));
698 Log(
_(
"Aborting debugging session"));
699 cbMessageBox(
_(
"The compiler is currently in use. Aborting debugging session..."),
704 Log(
_(
"Building to ensure sources are up-to-date"));
718 bool compilerFailed =
false;
722 AnnoyingDialog dlg(
_(
"Debug anyway?"),
_(
"Build failed, do you want to debug the program?"),
729 compilerFailed =
true;
754 bool IsValid()
const {
return !ttyPath.empty() && sleepPID > 0; }
760 ConsoleInfo GetConsoleTty(
int consolePID)
768 return ConsoleInfo();
771 const wxString &uniqueSleepTimeStr = MakeSleepCommand();
775 for (
int i = count - 1; i > -1; --i)
790 if (psCmd.
Contains(uniqueSleepTimeStr))
799 if (pidForLine != consolePID)
800 return ConsoleInfo(
wxT(
"/dev/") + psCmd.
BeforeFirst(
' '), pidForLine);
804 return ConsoleInfo();
807 struct ConsoleProcessTerminationInfo
809 ConsoleProcessTerminationInfo() : status(-1), terminated(
false) {}
811 bool FailedToStart()
const {
return terminated && status != 0; }
819 ConsoleProcess(cb::shared_ptr<ConsoleProcessTerminationInfo> cptInfo) : info(cptInfo) {}
820 void OnTerminate(
int pid,
int status)
override 822 info->terminated =
true;
823 info->status = status;
825 cb::shared_ptr<ConsoleProcessTerminationInfo> info;
845 cmd << term <<
_T(
" ");
847 const wxString &sleepCommand = MakeSleepCommand();
854 cb::shared_ptr<ConsoleProcessTerminationInfo> processInfo(
new ConsoleProcessTerminationInfo);
855 ConsoleProcess *process =
new ConsoleProcess(processInfo);
862 for (
int ii = 0; ii < 100; ++ii)
869 if (processInfo->FailedToStart() )
871 Log(
F(
wxT(
"Failed to execute terminal command: '%s' (exit code: %d)"),
877 const ConsoleInfo &info = GetConsoleTty(consolePid);
888 if (kill(consolePid, 0) == -1 && errno == ESRCH) {
889 DebugLog(
F(
wxT(
"Using sleep command's PID as console PID %d, TTY %s"),
890 info.sleepPID, info.ttyPath.wx_str()));
891 consoleTty = info.ttyPath;
892 return info.sleepPID;
896 DebugLog(
F(
wxT(
"Using terminal's PID as console PID %d, TTY %s"), info.sleepPID, info.ttyPath.wx_str()));
897 consoleTty = info.ttyPath;
904 #endif // !__WWXMSW__ 947 if (
Manager::Get()->GetDebuggerManager()->GetInterfaceFactory()->IsValueTooltipShown())
1016 DoAutocomplete(
CCToken(-1, token), ed);
1021 return (
Manager::Get()->GetCCManager()->GetProviderFor(ed) ==
this);
1105 if ( position == -1 )
1112 bool foundlf =
false;
1123 else if (c ==
_T(
'\r') && !foundlf)
1128 if (count > 1)
return str;
1129 if (!inComment && c !=
_T(
' ') && c !=
_T(
'\t') && c !=
_T(
'\n') && c !=
_T(
'\r') )
1132 for (
unsigned int i = 1; i < NumberOfWords ; ++i )
1144 return GetLastNonWhitespaceChars(ed, position, 1)[0];
1157 bool foundlf =
false;
1168 else if (c ==
_T(
'\r') && !foundlf)
1173 if (!inComment && c !=
_T(
' ') && c !=
_T(
'\t') && c !=
_T(
'\n') && c !=
_T(
'\r'))
1174 return stc->
GetTextRange(position-NumberOfChars+1, position+1);
1184 while (position < stc->GetLength())
1187 if ( c ==
_T(
'\n') || c ==
_T(
'\r') )
1189 if ( pos ) *pos = position;
1192 if ( c !=
_T(
' ') && c !=
_T(
'\t') )
1194 if ( pos ) *pos = position;
1211 else if (b == blockStart)
1230 if ( CaseSensitive )
1235 pb = stc->
FindText(pos, 0, blockStart, flags);
1236 pe = stc->
FindText(pos, 0, blockEnd, flags);
1244 if ( lvl == 0 )
return pb;
1256 int position = curr_position;
1257 int min_brace_position = position;
1258 int closing_braces = 0;
1259 bool found_brace =
false;
1260 bool has_braces =
false;
1267 if (style == string_style)
1272 found_brace =
false;
1275 else if (c ==
_T(
')'))
1280 else if (c ==
_T(
'('))
1283 if (closing_braces > 0)
1285 else if (!found_brace)
1287 min_brace_position = position + 1;
1292 else if (c ==
_T(
'\n') && position + 1 != curr_position && !has_braces)
1301 int tab_characters = 0;
1306 if (c ==
_T(
'\n') && position + 1 != curr_position)
1310 else if (c ==
_T(
'\t'))
1318 return min_brace_position - position - 1;
1326 while (position < stc->GetLength())
1329 if ( c ==
_T(
'\n') || c ==
_T(
'\r') )
1331 if ( pos ) *pos = position;
1334 if ( c !=
_T(
' ') && c !=
_T(
'\t') )
1336 if ( pos ) *pos = position;
void Attach()
Attach is not a virtual function, so you can't override it.
ProjectFile * GetFileByFilename(const wxString &filename, bool isRelative=true, bool isUnixFilename=false)
Access a file of the project.
int wxKill(long pid, wxSignal sig=wxSIGTERM, wxKillError *rc=NULL, int flags=wxKILL_NOCHILDREN)
bool BraceSmartIndentEnabled() const
wxString F(const wxChar *msg,...)
sprintf-like function
bool GetUseTabs() const
Retrieve whether tabs will be used in indentation.
static void Display(const wxString &title, const wxString &message, unsigned int delay=5000, unsigned int hysteresis=1)
void SetActiveConfig(int index)
bool CallTipActive()
Is there an active call tip?
virtual void GetCurrentPosition(wxString &filename, int &line)=0
void OnRelease(bool appShutDown) override
cbDebuggerPlugin * GetActiveDebugger()
int WordEndPosition(int pos, bool onlyWordCharacters)
Get position of end of word.
TextCtrlLogger * GetLogger(int &index)
EVTIMPORT const wxEventType cbEVT_EDITOR_CC_DONE
PluginManager * GetPluginManager() const
virtual int GetExitCode() const =0
Get the exit code of the last build process.
void SetupLog(int normalIndex)
static bool GetFlag(Flags flag)
void SetIsRunning(cbPlugin *plugin)
This method should be called when the applications is started by a plugin.
void OnProjectActivated(CodeBlocksEvent &event)
static Perspective GetPerspective()
wxChar GetNextNonWhitespaceCharOnLine(cbStyledTextCtrl *stc, int position=-1, int *pos=nullptr) const
EVTIMPORT const wxEventType cbEVT_SWITCH_VIEW_LAYOUT
ConfigManager * GetConfigManager(const wxString &name_space) const
Base class for debugger plugins.
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
wxString m_PreviousLayout
void OnCompilerFinished(CodeBlocksEvent &event)
EVTIMPORT const wxEventType cbEVT_COMPILER_FINISHED
cbDebuggerConfiguration & GetActiveConfig()
bool AutoIndentEnabled() const
DLLIMPORT const wxString DEFAULT_CONSOLE_TERM
virtual const wxString & GetHostApplication() const
Read the target's host application.
wxString layout
Layout's name.
void OnProjectClosed(CodeBlocksEvent &event)
EVTIMPORT const wxEventType cbEVT_PLUGIN_ATTACHED
void SwitchToPreviousLayout()
bool UnregisterDebugger(cbDebuggerPlugin *plugin)
Called to unregister a debugger plugin.
unsigned long wxGetProcessId()
void GotoLine(int line, bool centerOnScreen=true) override
Move the caret at the specified line.
int FindBlockStart(cbStyledTextCtrl *stc, int position, wxChar blockStart, wxChar blockEnd, bool skipNested=true) const
#define wxSCI_FIND_WHOLEWORD
bool ReadBool(const wxString &name, bool defaultVal=false)
bool SmartIndentEnabled() const
virtual int GetBreakpointsCount() const =0
bool EnsureBuildUpToDate(StartType startType)
EVTIMPORT const wxEventType cbEVT_PLUGIN_RELEASED
Target produces an executable.
const wxString & GetName() const
virtual void CleanupWhenProjectClosed(cbProject *project)=0
EVTIMPORT const wxEventType cbEVT_PROJECT_ACTIVATE
virtual void OnAttachReal()=0
Event used to request from the main app to add a log.
int RunNixConsole(wxString &consoleTty)
FileType
Known file types.
cbProject * GetProject() const
int GetSelectionStart() const
Returns the position at the start of the selection.
DLLIMPORT FileType FileTypeOf(const wxString &filename)
void Log(const wxString &msg, Logger::level level=Logger::info)
SyncEditorResult SyncEditor(const wxString &filename, int line, bool setMarker=true)
PluginType m_Type
Holds the plugin's type.
wxString & Remove(size_t pos)
wxChar GetLastNonWhitespaceChar(cbEditor *ed, int position=-1) const
forward search to the next character which is not a whitespace
void OnEditorOpened(CodeBlocksEvent &event)
wxString AfterFirst(wxUniChar ch) const
Represents a file in a Code::Blocks project.
ProjectBuildTarget * GetCurrentlyCompilingTarget()
Get a pointer to the currently compiling target.
size_t find(const wxString &str, size_t nStart=0) const
A generic Code::Blocks event.
virtual wxString GetOutputFilename()
Read the target's output filename.
virtual cbProject * GetParentProject()
void Release(bool appShutDown)
Release is not a virtual function, so you can't override it.
wxWindow * GetAppWindow() const
int GetIndexOfActiveConfig() const
int WordStartPosition(int pos, bool onlyWordCharacters)
Get position of start of word.
EditorManager * GetEditorManager() const
virtual TargetType GetTargetType() const
Read the target's type.
void Indent(cbStyledTextCtrl *stc, wxString &indent) const
wxUSE_UNICODE_dependent wxChar
wxString GetSelectedText()
Retrieve the selected text.
bool SelectionBraceCompletionEnabled() const
wxString BeforeFirst(wxUniChar ch, wxString *rest=NULL) const
ProjectManager * GetProjectManager() const
Functions returning pointers to the respective sub-manager instances.
bool Contains(const wxString &str) const
DebuggerManager * GetDebuggerManager() const
virtual const wxString & GetFilename() const
Get the editor's filename (if applicable).
DLLIMPORT wxString UnixFilename(const wxString &filename, wxPathFormat format=wxPATH_NATIVE)
Represents a Code::Blocks project.
bool GetDebuggee(wxString &pathToDebuggee, wxString &workingDirectory, ProjectBuildTarget *target)
void SwitchToDebuggingLayout()
int PositionFromPointClose(int x, int y)
Find the position from a point within the window but return wxSCI_INVALID_POSITION if not close to te...
#define wxSCI_FIND_MATCHCASE
cbStyledTextCtrl * GetControl() const
Returns a pointer to the underlying cbStyledTextCtrl object (which itself is the wxWindows implementa...
cbPlugin * GetIsRunning() const
Return a pointer to the plugin which is running the application.
const CompilerPlugins & GetCompilerPlugins() const
ModuleType
The type of module offering a context menu.
void CallTipCancel()
Cancel calltip only if not jumping braces via tab.
virtual void RefreshBreakpointMarkers()
Refresh all markers for the breakpoints (only the markers for the current debugger will be shown) ...
int GetTabWidth() const
Retrieve the visible size of a tab.
bool m_IsAttached
Holds the "attached" state.
Target produces a dynamic library.
size_t Replace(const wxString &strOld, const wxString &strNew, bool replaceAll=true)
virtual void OnRelease(cb_optional bool appShutDown)
Any descendent plugin should override this virtual method and perform any necessary de-initialization...
a logger which prints messages to a wxTextCtrl
cbEditor * GetBuiltinActiveEditor()
void RemoveAllEventSinksFor(void *owner)
bool IsSameAs(const wxString &s, bool caseSensitive=true) const
int FindText(int minPos, int maxPos, const wxString &text, int flags=0, int *findEnd=NULL)
Find some text in the document.
Target produces a native binary.
Base class that all "editors" should inherit from.
LogManager * GetLogManager() const
cbCompilerPlugin * m_pCompiler
int GetCurrentPos() const
Returns the position of the caret.
EVTIMPORT const wxEventType cbEVT_SWITCH_TO_LOG_WINDOW
wxString & Item(size_t nIndex)
Structure representing a generic token, passed between CC plugins and CCManager.
cbProject * GetActiveProject()
Retrieve the active project.
wxString Read(const wxString &key, const wxString &defaultVal=wxEmptyString)
virtual wxString GetBasePath() const
Read the target's base path, e.g. if GetFilename() returns "/usr/local/bin/xxx", base path will retur...
void ClearActiveMarkFromAllEditors()
virtual wxString GetWorkingDir()
Read the target's working dir for execution (valid only for executable targets)
wxString GetLongPath() const
const wxStringCharType * wx_str() const
virtual bool IsBuiltinEditor() const
Is this a built-in editor?
virtual void OnAttach()
Any descendent plugin should override this virtual method and perform any necessary initialization...
bool BraceCompletionEnabled() const
virtual bool IsRunning() const =0
Is the plugin currently compiling?
void OnAttach() override
Any descendent plugin should override this virtual method and perform any necessary initialization...
virtual void Stop()=0
Stop the debugging process (exit debugging).
virtual cbProject * GetProject()=0
MacrosManager * GetMacrosManager() const
cbEditor * Open(const wxString &filename, int pos=0, ProjectFile *data=nullptr)
const wxString & _(const wxString &string)
wxString & Trim(bool fromRight=true)
virtual void EditorLinesAddedOrRemoved(cbEditor *editor, int startline, int lines)
Notify the debugger that lines were added or removed in an editor.
int GetSelectionEnd() const
Returns the position at the end of the selection.
cbEditor * GetBuiltinEditor(EditorBase *eb)
std::map< cbDebuggerPlugin *, PluginData > RegisteredPlugins
virtual void DeleteBreakpoint(cb::shared_ptr< cbBreakpoint > breakpoint)=0
static void Yield()
Whenever you need to call wxYield(), call Manager::Yield(). It's safer.
int GetFirstBraceInLine(cbStyledTextCtrl *stc, int string_style) const
Get the first brace in the line according to the line style.
int PositionFromPoint(wxPoint pt) const
Find the position from a point within the window.
Target produces a static library.
bool ToLong(long *val, int base=10) const
void SetProjectFile(ProjectFile *project_file, bool preserve_modified=false)
Set the ProjectFile pointer associated with this editor.
wxChar GetNextNonWhitespaceCharOfLine(cbStyledTextCtrl *stc, int position=-1, int *pos=nullptr) const
Get the last non-whitespace character from position in line.
EVTIMPORT const wxEventType cbEVT_QUERY_VIEW_LAYOUT
void SetProject(cbProject *project, bool refresh=true)
Set the active project.
int GetCharAt(int pos) const
Returns the character byte at the position.
bool IsProviderFor(cbEditor *ed)
Has this plugin been selected to provide content for the editor.
RegisteredPlugins const & GetAllDebuggers() const
wxString GetGUIName() const
The entry point singleton for working with projects.
void ReplaceEnvVars(wxString &buffer)
Target produces a console executable (without GUI) (distinction between ttExecutable and ttConsoleOnl...
virtual cb::shared_ptr< cbBreakpoint > GetBreakpoint(int index)=0
bool IsRelative(wxPathFormat format=wxPATH_NATIVE) const
virtual wxString GetEditorWordAtCaret(const wxPoint *mousePosition=NULL)
void Log(const wxString &msg, int i=app_log, Logger::level lv=Logger::info)
cbPlugin()
In default cbPlugin's constructor the associated PluginInfo structure is filled with default values...
~cbPlugin() override
cbPlugin destructor.
#define wxSCI_INVALID_POSITION
void DebugLog(const wxString &msg, Logger::level lv=Logger::info)
virtual void ShiftBreakpoint(int index, int lines_to_shift)=0
bool ProcessEvent(CodeBlocksEvent &event)
void wxMilliSleep(unsigned long milliseconds)
bool m_WaitingCompilerToFinish
void RegisterEventSink(wxEventType eventType, IEventFunctorBase< CodeBlocksEvent > *functor)
virtual bool IsRunning() const =0
Is the plugin currently debugging?
DLLIMPORT HookFunctorBase * UnregisterHook(int id, bool deleteHook=true)
Unregister a previously registered project loading/saving hook.
int GetStyleAt(int pos) const
Returns the style byte at the position.
virtual void SetDebugLine(int line)
Highlight the line the debugger will execute next.
virtual void ResetProject()=0
bool HasBreakpoint(cbDebuggerPlugin &plugin, wxString const &filename, int line)
Represents a Code::Blocks project build target.
bool Normalize(int flags=wxPATH_NORM_ALL, const wxString &cwd=wxEmptyString, wxPathFormat format=wxPATH_NATIVE)
EVTIMPORT const wxEventType cbEVT_PROJECT_CLOSE
virtual int Build(ProjectBuildTarget *target=nullptr)=0
Build the project/target.
ProjectFile * GetProjectFile() const
Read the ProjectFile pointer associated with this editor.
EVTIMPORT const wxEventType cbEVT_EDITOR_OPEN
bool IsAttached() const
See whether this plugin is attached or not.
virtual bool SupportsFeature(cbDebuggerFeature::Flags flag)=0
bool MakeAbsolute(const wxString &cwd=wxEmptyString, wxPathFormat format=wxPATH_NATIVE)
virtual bool CompilerFinished(bool compilerFailed, StartType startType)
Called when the compilation has finished.
void OnRelease(bool appShutDown) override
virtual void NotImplemented(const wxString &log) const
This method logs a "Not implemented" message and is provided for convenience only.
void OnCCDoneEvent(CodeBlocksEvent &event)
wxString GetFullPath(wxPathFormat format=wxPATH_NATIVE) const
void OnAttach() override
Any descendent plugin should override this virtual method and perform any necessary initialization...
bool RegisterDebugger(cbDebuggerPlugin *plugin)
Called to register a debugger plugin.
Provides a HookFunctor which redirects the Call() of a cbSmartIndentPlugin so only the interface of c...
virtual void ConvertDirectory(wxString &str, wxString base=_T(""), bool relative=true)=0
cbDebuggerPlugin(const wxString &guiName, const wxString &settingsName)
bool wxGetKeyState(wxKeyCode key)
static wxString Format(const wxString &format,...)
wxString GetLastNonWhitespaceChars(cbEditor *ed, int position=-1, unsigned int NumberOfChars=1) const
(reverse) search for the last characters, which are not whitespace and not comment ...
Dialog that contains a "Don't annoy me" checkbox.
virtual void DoAutocomplete(const CCToken &token, cbEditor *ed)
Callback for inserting the selected autocomplete entry into the editor.
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
virtual void OnReleaseReal(bool appShutDown)=0
cbDebugInterfaceFactory * GetInterfaceFactory()
void DebugLog(const wxString &msg, Logger::level level=Logger::info)
EVTIMPORT const wxEventType cbEVT_SHOW_LOG_MANAGER
virtual bool IsAttachedToProcess() const =0
long wxExecute(const wxString &command, int flags=wxEXEC_ASYNC, wxProcess *callback=NULL, const wxExecuteEnv *env=NULL)
Event used to request from the main app to manage the view layouts.
Target only runs commands in pre-build and/or post-build steps.
DLLIMPORT int RegisterHook(HookFunctorBase *functor)
Register a project loading/saving hook.