ide;debugger; (#968) handle breakpoints by project correctly.
[sdk] / ide / src / debugger / Debugger.ec
index 4784107..10ece58 100644 (file)
@@ -13,6 +13,7 @@ import "debugTools"
 
 #ifdef _DEBUG
 #define GDB_DEBUG_CONSOLE
+#define _DEBUG_INST
 #endif
 
 extern char * strrchr(const char * s, int c);
@@ -21,6 +22,7 @@ extern char * strrchr(const char * s, int c);
 #define strlen _strlen
 #include <stdarg.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #ifdef __APPLE__
 #define __unix__
@@ -55,10 +57,12 @@ char * PrintNow()
 }
 
 // use =0 to disable printing of specific channels
-#ifdef _DEBUG
-static enum dplchan { none, gdbProtoIgnored=0/*1*/, gdbProtoUnknown=2, gdbOutput=3/*3*/, gdbCommand=4/*4*/, debuggerCall=5, debuggerProblem=6, debuggerTemp=7 };
+#ifdef _DEBUG_INST
+static enum dplchan { none, gdbProtoIgnored=0/*1*/, gdbProtoUnknown=2, gdbOutput=0/*3*/, gdbCommand=0/*4*/, debuggerCall=0/*5*/, debuggerProblem=6,
+                        debuggerUserAction=7,debuggerState=8, debuggerBreakpoints=9, debuggerWatches=0/*10*/, debuggerTemp=0 };
 #else
-static enum dplchan { none, gdbProtoIgnored=0, gdbProtoUnknown=0, gdbOutput=0, gdbCommand=0, debuggerCall=0, debuggerProblem=0, debuggerTemp=0 };
+static enum dplchan { none, gdbProtoIgnored=0, gdbProtoUnknown=0, gdbOutput=0, gdbCommand=0, debuggerCall=0, debuggerProblem=0,
+                        debuggerUserAction=0,debuggerState=0, debuggerBreakpoints=0, debuggerWatches=0, debuggerTemp=0 };
 #endif
 static char * _dpct[] = {
    null,
@@ -68,13 +72,22 @@ static char * _dpct[] = {
    "GDB Command",
    ""/*Debugger Call*/,
    "Debugger ***Problem***",
+   "Debugger::ChangeUserAction",
+   "Debugger::ChangeState",
+   "Breakpoints",
+   "Watches",
    "-----> Temporary Message",
    null
 };
 
 // TODO if(strlen(item.value) < MAX_F_STRING)
 
+// Debug Print Line
+#ifdef _DEBUG_INST
 #define _dpl2(...) __dpl2(__FILE__, __LINE__, ##__VA_ARGS__)
+#else
+#define _dpl2(...)
+#endif
 static void __dpl2(char * file, int line, char ** channels, int channel, int indent, typed_object object, ...)
 {
    bool chan = channel && channels && channels[channel];
@@ -442,19 +455,31 @@ char progFifoDir[MAX_LOCATION];
 enum DebuggerState { none, prompt, loaded, running, stopped, terminated, error };
 enum DebuggerEvent
 {
-   none, hit, breakEvent, signal, stepEnd, functionEnd, exit, valgrindStartPause;
+   none, hit, breakEvent, signal, stepEnd, functionEnd, exit, valgrindStartPause, locationReached;
 
-   property bool canBeMonitored { get { return (this == hit || this == breakEvent || this == signal || this == stepEnd || this == functionEnd); } };
+   property bool canBeMonitored { get { return (this == hit || this == breakEvent || this == signal || this == stepEnd || this == functionEnd || this == locationReached); } };
+};
+enum DebuggerAction { none, internal, restart, stop, selectFrame, advance }; //, bpValidation
+enum DebuggerReason
+{
+   unknown, endSteppingRange, functionFinished, signalReceived, breakpointHit, locationReached
+   //watchpointTrigger, readWatchpointTrigger, accessWatchpointTrigger, watchpointScope,
+   //exited, exitedNormally, exitedSignalled;
 };
-enum DebuggerAction { none, internal, restart, stop, selectFrame }; //, bpValidation
 enum BreakpointType
 {
-   none, internalMain, internalWinMain, internalModulesLoaded, user, runToCursor, internalModuleLoad;
+   none, internalMain, internalWinMain, internalModulesLoaded, user, runToCursor, internalModuleLoad, internalEntry;
 
-   property bool isInternal { get { return (this == internalMain || this == internalWinMain || this == internalModulesLoaded || this == internalModuleLoad); } };
+   property bool isInternal { get { return (this == internalMain || this == internalWinMain || this == internalModulesLoaded || this == internalModuleLoad || this == internalEntry); } };
    property bool isUser { get { return (this == user || this == runToCursor); } };
 };
 enum DebuggerEvaluationError { none, symbolNotFound, memoryCantBeRead, unknown };
+enum DebuggerUserAction { none, start, resume, _break, stop, restart, selectThread, selectFrame, stepInto, stepOver, stepUntil, stepOut, runToCursor };
+enum GdbExecution
+{
+   none, run, _continue, next, until, advance, step, finish;
+   property bool suspendInternalBreakpoints { get { return (this == until || this == advance || this == step || this == finish); } };
+};
 
 FileDialog debuggerFileDialog { type = selectDir };
 
@@ -498,9 +523,12 @@ class Debugger
    char * targetDir;
    char * targetFile;
    
+   GdbExecution gdbExecution;
+   DebuggerUserAction userAction;
    DebuggerState state;
    DebuggerEvent event;
    DebuggerAction breakType;
+   char * breakString;
    //DebuggerCommand lastCommand;    // THE COMPILER COMPILES STUFF THAT DOES NOT EXIST???
 
    GdbDataStop stopItem;
@@ -521,6 +549,10 @@ class Debugger
    ValgrindLogThread vgLogThread { debugger = this };
    ValgrindTargetThread vgTargetThread { debugger = this };
    GdbThread gdbThread { debugger = this };
+
+   bool entryPoint;
+   Map<String, bool> projectsLibraryLoaded { };
+
    Timer gdbTimer
    {
       delay = 0.0, userData = this;
@@ -538,16 +570,51 @@ class Debugger
 
          event = none;
          if(this.stopItem)
+         {
             this.stopItem = null;
+#ifdef _DEBUG_INST
+            {
+               char * s;
+               DynamicString bpReport { };
+
+               for(bp : sysBPs; bp.inserted)
+               {
+                  bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
+                  delete s;
+               }
+               if(bpRunToCursor && bpRunToCursor.inserted)
+               {
+                  Breakpoint bp = bpRunToCursor;
+                  bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
+                  delete s;
+               }
+               for(bp : ide.workspace.breakpoints; bp.inserted)
+               {
+                  bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
+                  delete s;
+               }
+               s = bpReport;
+               _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "gdbTimer::DelayExpired: ", s+1);
+
+               if(stopItem.bkptno)
+               {
+                  bool isInternal;
+                  Breakpoint bp = GetBreakpointById(stopItem.bkptno, &isInternal);
+                  if(bp)
+                     _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "gdb stopped by a breakpoint: ", bp.type, "(", s=bp.CopyLocationString(false), ")"); delete s;
+               }
+            }
+#endif
+         }
+#ifdef _DEBUG_INST
          else
          {
             if(curEvent && curEvent != exit)
             {
-#ifdef _DEBUG
                _dpl(0, "No stop item");
-#endif
             }
          }
+#endif
          switch(breakType)
          {
             case restart:
@@ -576,13 +643,8 @@ class Debugger
          if(curEvent == none)
             return false;
 
-         switch (curEvent)
+         switch(curEvent)
          {
-            case breakEvent:
-               activeThread = stopItem.threadid;
-               GdbCommand(false, "-thread-list-ids");
-               GdbGetStack();
-               break;
             case hit:
                {
                   bool isInternal;
@@ -596,7 +658,7 @@ class Debugger
                      if(stopItem && stopItem.frame)
                      {
                         if(bpInternal && bpRunToCursor && bpRunToCursor.inserted && !strcmp(bpRunToCursor.bp.addr, bp.bp.addr))
-                           bpUser =  bpRunToCursor;
+                           bpUser = bpRunToCursor;
                         else
                         {
                            for(item : (bpInternal ? ide.workspace.breakpoints : sysBPs); item.inserted)
@@ -619,8 +681,6 @@ class Debugger
                   }
                   else
                      _dpl2(_dpct, dplchan::debuggerProblem, 0, "Breakpoint bkptno(", stopItem.bkptno, ") invalid or not found!");
-                  if(bpUser && bpUser.type == runToCursor)
-                     ignoreBreakpoints = false;
                   if((bpUser && !ignoreBreakpoints) || (bpInternal && userBreakOnInternalBreakpoint))
                      monitor = true;
                   hitThread = stopItem.threadid;
@@ -628,8 +688,10 @@ class Debugger
                break;
             case signal:
                signalThread = stopItem.threadid;
+            case breakEvent:
             case stepEnd:
             case functionEnd:
+            case locationReached:
                monitor = true;
                ignoreBreakpoints = false;
                break;
@@ -641,16 +703,19 @@ class Debugger
                break;
          }
 
+         if(monitor || (bpUser && bpUser.type == runToCursor))
+            GdbGetStack();
+
          if(monitor)
          {
             activeThread = stopItem.threadid;
             GdbCommand(false, "-thread-list-ids");
-            GdbGetStack();
             if(activeFrameLevel > 0)
                GdbCommand(false, "-stack-select-frame %d", activeFrameLevel);
 
             WatchesCodeEditorLinkInit();
             EvaluateWatches();
+            ide.AdjustDebugMenus();
          }
 
          if(curEvent == signal)
@@ -672,15 +737,37 @@ class Debugger
 
          if(monitor && curEvent.canBeMonitored)
          {
-            SelectFrame(activeFrameLevel);
-            GoToStackFrameLine(activeFrameLevel, true);
+            InternalSelectFrame(activeFrameLevel);
+            GoToStackFrameLine(activeFrameLevel, true, false);
             ide.ShowCodeEditor();
             ideMainFrame.Activate();   // TOFIX: ide.Activate() is not reliable (app inactive)
             ide.Update(null);
          }
 
          if(curEvent == hit)
-            EventHit(stopItem, bpInternal, bpUser);
+         {
+            if(BreakpointHit(stopItem, bpInternal, bpUser))
+            {
+               ide.AdjustDebugMenus();
+               if(bpUser && bpUser.type == runToCursor)
+               {
+                  ignoreBreakpoints = false;
+                  UnsetBreakpoint(bpUser);
+                  delete bpRunToCursor;
+               }
+            }
+            else
+            {
+               if(breakType == advance && bpInternal && (bpInternal.type == internalMain || bpInternal.type == internalEntry))
+               {
+                  breakType = none;
+                  GdbExecAdvance(breakString, 0);
+                  delete breakString;
+               }
+               else
+                  GdbExecContinue(false);
+            }
+         }
 
          if(stopItem)
          {
@@ -700,12 +787,32 @@ class Debugger
    ProgramThread progThread { };
 #endif
 
+#ifdef _DEBUG_INST
+#define _ChangeUserAction(value) ChangeUserAction(__FILE__, __LINE__, value)
+   void ChangeUserAction(char * file, int line, DebuggerUserAction value)
+   {
+      bool same = value == userAction;
+      __dpl2(file, line, _dpct, dplchan::debuggerUserAction, 0, userAction, /*same ? " *** == *** " : */" -> ", value);
+      userAction = value;
+   }
+#else
+#define _ChangeUserAction(value) userAction = value
+#endif
+
+#ifdef _DEBUG_INST
+#define _ChangeState(value) ChangeState(__FILE__, __LINE__, value)
+   void ChangeState(char * file, int line, DebuggerState value)
+#else
+#define _ChangeState(value) ChangeState(value)
    void ChangeState(DebuggerState value)
+#endif
    {
       bool same = value == state;
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ChangeState (", state, same ? " *** == *** " : " -> ", value, ")");
+#ifdef _DEBUG_INST
+      __dpl2(file, line, _dpct, dplchan::debuggerState, 0, state, same ? " *** == *** " : " -> ", value);
+#endif
       state = value;
-      if(!same && ide) ide.AdjustDebugMenus();
+      if(!same) ide.AdjustDebugMenus();
    }
 
    void CleanUp()
@@ -742,7 +849,7 @@ class Debugger
       targetDir = null;
       targetFile = null;
       
-      ChangeState(none);
+      _ChangeState(none);
       event = none;
       breakType = none;
 
@@ -756,6 +863,9 @@ class Debugger
       prjConfig = null;
       codeEditor = null;
 
+      entryPoint = false;
+      projectsLibraryLoaded.Free();
+
       /*GdbThread gdbThread
       Timer gdbTimer*/
    }
@@ -765,6 +875,7 @@ class Debugger
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::constructor");
       ideProcessId = Process_GetCurrentProcessId();
 
+      sysBPs.Add(Breakpoint { type = internalEntry, enabled = false, level = -1 });
       sysBPs.Add(Breakpoint { type = internalMain, function = "main", enabled = true, level = -1 });
 #if defined(__WIN32__)
       sysBPs.Add(Breakpoint { type = internalWinMain, function = "WinMain", enabled = true, level = -1 });
@@ -789,12 +900,14 @@ class Debugger
    void Resume()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Resume");
+      _ChangeUserAction(resume);
       GdbExecContinue(true);
    }
 
    void Break()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Break");
+      _ChangeUserAction(_break);
       if(state == running)
       {
          if(targetProcessId)
@@ -805,6 +918,7 @@ class Debugger
    void Stop()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Stop");
+      _ChangeUserAction(stop);
       switch(state)
       {
          case running:
@@ -828,6 +942,7 @@ class Debugger
    void Restart(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Restart");
+      _ChangeUserAction(restart);
       if(StartSession(compiler, config, bitDepth, useValgrind, true, false, false/*, false*/) == loaded)
          GdbExecRun();
    }
@@ -851,7 +966,7 @@ class Debugger
       return false;
    }
 
-   bool GoToStackFrameLine(int stackLevel, bool askForLocation)
+   bool GoToStackFrameLine(int stackLevel, bool askForLocation, bool fromCallStack)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GoToStackFrameLine(", stackLevel, ", ", askForLocation, ")");
       if(ide)
@@ -867,9 +982,12 @@ class Debugger
                break;
          if(frame)
          {
-            ide.callStackView.Show();
+            if(!fromCallStack)
+               ide.callStackView.Show();
 
-            if(!frame.absoluteFile && frame.file)
+            if(frame.absoluteFile)
+               editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal, false);
+            if(!editor && frame.file)
                frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
             if(!frame.absoluteFile && askForLocation && frame.file)
             {
@@ -884,8 +1002,10 @@ class Debugger
                   frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
                }
             }
-            if(frame.absoluteFile)
+            if(!editor && frame.absoluteFile)
                editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal, false);
+            if(editor)
+               ide.RepositionWindows(false);
             ide.Update(null);
             if(editor && frame.line)
             {
@@ -902,6 +1022,7 @@ class Debugger
    void SelectThread(int thread)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectThread(", thread, ")");
+      _ChangeUserAction(selectThread);
       if(state == stopped)
       {
          if(thread != activeThread)
@@ -910,9 +1031,8 @@ class Debugger
             ide.callStackView.Clear();
             GdbCommand(false, "-thread-select %d", thread);
             GdbGetStack();
-            // Why was SelectFrame missing here?
-            SelectFrame(activeFrameLevel);
-            GoToStackFrameLine(activeFrameLevel, true);
+            InternalSelectFrame(activeFrameLevel);
+            GoToStackFrameLine(activeFrameLevel, true, false);
             WatchesCodeEditorLinkRelease();
             WatchesCodeEditorLinkInit();
             EvaluateWatches();
@@ -924,7 +1044,14 @@ class Debugger
 
    void SelectFrame(int frame)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectFrame(", frame, ")");
+      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectFrame(", frame, ")");
+      _ChangeUserAction(selectFrame);
+      InternalSelectFrame(frame);
+   }
+
+   void InternalSelectFrame(int frame)
+   {
+      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::InternalSelectFrame(", frame, ")");
       if(state == stopped)
       {
          if(frame != activeFrameLevel || !codeEditor || !codeEditor.visible)
@@ -949,7 +1076,7 @@ class Debugger
       char verboseExitCode[128];
       
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::HandleExit(", reason, ", ", code, ")");
-      ChangeState(loaded); // this state change seems to be superfluous, might be in case of gdb crash
+      _ChangeState(loaded); // this state change seems to be superfluous, might be in case of gdb crash
       targetProcessId = 0;
 
       if(code)
@@ -1048,8 +1175,6 @@ class Debugger
          }
          this.ignoreBreakpoints = ignoreBreakpoints;
          this.userBreakOnInternalBreakpoint = userBreakOnInternalBreakpoint;
-         if(ignoreBreakpoints && (result == loaded || result == stopped))
-            GdbBreakpointsDelete(false, false);
       }
       return result;
    }
@@ -1057,6 +1182,7 @@ class Debugger
    void Start(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Start()");
+      _ChangeUserAction(start);
       if(StartSession(compiler, config, bitDepth, useValgrind, true, false, false/*, false*/) == loaded)
          GdbExecRun();
    }
@@ -1064,6 +1190,7 @@ class Debugger
    void StepInto(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepInto()");
+      _ChangeUserAction(stepInto);
       switch(StartSession(compiler, config, bitDepth, useValgrind, false, true, false/*, false*/))
       {
          case loaded:  GdbExecRun();  break;
@@ -1074,6 +1201,7 @@ class Debugger
    void StepOver(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool ignoreBreakpoints)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOver()");
+      _ChangeUserAction(stepOver);
       switch(StartSession(compiler, config, bitDepth, useValgrind, false, true, ignoreBreakpoints/*, false*/))
       {
          case loaded:  GdbExecRun();  break;
@@ -1081,28 +1209,36 @@ class Debugger
       }
    }
 
+   void StepUntil(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool ignoreBreakpoints)
+   {
+      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepUntil()");
+      _ChangeUserAction(stepUntil);
+      switch(StartSession(compiler, config, bitDepth, useValgrind, false, true, ignoreBreakpoints/*, false*/))
+      {
+         case loaded:  GdbExecRun();          break;
+         case stopped: GdbExecUntil(null, 0); break;
+      }
+   }
+
    void StepOut(bool ignoreBreakpoints)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOut()");
+      _ChangeUserAction(stepOut);
       if(state == stopped)
       {
          this.ignoreBreakpoints = ignoreBreakpoints;
-         if(ignoreBreakpoints)
-            GdbBreakpointsDelete(true, false);
-         GdbExecFinish();
+         if(frameCount > 1)
+            GdbExecFinish();
+         else
+            GdbExecContinue(true);
       }
    }
 
-   void RunToCursor(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, char * absoluteFilePath, int lineNumber, bool ignoreBreakpoints, bool atSameLevel)
+   void RunToCursor(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, char * absoluteFilePath, int lineNumber, bool ignoreBreakpoints, bool atSameLevel, bool oldImplementation)
    {
       char relativeFilePath[MAX_LOCATION];
-      DebuggerState st = state;
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::RunToCursor()");
-      //if(st == loaded)
-      //{
-      //   ide.outputView.ShowClearSelectTab(debug);
-      //   ide.outputView.debugBox.Logf($"Starting debug mode\n");
-      //}
+      _ChangeUserAction(runToCursor);
       if(!ide.projectView.project.GetRelativePath(absoluteFilePath, relativeFilePath))
          strcpy(relativeFilePath, absoluteFilePath);
 
@@ -1112,22 +1248,37 @@ class Debugger
          delete bpRunToCursor;
       }
 
-      bpRunToCursor = Breakpoint { };
-      bpRunToCursor.absoluteFilePath = absoluteFilePath;
-      bpRunToCursor.relativeFilePath = relativeFilePath;
-      bpRunToCursor.line = lineNumber;
-      bpRunToCursor.type = runToCursor;
-      bpRunToCursor.enabled = true;
-      bpRunToCursor.level = atSameLevel ? frameCount - activeFrameLevel -1 : -1;
+      StartSession(compiler, config, bitDepth, useValgrind, false, false, ignoreBreakpoints/*, true*/);
 
-      switch(StartSession(compiler, config, bitDepth, useValgrind, false, false, ignoreBreakpoints/*, true*/))
+#if 0
+      if(oldImplementation)
       {
-         case loaded:
-            GdbExecRun();
-            break;
-         case stopped:
+         bpRunToCursor = Breakpoint { };
+         bpRunToCursor.absoluteFilePath = absoluteFilePath;
+         bpRunToCursor.relativeFilePath = relativeFilePath;
+         bpRunToCursor.line = lineNumber;
+         bpRunToCursor.type = runToCursor;
+         bpRunToCursor.enabled = true;
+         bpRunToCursor.level = atSameLevel ? frameCount - activeFrameLevel -1 : -1;
+      }
+#endif
+      if(state == loaded)
+      {
+         breakType = advance;
+         breakString = PrintString(relativeFilePath, ":", lineNumber);
+         GdbExecRun();
+      }
+      else if(state == stopped)
+      {
+         if(oldImplementation)
             GdbExecContinue(true);
-            break;
+         else
+         {
+            if(atSameLevel)
+               GdbExecUntil(absoluteFilePath, lineNumber);
+            else
+               GdbExecAdvance(absoluteFilePath, lineNumber);
+         }
       }
    }
 
@@ -1348,7 +1499,7 @@ class Debugger
       char sourceDir[MAX_LOCATION];
       Breakpoint bp = null;
 
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ToggleBreakpoint(", fileName, ":", lineNumber, ")");
+      _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::ToggleBreakpoint(", fileName, ":", lineNumber, ")");
       strcpy(absolutePath, absoluteFilePath);
       for(i : ide.workspace.breakpoints; i.type == user && i.absoluteFilePath && !fstrcmp(i.absoluteFilePath, absolutePath) && i.line == lineNumber)
       {
@@ -1419,7 +1570,7 @@ class Debugger
             }
          }
          ide.workspace.bpCount++;
-         bp = { line = lineNumber, type = user, enabled = true, level = -1 };
+         bp = { line = lineNumber, type = user, enabled = true, level = -1, project = prj };
          ide.workspace.breakpoints.Add(bp);
          bp.absoluteFilePath = absolutePath;
          bp.relativeFilePath = relativePath;
@@ -1478,7 +1629,7 @@ class Debugger
       DebugListItem item { };
       Argument arg;
       
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseFrame()");
+      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseFrame()");
       TokenizeList(string, ',', frameTokens);
       for(i = 0; i < frameTokens.count; i++)
       {
@@ -1565,7 +1716,7 @@ class Debugger
    Breakpoint GetBreakpointById(int id, bool * isInternal)
    {
       Breakpoint bp = null;
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GetBreakpointById(", id, ")");
+      //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::GetBreakpointById(", id, ")");
       if(isInternal)
          *isInternal = false;
       if(id)
@@ -1736,93 +1887,108 @@ class Debugger
       return true;
    }
 
-   void GdbBreakpointsInsert()
+   void BreakpointsMaintenance()
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbBreakpointsInsert()");
+      //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::BreakpointsMaintenance()");
       if(symbols)
       {
-         DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig, bitDepth);
-         for(bp : sysBPs; !bp.inserted)
+         if(gdbExecution.suspendInternalBreakpoints)
+         {
+            for(bp : sysBPs; bp.inserted)
+               UnsetBreakpoint(bp);
+         }
+         else
          {
-            bool insert = false;
-            if(bp.type == internalModulesLoaded)
+            DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig, bitDepth);
+            for(bp : sysBPs; !bp.inserted)
             {
-               char path[MAX_LOCATION];
-               char name[MAX_LOCATION];
-               char fixedModuleName[MAX_FILENAME];
-               char line[16384];
-               int lineNumber;
-               bool moduleLoadBlock = false;
-               File f;
-               ReplaceSpaces(fixedModuleName, ide.project.moduleName);
-               snprintf(name, sizeof(name),"%s.main.ec", fixedModuleName);
-               name[sizeof(name)-1] = 0;
-               strcpy(path, ide.workspace.projectDir);
-               PathCatSlash(path, objDir.dir);
-               PathCatSlash(path, name);
-               f = FileOpen(path, read);
-               if(f)
+               bool insert = false;
+               if(bp.type == internalModulesLoaded)
                {
-                  for(lineNumber = 1; !f.Eof(); lineNumber++)
+                  char path[MAX_LOCATION];
+                  char name[MAX_LOCATION];
+                  char fixedModuleName[MAX_FILENAME];
+                  char line[16384];
+                  int lineNumber;
+                  bool moduleLoadBlock = false;
+                  File f;
+                  ReplaceSpaces(fixedModuleName, ide.project.moduleName);
+                  snprintf(name, sizeof(name),"%s.main.ec", fixedModuleName);
+                  name[sizeof(name)-1] = 0;
+                  strcpy(path, ide.workspace.projectDir);
+                  PathCatSlash(path, objDir.dir);
+                  PathCatSlash(path, name);
+                  f = FileOpen(path, read);
+                  if(f)
                   {
-                     if(f.GetLine(line, sizeof(line) - 1))
+                     for(lineNumber = 1; !f.Eof(); lineNumber++)
                      {
-                        bool moduleLoadLine;
-                        TrimLSpaces(line, line);
-                        moduleLoadLine = !strncmp(line, "eModule_Load", strlen("eModule_Load"));
-                        if(!moduleLoadBlock && moduleLoadLine)
-                           moduleLoadBlock = true;
-                        else if(moduleLoadBlock && !moduleLoadLine && strlen(line) > 0)
-                           break;
+                        if(f.GetLine(line, sizeof(line) - 1))
+                        {
+                           bool moduleLoadLine;
+                           TrimLSpaces(line, line);
+                           moduleLoadLine = !strncmp(line, "eModule_Load", strlen("eModule_Load"));
+                           if(!moduleLoadBlock && moduleLoadLine)
+                              moduleLoadBlock = true;
+                           else if(moduleLoadBlock && !moduleLoadLine && strlen(line) > 0)
+                              break;
+                        }
                      }
+                     if(!f.Eof())
+                     {
+                        char relative[MAX_LOCATION];
+                        bp.absoluteFilePath = path;
+                        MakePathRelative(path, ide.workspace.projectDir, relative);
+                        bp.relativeFilePath = relative;
+                        bp.line = lineNumber;
+                        insert = true;
+                     }
+                     delete f;
                   }
-                  if(!f.Eof())
-                  {
-                     char relative[MAX_LOCATION];
-                     bp.absoluteFilePath = path;
-                     MakePathRelative(path, ide.workspace.projectDir, relative);
-                     bp.relativeFilePath = relative;
-                     bp.line = lineNumber;
-                     insert = true;
-                  }
-                  delete f;
                }
-            }
-            else if(bp.type == internalModuleLoad)
-            {
-               if(modules)
+               else if(bp.type == internalModuleLoad)
                {
-                  for(prj : ide.workspace.projects)
+                  if(modules)
                   {
-                     if(!strcmp(prj.moduleName, "ecere"))
+                     for(prj : ide.workspace.projects)
                      {
-                        ProjectNode node = prj.topNode.Find("instance.c", false);
-                        if(node)
+                        if(!strcmp(prj.moduleName, "ecere"))
                         {
-                           char path[MAX_LOCATION];
-                           char relative[MAX_LOCATION];
-                           node.GetFullFilePath(path);
-                           bp.absoluteFilePath = path;
-                           MakePathRelative(path, prj.topNode.path, relative);
-                           bp.relativeFilePath = relative;
-                           insert = true;
-                           break;
+                           ProjectNode node = prj.topNode.Find("instance.c", false);
+                           if(node)
+                           {
+                              char path[MAX_LOCATION];
+                              char relative[MAX_LOCATION];
+                              node.GetFullFilePath(path);
+                              bp.absoluteFilePath = path;
+                              MakePathRelative(path, prj.topNode.path, relative);
+                              bp.relativeFilePath = relative;
+                              insert = true;
+                              break;
+                           }
                         }
                      }
                   }
                }
+               else
+                  insert = true;
+               if(insert)
+                  SetBreakpoint(bp, false);
             }
-            else
-               insert = true;
-            if(insert)
-               SetBreakpoint(bp, false);
+            delete objDir;
          }
-         delete objDir;
 
+         if(userAction != runToCursor && bpRunToCursor && bpRunToCursor.inserted)
+            UnsetBreakpoint(bpRunToCursor);
          if(bpRunToCursor && !bpRunToCursor.inserted)
             SetBreakpoint(bpRunToCursor, false);
 
-         if(!ignoreBreakpoints)
+         if(ignoreBreakpoints)
+         {
+            for(bp : ide.workspace.breakpoints; bp.inserted)
+               UnsetBreakpoint(bp);
+         }
+         else
          {
             for(bp : ide.workspace.breakpoints; !bp.inserted && bp.type == user)
             {
@@ -1846,7 +2012,7 @@ class Debugger
 
    void UnsetBreakpoint(Breakpoint bp)
    {
-      char * s; _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::UnsetBreakpoint(", s=bp.CopyLocationString(false), ")"); delete s;
+      char * s; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::UnsetBreakpoint(", s=bp.CopyLocationString(false), ") -- ", bp.type); delete s;
       if(symbols && bp.inserted)
       {
          GdbCommand(false, "-break-delete %s", bp.bp.number);
@@ -1857,9 +2023,9 @@ class Debugger
 
    bool SetBreakpoint(Breakpoint bp, bool removePath)
    {
-      char * s; _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SetBreakpoint(", s=bp.CopyLocationString(false), ", ", removePath ? "**** removePath(true) ****" : "", ")"); delete s;
+      char * s; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::SetBreakpoint(", s=bp.CopyLocationString(false), ", ", removePath ? "**** removePath(true) ****" : "", ") -- ", bp.type); delete s;
       breakpointError = false;
-      if(symbols)
+      if(symbols && bp.enabled && (!bp.project || bp.project == ide.project || projectsLibraryLoaded[bp.project.name]))
       {
          char * location = bp.CopyLocationString(removePath);
          sentBreakInsert = true;
@@ -1918,23 +2084,6 @@ class Debugger
       return !breakpointError;
    }
 
-   void GdbBreakpointsDelete(bool deleteRunToCursor, bool deleteInternalBreakpoints)
-   {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbBreakpointsDelete(deleteRunToCursor(", deleteRunToCursor, "))");
-      if(symbols)
-      {
-         if(deleteInternalBreakpoints)
-         {
-            for(bp : sysBPs)
-               UnsetBreakpoint(bp);
-         }
-         for(bp : ide.workspace.breakpoints)
-            UnsetBreakpoint(bp);
-         if(deleteRunToCursor && bpRunToCursor)
-            UnsetBreakpoint(bpRunToCursor);
-      }
-   }
-
    void GdbGetStack()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbGetStack()");
@@ -1960,7 +2109,7 @@ class Debugger
       {
          char escaped[MAX_LOCATION];
          strescpy(escaped, targetFile);
-         GdbCommand(false, "file \"%s\"", escaped);  //GDB/MI Missing Implementation -symbol-file, -target-attach
+         GdbCommand(false, "file \"%s\"", escaped); //GDB/MI Missing Implementation in 5.1.1 but we now have -file-exec-and-symbols / -file-exec-file / -file-symbol-file
 
          if(!symbols)
             return true;
@@ -1972,6 +2121,8 @@ class Debugger
             printf("target remote | %s --pid=%d\n", vgdbCommand, targetProcessId);
             GdbCommand(false, "target remote | %s --pid=%d", vgdbCommand, targetProcessId); // TODO: vgdb command config option
          }
+         else
+            GdbCommand(false, "info target"); //GDB/MI Missing Implementation -file-list-symbol-files and -file-list-exec-sections
 
          /*for(prj : ide.workspace.projects; prj != ide.workspace.projects.firstIterator.data)
             GdbCommand(false, "-environment-directory \"%s\"", prj.topNode.path);*/
@@ -2000,7 +2151,7 @@ class Debugger
    {
       if(targeted)
       {
-         GdbBreakpointsDelete(true, true);
+         BreakpointsDeleteAll();
          GdbCommand(false, "file");  //GDB/MI Missing Implementation -target-detach
          targeted = false;
          symbols = true;
@@ -2021,7 +2172,7 @@ class Debugger
             serialSemaphore.Wait();
          else
          {
-            ChangeState(loaded);
+            _ChangeState(loaded);
             targetProcessId = 0;
          }
          app.Lock();
@@ -2034,10 +2185,12 @@ class Debugger
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecRun()");
       GdbTargetSet();
+      if(!usingValgrind)
+         gdbExecution = run;
       GdbExecCommon();
       ShowDebuggerViews();
       if(usingValgrind)
-         GdbCommand(true, "-exec-continue");
+         GdbExecContinue(true);
       else
          GdbCommand(true, "-exec-run");
    }
@@ -2045,6 +2198,7 @@ class Debugger
    void GdbExecContinue(bool focus)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecContinue()");
+      gdbExecution = run;
       GdbExecCommon();
       GdbCommand(focus, "-exec-continue");
    }
@@ -2052,13 +2206,47 @@ class Debugger
    void GdbExecNext()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecNext()");
+      gdbExecution = next;
       GdbExecCommon();
       GdbCommand(true, "-exec-next");
    }
 
+   void GdbExecUntil(char * absoluteFilePath, int lineNumber)
+   {
+      char relativeFilePath[MAX_LOCATION];
+      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecUntil()");
+      gdbExecution = until;
+      GdbExecCommon();
+      if(absoluteFilePath)
+      {
+         if(!ide.projectView.project.GetRelativePath(absoluteFilePath, relativeFilePath))
+            strcpy(relativeFilePath, absoluteFilePath);
+         GdbCommand(true, "-exec-until %s:%d", relativeFilePath, lineNumber);
+      }
+      else
+         GdbCommand(true, "-exec-until");
+   }
+
+   void GdbExecAdvance(char * absoluteFilePathOrLocation, int lineNumber)
+   {
+      char relativeFilePath[MAX_LOCATION];
+      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecAdvance()");
+      gdbExecution = advance;
+      GdbExecCommon();
+      if(lineNumber)
+      {
+         if(!ide.projectView.project.GetRelativePath(absoluteFilePathOrLocation, relativeFilePath))
+            strcpy(relativeFilePath, absoluteFilePathOrLocation);
+         GdbCommand(true, "advance %s:%d", relativeFilePath, lineNumber); // should use -exec-advance -- GDB/MI implementation missing
+      }
+      else
+         GdbCommand(true, "advance %s", absoluteFilePathOrLocation); // should use -exec-advance -- GDB/MI implementation missing
+   }
+
    void GdbExecStep()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecStep()");
+      gdbExecution = step;
       GdbExecCommon();
       GdbCommand(true, "-exec-step");
    }
@@ -2066,6 +2254,7 @@ class Debugger
    void GdbExecFinish()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecFinish()");
+      gdbExecution = finish;
       GdbExecCommon();
       GdbCommand(true, "-exec-finish");
    }
@@ -2073,8 +2262,7 @@ class Debugger
    void GdbExecCommon()
    {
       //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecCommon()");
-      ClearBreakDisplay();
-      GdbBreakpointsInsert();
+      BreakpointsMaintenance();
    }
 
 #ifdef GDB_DEBUG_GUI
@@ -2147,7 +2335,7 @@ class Debugger
       this.bitDepth = bitDepth;
       usingValgrind = useValgrind;
 
-      ChangeState(loaded);
+      _ChangeState(loaded);
       sentKill = false;
       sentBreakInsert = false;
       breakpointError = false;
@@ -2156,7 +2344,8 @@ class Debugger
       targeted = false;
       modules = false;
       needReset = false;
-      
+      projectsLibraryLoaded.Free();
+
       ide.outputView.ShowClearSelectTab(debug);
       ide.outputView.debugBox.Logf($"Starting debug mode\n");
 
@@ -2224,7 +2413,7 @@ class Debugger
                   valgrindCommand, vgLogPath, (char*)vgLeakCheck, vgRedzoneSizeFlag, vgTrackOrigins ? "yes" : "no", targetFile, clArgs ? " " : "", clArgs ? clArgs : "");
             if(vgRedzoneSize != -1)
                delete vgRedzoneSizeFlag;
-            vgTargetHandle = DualPipeOpen(PipeOpenMode { output = 1, error = 2, input = 1 }, command);
+            vgTargetHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
             if(!vgTargetHandle)
             {
                ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start Valgrind\n");
@@ -2267,7 +2456,7 @@ class Debugger
          {
             strcat(command, " -n -silent --interpreter=mi2"); //-async //\"%s\"
             gdbTimer.Start();
-            gdbHandle = DualPipeOpen(PipeOpenMode { output = 1, error = 2, input = 1 }, command);
+            gdbHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
             if(!gdbHandle)
             {
                ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start GDB\n");
@@ -2303,7 +2492,7 @@ class Debugger
 
          if(!GdbTargetSet())
          {
-            //ChangeState(terminated);
+            //_ChangeState(terminated);
             result = false;
          }
       }
@@ -2382,7 +2571,7 @@ class Debugger
          }
       }
       gdbTimer.Stop();
-      ChangeState(terminated); // this state change seems to be superfluous, is it safety for something?
+      _ChangeState(terminated); // this state change seems to be superfluous, is it safety for something?
       prjConfig = null;
       needReset = false;
 
@@ -2487,7 +2676,7 @@ class Debugger
    {
       bool result = false;
       
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ResolveWatch()");
+      _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::ResolveWatch()");
       wh.Reset();
 
       /*delete wh.value;
@@ -2946,14 +3135,14 @@ class Debugger
 
    void EvaluateWatches()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::EvaluateWatches()");
+      _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateWatches()");
       for(wh : ide.workspace.watches)
          ResolveWatch(wh);
    }
 
    char * ::GdbEvaluateExpression(char * expression)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbEvaluateExpression(", expression, ")");
+      _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::GdbEvaluateExpression(", expression, ")");
       eval.active = true;
       eval.error = none;
       GdbCommand(false, "-data-evaluate-expression \"%s\"", expression);
@@ -3021,10 +3210,11 @@ class Debugger
       return null;
    }
 
-   void EventHit(GdbDataStop stopItem, Breakpoint bpInternal, Breakpoint bpUser)
+   bool BreakpointHit(GdbDataStop stopItem, Breakpoint bpInternal, Breakpoint bpUser)
    {
+      bool result = true;
       char * s1 = null; char * s2 = null;
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::EventHit(",
+      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::BreakpointHit(",
             "bpInternal(", bpInternal ? s1=bpInternal.CopyLocationString(false) : null, "), ",
             "bpUser(", bpUser ? s2=bpUser.CopyLocationString(false) : null, ")) -- ",
             "ignoreBreakpoints(", ignoreBreakpoints, "), ",
@@ -3045,36 +3235,39 @@ class Debugger
          if(bpInternal.type == internalModulesLoaded)
             modules = true;
          if(!bpUser && !userBreakOnInternalBreakpoint)
-            GdbExecContinue(false);
+         {
+            if(userAction == stepOut)//if(prevStopItem.reason == functionFinished)
+               StepOut(ignoreBreakpoints);
+            else
+               result = false;
+         }
       }
       if(bpUser)
       {
          bool conditionMet = true;
+         bool levelMatch = (bpUser.level == -1 || bpUser.level == frameCount-1);
          if(bpUser.condition)
             conditionMet = ResolveWatch(bpUser.condition);
          bpUser.hits++;
-         if(!ignoreBreakpoints && (bpUser.level == -1 || bpUser.level == frameCount-1) && conditionMet)
+         if(levelMatch && conditionMet)
          {
             if(!bpUser.ignore)
                bpUser.breaks++;
             else
             {
                bpUser.ignore--;
-               GdbExecContinue(false);
+               result = false;
             }
          }
          else
-            GdbExecContinue(false);
+            result = false;
          ide.breakpointsView.UpdateBreakpoint(bpUser.row);
-         if(bpUser == bpRunToCursor)
-         {
-            UnsetBreakpoint(bpUser);
-            delete bpRunToCursor;
-         }
       }
 
       if(!bpUser && !bpInternal)
-         GdbExecContinue(false);
+         result = false;
+
+      return result;
    }
 
    void ValgrindTargetThreadExit()
@@ -3093,7 +3286,7 @@ class Debugger
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbThreadExit()");
       if(state != terminated)
       {
-         ChangeState(terminated);
+         _ChangeState(terminated);
          targetProcessId = 0;
          ClearBreakDisplay();
 
@@ -3111,13 +3304,14 @@ class Debugger
             ide.Update(null);
             HideDebuggerViews();
          }
-         //ChangeState(terminated);
+         //_ChangeState(terminated);
       }
    }
 
    void GdbThreadMain(char * output)
    {
       int i;
+      char * t;
       Array<char *> outTokens { minAllocSize = 50 };
       Array<char *> subTokens { minAllocSize = 50 };
       DebugListItem item { };
@@ -3169,6 +3363,23 @@ class Debugger
                ide.outputView.debugBox.Logf($"Target doesn't contain debug information!\n");
                ide.Update(null);
             }
+            if(!entryPoint && (t = strstr(output, "Entry point:")))
+            {
+               char * addr = t + strlen("Entry point:");
+               t = addr;
+               if(*t++ == ' ' && *t++ == '0' && *t == 'x')
+               {
+                  *addr = '*';
+                  while(isxdigit(*++t));
+                  *t = '\0';
+                  for(bp : sysBPs; bp.type == internalEntry)
+                  {
+                     bp.function = addr;
+                     bp.enabled = entryPoint = true;
+                     break;
+                  }
+               }
+            }
             break;
          case '^':
             gdbReady = false;
@@ -3179,7 +3390,7 @@ class Debugger
                   if(sentKill)
                   {
                      sentKill = false;
-                     ChangeState(loaded);
+                     _ChangeState(loaded);
                      targetProcessId = 0;
                      if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
                      {
@@ -3406,10 +3617,11 @@ class Debugger
             {
                waitingForPID = true;
                setWaitingForPID = true;
+               ClearBreakDisplay();
             }
             else if(!strcmp(outTokens[0], "^exit"))
             {
-               ChangeState(terminated);
+               _ChangeState(terminated);
                // ide.outputView.debugBox.Logf("Exit\n");
                // ide.Update(null);
                gdbReady = true;
@@ -3447,12 +3659,12 @@ class Debugger
                      }
                      else if(!strcmp(item.value, "Cannot find bounds of current function"))
                      {
-                        ChangeState(stopped);
+                        _ChangeState(stopped);
                         gdbHandle.Printf("-exec-continue\n");
                      }
                      else if(!strcmp(item.value, "ptrace: No such process."))
                      {
-                        ChangeState(loaded);
+                        _ChangeState(loaded);
                         targetProcessId = 0;
                      }
                      else if(!strcmp(item.value, "Function \\\"WinMain\\\" not defined."))
@@ -3460,17 +3672,17 @@ class Debugger
                      }
                      else if(!strcmp(item.value, "You can't do that without a process to debug."))
                      {
-                        ChangeState(loaded);
+                        _ChangeState(loaded);
                         targetProcessId = 0;
                      }
                      else if(strstr(item.value, "No such file or directory."))
                      {
-                        ChangeState(loaded);
+                        _ChangeState(loaded);
                         targetProcessId = 0;
                      }
                      else if(strstr(item.value, "During startup program exited with code "))
                      {
-                        ChangeState(loaded);
+                        _ChangeState(loaded);
                         targetProcessId = 0;
                      }
                      else
@@ -3530,7 +3742,7 @@ class Debugger
                else if(!strcmp(outTokens[0], "*stopped"))
                {
                   int tk;
-                  ChangeState(stopped);
+                  _ChangeState(stopped);
 
                   for(tk = 1; tk < outTokens.count; tk++)
                   {
@@ -3557,71 +3769,18 @@ class Debugger
                               HandleExit(reason, exitCode);
                               needReset = true;
                            }
-                           else if(!strcmp(reason, "breakpoint-hit"))
-                           {
-      #ifdef _DEBUG
-                              if(stopItem)
-                                 _dpl(0, "problem");
-      #endif
-                              stopItem = GdbDataStop { };
-
-                              for(i = tk+1; i < outTokens.count; i++)
-                              {
-                                 TokenizeListItem(outTokens[i], item);
-                                 StripQuotes(item.value, item.value);
-                                 if(!strcmp(item.name, "bkptno"))
-                                    stopItem.bkptno = atoi(item.value);
-                                 else if(!strcmp(item.name, "thread-id"))
-                                    stopItem.threadid = atoi(item.value);
-                                 else if(!strcmp(item.name, "frame"))
-                                 {
-                                    item.value = StripCurlies(item.value);
-                                    ParseFrame(stopItem.frame, item.value);
-                                 }
-                                 else if(!strcmp(item.name, "disp") || !strcmp(item.name, "stopped-threads") || !strcmp(item.name, "core"))
-                                    _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "(", item.name, "=", item.value, ")");
-                                 else
-                                    _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown breakpoint hit item name (", item.name, "=", item.value, ")");
-                              }
-
-                              event = hit;
-                           }
-                           else if(!strcmp(reason, "end-stepping-range"))
+                           else if(!strcmp(reason, "breakpoint-hit") ||
+                                   !strcmp(reason, "function-finished") ||
+                                   !strcmp(reason, "end-stepping-range") ||
+                                   !strcmp(reason, "location-reached") ||
+                                   !strcmp(reason, "signal-received"))
                            {
-      #ifdef _DEBUG
-                              if(stopItem)
-                                 _dpl(0, "problem");
-      #endif
-                              stopItem = GdbDataStop { };
-
-                              for(i = tk+1; i < outTokens.count; i++)
-                              {
-                                 TokenizeListItem(outTokens[i], item);
-                                 StripQuotes(item.value, item.value);
-                                 if(!strcmp(item.name, "thread-id"))
-                                    stopItem.threadid = atoi(item.value);
-                                 else if(!strcmp(item.name, "frame"))
-                                 {
-                                    item.value = StripCurlies(item.value);
-                                    ParseFrame(stopItem.frame, item.value);
-                                 }
-                                 else if(!strcmp(item.name, "reason") || !strcmp(item.name, "bkptno"))
-                                    _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "(", item.name, "=", item.value, ")");
-                                 else
-                                    _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown end of stepping range item name (", item.name, "=", item.value, ")");
-                              }
-
-                              event = stepEnd;
-                              ide.Update(null);
-                           }
-                           else if(!strcmp(reason, "function-finished"))
-                           {
-      #ifdef _DEBUG
-                              if(stopItem)
-                                 _dpl(0, "problem");
-      #endif
+                              char r = reason[0];
+#ifdef _DEBUG
+                              if(stopItem) _dpl(0, "problem");
+#endif
                               stopItem = GdbDataStop { };
-                              stopItem.reason = CopyString(reason);
+                              stopItem.reason = r == 'b' ? breakpointHit : r == 'f' ? functionFinished : r == 'e' ? endSteppingRange : r == 'l' ? locationReached : signalReceived;
 
                               for(i = tk+1; i < outTokens.count; i++)
                               {
@@ -3634,45 +3793,27 @@ class Debugger
                                     item.value = StripCurlies(item.value);
                                     ParseFrame(stopItem.frame, item.value);
                                  }
-                                 else if(!strcmp(item.name, "gdb-result-var"))
+                                 else if(stopItem.reason == breakpointHit && !strcmp(item.name, "bkptno"))
+                                    stopItem.bkptno = atoi(item.value);
+                                 else if(stopItem.reason == functionFinished && !strcmp(item.name, "gdb-result-var"))
                                     stopItem.gdbResultVar = CopyString(item.value);
-                                 else if(!strcmp(item.name, "return-value"))
+                                 else if(stopItem.reason == functionFinished && !strcmp(item.name, "return-value"))
                                     stopItem.returnValue = CopyString(item.value);
-                                 else
-                                    _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown function finished item name (", item.name, "=", item.value, ")");
-                              }
-
-                              event = functionEnd;
-                              ide.Update(null);
-                           }
-                           else if(!strcmp(reason, "signal-received"))
-                           {
-      #ifdef _DEBUG
-                              if(stopItem)
-                                 _dpl(0, "problem");
-      #endif
-                              stopItem = GdbDataStop { };
-                              stopItem.reason = CopyString(reason);
-
-                              for(i = tk+1; i < outTokens.count; i++)
-                              {
-                                 TokenizeListItem(outTokens[i], item);
-                                 StripQuotes(item.value, item.value);
-                                 if(!strcmp(item.name, "signal-name"))
+                                 else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-name"))
                                     stopItem.name = CopyString(item.value);
-                                 else if(!strcmp(item.name, "signal-meaning"))
+                                 else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-meaning"))
                                     stopItem.meaning = CopyString(item.value);
-                                 else if(!strcmp(item.name, "thread-id"))
-                                    stopItem.threadid = atoi(item.value);
-                                 else if(!strcmp(item.name, "frame"))
-                                 {
-                                    item.value = StripCurlies(item.value);
-                                    ParseFrame(stopItem.frame, item.value);
-                                 }
+                                 else if(!strcmp(item.name, "stopped-threads"))
+                                    _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Advanced thread debugging not handled");
+                                 else if(!strcmp(item.name, "core"))
+                                    _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Information (core) not used");
+                                 else if(!strcmp(item.name, "disp"))
+                                    _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": (", item.name, "=", item.value, ")");
                                  else
-                                    _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown signal reveived item name (", item.name, "=", item.value, ")");
+                                    _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown ", reason, " item name (", item.name, "=", item.value, ")");
                               }
-                              if(!strcmp(stopItem.name, "SIGTRAP"))
+
+                              if(stopItem.reason == signalReceived && !strcmp(stopItem.name, "SIGTRAP"))
                               {
                                  switch(breakType)
                                  {
@@ -3688,7 +3829,8 @@ class Debugger
                               }
                               else
                               {
-                                 event = signal;
+                                 event = r == 'b' ? hit : r == 'f' ? functionEnd : r == 'e' ? stepEnd : r == 'l' ? locationReached : signal;
+                                 ide.Update(null);
                               }
                            }
                            else if(!strcmp(reason, "watchpoint-trigger"))
@@ -3699,8 +3841,6 @@ class Debugger
                               _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason access watchpoint trigger not handled");
                            else if(!strcmp(reason, "watchpoint-scope"))
                               _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint scope not handled");
-                           else if(!strcmp(reason, "location-reached"))
-                              _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason location reached not handled");
                            else
                               _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown reason: ", reason);
                         }
@@ -3736,14 +3876,14 @@ class Debugger
                   }
 
                   if(targetProcessId)
-                     ChangeState(running);
+                     _ChangeState(running);
                   else if(!oldProcessID)
                   {
                      ide.outputView.debugBox.Logf($"Debugger Error: No target process ID\n");
                      // TO VERIFY: The rest of this block has not been thoroughly tested in this particular location
                      gdbHandle.Printf("-gdb-exit\n");
                      gdbTimer.Stop();
-                     ChangeState(terminated); //loaded;
+                     _ChangeState(terminated); //loaded;
                      prjConfig = null;
 
                      if(ide.workspace)
@@ -3895,7 +4035,9 @@ class Debugger
                      match = !fstrcmp(prjTargetPath, path);
                   }
                }
-               if(!match)
+               if(match)
+                  projectsLibraryLoaded[prj.name] = true;
+               else
                   ide.outputView.debugBox.Logf($"Loaded library %s doesn't match the %s target of the %s added project.\n", path, prjTargetPath, prj.topNode.name);
                break;
             }
@@ -3922,7 +4064,7 @@ class Debugger
 
    ExpressionType ::DebugEvalExpTypeError(char * result)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::DebugEvalExpTypeError()");
+      _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::DebugEvalExpTypeError()");
       if(result)
          return dummyExp;
       switch(eval.error)
@@ -3938,7 +4080,7 @@ class Debugger
    char * ::EvaluateExpression(char * expression, ExpressionType * error)
    {
       char * result;
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::EvaluateExpression(", expression, ")");
+      _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateExpression(", expression, ")");
       if(ide.projectView && ide.debugger.state == stopped)
       {
          result = GdbEvaluateExpression(expression);
@@ -4333,7 +4475,7 @@ class Frame : struct
 
 class GdbDataStop : struct
 {
-   char * reason;
+   DebuggerReason reason;
    int threadid;
    union
    {
@@ -4358,17 +4500,16 @@ class GdbDataStop : struct
    {
       if(reason)
       {
-         if(!strcmp(reason, "signal-received"))
+         if(reason == signalReceived)
          {
             delete name;
             delete meaning;
          }
-         else if(!strcmp(reason, "function-finished"))
+         else if(reason == functionFinished)
          {
             delete gdbResultVar;
             delete returnValue;
          }
-         delete reason;
       }
       if(frame) frame.Free();
    }
@@ -4438,6 +4579,8 @@ class Breakpoint : struct
    property char * relativeFilePath { set { delete relativeFilePath; if(value) relativeFilePath = CopyString(value); } }
    char * absoluteFilePath;
    property char * absoluteFilePath { set { delete absoluteFilePath; if(value) absoluteFilePath = CopyString(value); } }
+   char * location;
+   property char * location { set { delete location; if(value) location = CopyString(value); } }
    int line;
    bool enabled;
    int hits;
@@ -4449,6 +4592,69 @@ class Breakpoint : struct
    BreakpointType type;
    DataRow row;
    GdbDataBreakpoint bp;
+   Project project;
+
+   void ParseLocation()
+   {
+      char * prjName = null;
+      char * filePath = null;
+      char * file;
+      char * line;
+      char fullPath[MAX_LOCATION];
+      ProjectNode node;
+      if(location[0] == '\(' && location[1] && (file = strchr(location+2, '\)')) && file[1])
+      {
+         prjName = new char[file-location];
+         strncpy(prjName, location+1, file-location-1);
+         prjName[file-location-1] = '\0';
+         file++;
+      }
+      else
+         file = location;
+      if((line = strchr(file+1, ':')))
+      {
+         filePath = new char[strlen(file)+1];
+         strncpy(filePath, file, line-file);
+         filePath[line-file] = '\0';
+         line++;
+      }
+      else
+         filePath = CopyString(file);
+      property::relativeFilePath = filePath;
+      if(prjName)
+      {
+         for(prj : ide.workspace.projects)
+         {
+            if(!strcmp(prjName, prj.name))
+            {
+               node = prj.topNode.FindWithPath(filePath, false);
+               if(node)
+               {
+                  node.GetFullFilePath(fullPath);
+                  property::absoluteFilePath = fullPath;
+                  project = prj;
+                  break;
+               }
+            }
+         }
+         if(line[0])
+            this.line = atoi(line);
+      }
+      else
+      {
+         node = ide.projectView.project.topNode.Find(filePath, false);
+         if(node)
+         {
+            node.GetFullFilePath(fullPath);
+            property::absoluteFilePath = fullPath;
+         }
+         project = ide.project;
+      }
+      if(!absoluteFilePath)
+         property::absoluteFilePath = "";
+      delete prjName;
+      delete filePath;
+   }
 
    char * CopyLocationString(bool removePath)
    {
@@ -4480,7 +4686,7 @@ class Breakpoint : struct
       char * location;
       char * loc = CopyLocationString(false);
       Project prj = null;
-      for(p : ide.workspace.projects)
+      for(p : ide.workspace.projects; p != ide.workspace.projects.firstIterator.data)
       {
          if(p.topNode.FindByFullPath(absoluteFilePath, false))
          {
@@ -4502,7 +4708,9 @@ class Breakpoint : struct
    {
       if(relativeFilePath && relativeFilePath[0])
       {
-         f.Printf("    * %d,%d,%d,%d,%s\n", enabled ? 1 : 0, ignore, level, line, relativeFilePath);
+         char * location = CopyUserLocationString();
+         f.Printf("    * %d,%d,%d,%d,%s\n", enabled ? 1 : 0, ignore, level, line, location);
+         delete location;
          if(condition)
             f.Printf("       ~ %s\n", condition.expression);
       }
@@ -4516,6 +4724,7 @@ class Breakpoint : struct
       delete function;
       delete relativeFilePath;
       delete absoluteFilePath;
+      delete location;
    }
 
    ~Breakpoint()