extras: improve debug print line (dpl) debugging tools (111d8299ce536c62d57c1dc06ea81...
[sdk] / ide / src / debugger / Debugger.ec
index 1f495a3..408450e 100644 (file)
@@ -13,6 +13,7 @@ import "debugTools"
 
 #ifdef _DEBUG
 #define GDB_DEBUG_CONSOLE
+#define _DPL_ON
 #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 <string.h> // For memchr
 
 #ifdef __APPLE__
 #define __unix__
@@ -33,34 +35,12 @@ extern char * strrchr(const char * s, int c);
 #undef uint
 #undef strlen
 
-char * PrintNow()
-{
-   int c;
-   char * s[6];
-   char * time;
-   DateTime now;
-   now.GetLocalTime();
-   for(c=0; c<6; c++)
-      s[c] = new char[8];
-   sprintf(s[0], "%04d", now.year);
-   sprintf(s[1], "%02d", now.month+1);
-   sprintf(s[2], "%02d", now.day);
-   sprintf(s[3], "%02d", now.hour);
-   sprintf(s[4], "%02d", now.minute);
-   sprintf(s[5], "%02d", now.second);
-   time = PrintString("*", s[0], s[1], s[2], "-", s[3], s[4], s[5], "*");
-   for(c=0; c<6; c++)
-      delete s[c];
-   return time;
-}
-
+#include <dpl.eh>
+#ifdef _DPL_ON
 // 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 };
-#else
-static enum dplchan { none, gdbProtoIgnored=0, gdbProtoUnknown=0, gdbOutput=0, gdbCommand=0, debuggerCall=0, debuggerProblem=0, debuggerTemp=0 };
-#endif
-static char * _dpct[] = {
+static enum dplchan { none, gdbProtoIgnored=0/*1*/, gdbProtoUnknown=2, gdbOutput=3/*3*/, gdbCommand=4/*4*/, debuggerCall=0/*5*/, debuggerProblem=6,
+                        debuggerUserAction=7,debuggerState=8, debuggerBreakpoints=9, debuggerWatches=0/*10*/, debuggerTemp=0 };
+static const char * _dpct[] = {
    null,
    "GDB Protocol Ignored",
    "GDB Protocol ***Unknown***",
@@ -68,64 +48,14 @@ 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)
-
-#define _dpl2(...) __dpl2(__FILE__, __LINE__, ##__VA_ARGS__)
-static void __dpl2(char * file, int line, char ** channels, int channel, int indent, typed_object object, ...)
-{
-   bool chan = channel && channels && channels[channel];
-   if(chan || !channels)
-   {
-      char string[MAX_F_STRING];
-      int len;
-      char * time = PrintNow();
-      va_list args;
-      //ide.outputView.debugBox.Logf();
-      Logf("%s %s:% 5d: %s%s", time, file, line, chan ? channels[channel] : "", chan && channels[channel][0] ? ": " : "");
-      va_start(args, object);
-      len = PrintStdArgsToBuffer(string, sizeof(string), object, args);
-      Log(string);
-      va_end(args);
-      Log("\n");
-      delete time;
-   }
-}
-
-#define _dpl(...) __dpl(__FILE__, __LINE__, ##__VA_ARGS__)
-static void __dpl(char * file, int line, int indent, char * format, ...)
-{
-   va_list args;
-   char string[MAX_F_STRING];
-   int c;
-   char * time = PrintNow();
-   //static File f = null;
-   va_start(args, format);
-   vsnprintf(string, sizeof(string), format, args);
-   string[sizeof(string)-1] = 0;
-   /*if(!f)
-   {
-      char * time = PrintNow();
-      char * logName;
-      logName = PrintString(time, ".log");
-      delete time;
-      f = FileOpen(logName, write);
-      delete logName;
-   }*/
-   /*f.Printf("%s %s:% 5d: ", time, file, line);
-   for(c = 0; c<indent; c++)
-      f.Putc(' ');
-   f.Printf("%s\n", string);*/
-   Logf("%s %s:% 5d: ", time, file, line);
-   for(c = 0; c<indent; c++)
-      Log(" ");
-   Logf("%s\n", string);
-   va_end(args);
-   delete time;
-}
+#endif
 
 public char * StripQuotes2(char * string, char * output)
 {
@@ -133,7 +63,7 @@ public char * StripQuotes2(char * string, char * output)
    int d = 0;
    bool quoted = false, escaped = false;
    char ch;
-   for(c = 0; ch = string[c]; c++)
+   for(c = 0; (ch = string[c]); c++)
    {
       if(quoted)
       {
@@ -157,71 +87,44 @@ public char * StripQuotes2(char * string, char * output)
 // String Escape Copy
 static void strescpy(char * d, char * s)
 {
-   int j, k;
-   j = k = 0;
-   while(s[j])
+   int j = 0, k = 0;
+   char ch;
+   while((ch = s[j]))
    {
-      switch(s[j])
+      switch(ch)
       {
-         case '\n':
-            d[k] = '\\';
-            d[++k] = 'n';
-            break;
-         case '\t':
-            d[k] = '\\';
-            d[++k] = 't';
-            break;
-         case '\a':
-            d[k] = '\\';
-            d[++k] = 'a';
-            break;
-         case '\b':
-            d[k] = '\\';
-            d[++k] = 'b';
-            break;
-         case '\f':
-            d[k] = '\\';
-            d[++k] = 'f';
-            break;
-         case '\r':
-            d[k] = '\\';
-            d[++k] = 'r';
-            break;
-         case '\v':
-            d[k] = '\\';
-            d[++k] = 'v';
-            break;
-         case '\\':
-            d[k] = '\\';
-            d[++k] = '\\';
-            break;
-         case '\"':
-            d[k] = '\\';
-            d[++k] = '\"';
-            break;
-         default:
-            d[k] = s[j];
+         case '\n': d[k] = '\\'; d[++k] = 'n'; break;
+         case '\t': d[k] = '\\'; d[++k] = 't'; break;
+         case '\a': d[k] = '\\'; d[++k] = 'a'; break;
+         case '\b': d[k] = '\\'; d[++k] = 'b'; break;
+         case '\f': d[k] = '\\'; d[++k] = 'f'; break;
+         case '\r': d[k] = '\\'; d[++k] = 'r'; break;
+         case '\v': d[k] = '\\'; d[++k] = 'v'; break;
+         case '\\': d[k] = '\\'; d[++k] = '\\'; break;
+         case '\"': d[k] = '\\'; d[++k] = '\"'; break;
+         default: d[k] = s[j];
       }
-      ++j;
-      ++k;
+      j++, k++;
    }
-   d[k] = s[j];
+   d[k] = '\0';
 }
 
-static char * CopyUnescapedSystemPath(char * p)
+/*static char * CopyUnescapedSystemPath(char * p)
 {
-   char * d = new char[strlen(p) + 1];
-   struscpy(d, p);
+   int len = strlen(p);
+   char * d = new char[len + 1];
+   UnescapeString(d, p, len);
 #if defined(__WIN32__)
    ChangeCh(d, '/', '\\');
 #endif
    return d;
-}
+}*/
 
 static char * CopyUnescapedUnixPath(char * p)
 {
-   char * d = new char[strlen(p) + 1];
-   struscpy(d, p);
+   int len = strlen(p);
+   char * d = new char[len + 1];
+   UnescapeString(d, p, len);
 #if defined(__WIN32__)
    ChangeCh(d, '\\', '/');
 #endif
@@ -230,68 +133,12 @@ static char * CopyUnescapedUnixPath(char * p)
 
 static char * CopyUnescapedString(char * s)
 {
-   char * d = new char[strlen(s) + 1];
-   struscpy(d, s);
+   int len = strlen(s);
+   char * d = new char[len + 1];
+   UnescapeString(d, s, len);
    return d;
 }
 
-// String Unescape Copy
-
-// TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
-// Seems very similar to ReadString in pass15.ec (which also misses numeric escape codes :) )
-
-static void struscpy(char * d, char * s)
-{
-   int j, k;
-   j = k = 0;
-   while(s[j])
-   {
-      switch(s[j])
-      {
-         case '\\':
-            switch(s[++j])
-            {
-               case 'n':
-                  d[k] = '\n';
-                  break;
-               case 't':
-                  d[k] = '\t';
-                  break;
-               case 'a':
-                  d[k] = '\a';
-                  break;
-               case 'b':
-                  d[k] = '\b';
-                  break;
-               case 'f':
-                  d[k] = '\f';
-                  break;
-               case 'r':
-                  d[k] = '\r';
-                  break;
-               case 'v':
-                  d[k] = '\v';
-                  break;
-               case '\\':
-                  d[k] = '\\';
-                  break;
-               case '\"':
-                  d[k] = '\"';
-                  break;
-               default:
-                  d[k] = '\\';
-                  d[++k] = s[j];
-            }
-            break;
-         default:
-            d[k] = s[j];
-      }
-      ++j;
-      ++k;
-   }
-   d[k] = s[j];
-}
-
 static char * StripBrackets(char * string)
 {
    int length = strlen(string);
@@ -318,7 +165,7 @@ static char * StripCurlies(char * string)
       return string;
 }
 
-static int StringGetInt(char * string, int start)
+/*static int StringGetInt(char * string, int start)
 {
    char number[8];
    int i, len = strlen(string);
@@ -331,15 +178,15 @@ static int StringGetInt(char * string, int start)
          break;
    }
    return atoi(number);
-}
+}*/
 
 static int TokenizeList(char * string, const char seperator, Array<char *> tokens)
 {
    uint level = 0;
-   
+
    bool quoted = false, escaped = false;
    char * start = string, ch;
-   
+
    for(; (ch = *string); string++)
    {
       if(!start)
@@ -384,11 +231,9 @@ static bool TokenizeListItem(char * string, DebugListItem item)
       *equal = '\0';
       equal++;
       item.value = equal;
-      equal = null;
       return true;
    }
-   else
-      return false;
+   return false;
 }
 
 static bool CheckCommandAvailable(const char * command)
@@ -417,6 +262,7 @@ static bool CheckCommandAvailable(const char * command)
                if(fl.stats.attribs.isFile && !fstrcmp(fl.name, name))
                {
                   available = true;
+                  fl.Stop();
                   break;
                }
             }
@@ -442,19 +288,35 @@ 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;
+   property bool breaksOnInternalBreakpoint { get { return (this == stepInto || this == stepOver || this == stepUntil); } };
+};
+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 };
 
@@ -479,11 +341,8 @@ class Debugger
    bool sentKill;
    bool sentBreakInsert;
    bool ignoreBreakpoints;
-   bool userBreakOnInternalBreakpoint;
-   //bool runToCursorDebugStart;
    bool signalOn;
    bool needReset;
-   //bool watchesInit;
    bool usingValgrind;
 
    int ideProcessId;
@@ -497,18 +356,24 @@ 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;
    GdbDataBreakpoint bpItem;
    Frame activeFrame;
-   
+
    List<Breakpoint> sysBPs { };
    Breakpoint bpRunToCursor;
+   Breakpoint intBpEntry;
+   Breakpoint intBpMain;
+   Breakpoint intBpWinMain;
 
    OldList stackFrames;
 
@@ -521,6 +386,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 +407,55 @@ class Debugger
 
          event = none;
          if(this.stopItem)
+         {
             this.stopItem = null;
+#ifdef _DPL_ON
+            {
+               char * s = null;
+               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;
+               _dpcl(_dpct, dplchan::debuggerBreakpoints, 0, "gdbTimer::DelayExpired: ", s+1);
+
+               if(stopItem.bkptno)
+               {
+                  bool isInternal;
+                  Breakpoint bp = GetBreakpointById(stopItem.bkptno, &isInternal);
+                  if(bp)
+                  {
+                     _dpcl(_dpct, dplchan::debuggerBreakpoints, 0, "gdb stopped by a breakpoint: ", bp.type, "(", s=bp.CopyLocationString(false), ")");
+                     delete s;
+                  }
+               }
+               delete bpReport;
+            }
+#endif
+         }
+#ifdef _DPL_ON
          else
          {
             if(curEvent && curEvent != exit)
             {
-#ifdef _DEBUG
-               _dpl(0, "No stop item");
-#endif
+               _dplf(0, "No stop item");
             }
          }
+#endif
          switch(breakType)
          {
             case restart:
@@ -561,7 +469,7 @@ class Debugger
             case selectFrame:
             {
                breakType = none;
-               GdbCommand(false, "-stack-select-frame %d", activeFrameLevel);
+               GdbCommand(0, false, "-stack-select-frame %d", activeFrameLevel);
                for(activeFrame = stackFrames.first; activeFrame; activeFrame = activeFrame.next)
                   if(activeFrame.level == activeFrameLevel)
                      break;
@@ -569,20 +477,15 @@ class Debugger
             }
             //case bpValidation:
             //   breakType = none;
-            //   GdbCommand(false, "-break-info %s", bpItem.number);
+            //   GdbCommand(0, false, "-break-info %s", bpItem.number);
             //   break;
          }
 
          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 +499,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)
@@ -613,49 +516,38 @@ class Debugger
                         }
                      }
                      else
-                        _dpl2(_dpct, dplchan::debuggerProblem, 0, "Invalid stopItem!");
-                     if(bpUser && strcmp(stopItem.frame.addr, bpUser.bp.addr))
-                        bpUser = null;
+                        _dpcl(_dpct, dplchan::debuggerProblem, 0, "Invalid stopItem!");
+                     if(bpUser && stopItem.frame.addr && strcmp(stopItem.frame.addr, bpUser.bp.addr))
+                        _dpcl(_dpct, dplchan::debuggerProblem, 0, "Breakpoint bkptno(", stopItem.bkptno, ") address missmatch!");
                   }
                   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))
+                     _dpcl(_dpct, dplchan::debuggerProblem, 0, "Breakpoint bkptno(", stopItem.bkptno, ") invalid or not found!");
+                  if((bpUser && !ignoreBreakpoints) || (bpInternal && userAction.breaksOnInternalBreakpoint))
                      monitor = true;
                   hitThread = stopItem.threadid;
                }
                break;
             case signal:
                signalThread = stopItem.threadid;
+            case breakEvent:
             case stepEnd:
             case functionEnd:
+            case locationReached:
                monitor = true;
                ignoreBreakpoints = false;
                break;
             case valgrindStartPause:
                GdbExecContinue(true);
+               monitor = false;
                break;
             case exit:
                HideDebuggerViews();
                break;
          }
 
-         if(monitor)
-         {
-            activeThread = stopItem.threadid;
-            GdbCommand(false, "-thread-list-ids");
-            GdbGetStack();
-            if(activeFrameLevel > 0)
-               GdbCommand(false, "-stack-select-frame %d", activeFrameLevel);
-
-            WatchesCodeEditorLinkInit();
-            EvaluateWatches();
-         }
-
          if(curEvent == signal)
          {
-            char * s;
+            char * s = null;
             signalOn = true;
             ide.outputView.debugBox.Logf($"Signal received: %s - %s\n", stopItem.name, stopItem.meaning);
             ide.outputView.debugBox.Logf("    %s:%d\n", (s = CopySystemPath(stopItem.frame.file)), stopItem.frame.line);
@@ -669,26 +561,53 @@ class Debugger
             ide.callStackView.Show();
             ide.callStackView.Activate();
          }
+         else if(curEvent == hit)
+         {
+            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);
+                  monitor = false;
+               }
+            }
+         }
 
          if(monitor && curEvent.canBeMonitored)
          {
-            SelectFrame(activeFrameLevel);
-            GoToStackFrameLine(activeFrameLevel, true);
+            GdbGetStack();
+            activeThread = stopItem.threadid;
+            GdbCommand(0, false, "-thread-list-ids");
+            InternalSelectFrame(activeFrameLevel);
+            GoToStackFrameLine(activeFrameLevel, true, false);
+            EvaluateWatches();
             ide.ShowCodeEditor();
+            ide.AdjustDebugMenus();
             ideMainFrame.Activate();   // TOFIX: ide.Activate() is not reliable (app inactive)
             ide.Update(null);
          }
 
-         if(curEvent == hit)
-            EventHit(stopItem, bpInternal, bpUser);
-
          if(stopItem)
          {
             stopItem.Free();
             delete stopItem;
          }
-         if(userBreakOnInternalBreakpoint)
-            userBreakOnInternalBreakpoint = false;
          return false;
       }
    };
@@ -700,17 +619,39 @@ class Debugger
    ProgramThread progThread { };
 #endif
 
+#ifdef _DPL_ON
+#define _ChangeUserAction(value) ChangeUserAction(__FILE__, __LINE__, value)
+   void ChangeUserAction(const char * file, int line, DebuggerUserAction value)
+   {
+#if 0
+      bool same = value == userAction;
+      __dpl(file, line, _dpct, dplchan::debuggerUserAction, 0, userAction, /*same ? " *** == *** " : */" -> ", value);
+#endif
+      userAction = value;
+   }
+#else
+#define _ChangeUserAction(value) userAction = value
+#endif
+
+#ifdef _DPL_ON
+#define _ChangeState(value) ChangeState(__FILE__, __LINE__, value)
+   void ChangeState(const 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, ")");
+#if 0 //def _DPL_ON
+      __dpl(file, line, _dpct, dplchan::debuggerState, 0, state, same ? " *** == *** " : " -> ", value);
+#endif
       state = value;
-      if(!same && ide) ide.AdjustDebugMenus();
+      if(!same) ide.AdjustDebugMenus();
    }
 
    void CleanUp()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::CleanUp");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::CleanUp");
 
       stackFrames.Free(Frame::Free);
 
@@ -729,8 +670,6 @@ class Debugger
       sentKill = false;
       sentBreakInsert = false;
       ignoreBreakpoints = false;
-      userBreakOnInternalBreakpoint = false;
-      //runToCursorDebugStart = false;
       signalOn = false;
 
       activeFrameLevel = 0;
@@ -741,33 +680,38 @@ class Debugger
 
       targetDir = null;
       targetFile = null;
-      
-      ChangeState(none);
+
+      _ChangeState(none);
       event = none;
       breakType = none;
 
-      stopItem = null;
-      bpItem = null;
+      delete stopItem;
+      delete bpItem;
       activeFrame = 0;
-      
+
       bpRunToCursor = null;
 
       delete currentCompiler;
       prjConfig = null;
-      codeEditor = null;
+
+      WatchesReleaseCodeEditor();
+
+      entryPoint = false;
+      projectsLibraryLoaded.Free();
 
       /*GdbThread gdbThread
       Timer gdbTimer*/
    }
-   
+
    Debugger()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::constructor");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::constructor");
       ideProcessId = Process_GetCurrentProcessId();
 
-      sysBPs.Add(Breakpoint { type = internalMain, function = "main", enabled = true, level = -1 });
+      sysBPs.Add((intBpEntry = Breakpoint { type = internalEntry, enabled = false, level = -1 }));
+      sysBPs.Add((intBpMain = Breakpoint { type = internalMain, function = "main", enabled = true, level = -1 }));
 #if defined(__WIN32__)
-      sysBPs.Add(Breakpoint { type = internalWinMain, function = "WinMain", enabled = true, level = -1 });
+      sysBPs.Add((intBpWinMain = Breakpoint { type = internalWinMain, function = "WinMain", enabled = true, level = -1 }));
 #endif
       sysBPs.Add(Breakpoint { type = internalModulesLoaded, enabled = true, level = -1 });
       sysBPs.Add(Breakpoint { type = internalModuleLoad, function = "InternalModuleLoadBreakpoint", enabled = true, level = -1 });
@@ -775,7 +719,7 @@ class Debugger
 
    ~Debugger()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::destructor");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::destructor");
       sysBPs.Free();
       Stop();
       CleanUp();
@@ -788,13 +732,15 @@ class Debugger
 
    void Resume()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Resume");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::Resume");
+      _ChangeUserAction(resume);
       GdbExecContinue(true);
    }
 
    void Break()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Break");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::Break");
+      _ChangeUserAction(_break);
       if(state == running)
       {
          if(targetProcessId)
@@ -804,7 +750,8 @@ class Debugger
 
    void Stop()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Stop");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::Stop");
+      _ChangeUserAction(stop);
       switch(state)
       {
          case running:
@@ -827,36 +774,36 @@ class Debugger
 
    void Restart(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Restart");
-      if(StartSession(compiler, config, bitDepth, useValgrind, true, false, false/*, false*/) == loaded)
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::Restart");
+      _ChangeUserAction(restart);
+      if(StartSession(compiler, config, bitDepth, useValgrind, true, false) == loaded)
          GdbExecRun();
    }
 
    bool GoToCodeLine(char * location)
    {
       CodeLocation codloc;
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GoToCodeLine(", location, ")");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GoToCodeLine(", location, ")");
       codloc = CodeLocation::ParseCodeLocation(location);
       if(codloc)
       {
-         CodeEditor editor = (CodeEditor)ide.OpenFile(codloc.absoluteFile, normal, true, null, no, normal, false);
+         CodeEditor editor = (CodeEditor)ide.OpenFile(codloc.absoluteFile, false, true, null, no, normal, false);
          if(editor)
          {
             EditBox editBox = editor.editBox;
-            editBox.GoToLineNum(codloc.line - 1);
-            editBox.GoToPosition(editBox.line, codloc.line - 1, 0);
+            if(editBox.GoToLineNum(codloc.line - 1))
+               editBox.GoToPosition(editBox.line, codloc.line - 1, 0);
             return true;
          }
       }
       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, ")");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GoToStackFrameLine(", stackLevel, ", ", askForLocation, ")");
       if(ide)
       {
-         char filePath[MAX_LOCATION];
          char sourceDir[MAX_LOCATION];
          Frame frame;
          CodeEditor editor = null;
@@ -867,13 +814,16 @@ class Debugger
                break;
          if(frame)
          {
-            ide.callStackView.Show();
+            if(!fromCallStack)
+               ide.callStackView.Show();
 
-            if(!frame.absoluteFile && frame.file)
-               frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
+            if(frame.absoluteFile)
+               editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, false, true, null, no, normal, false);
+            if(!editor && frame.file)
+               frame.absoluteFile = ide.workspace.CopyAbsolutePathFromRelative(frame.file);
             if(!frame.absoluteFile && askForLocation && frame.file)
             {
-               char * s;
+               char * s = null;
                char title[MAX_LOCATION];
                snprintf(title, sizeof(title), $"Provide source file location for %s", (s = CopySystemPath(frame.file)));
                title[sizeof(title)-1] = 0;
@@ -881,11 +831,13 @@ class Debugger
                if(SourceDirDialog(title, ide.workspace.projectDir, frame.file, sourceDir))
                {
                   AddSourceDir(sourceDir);
-                  frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
+                  frame.absoluteFile = ide.workspace.CopyAbsolutePathFromRelative(frame.file);
                }
             }
-            if(frame.absoluteFile)
-               editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal, false);
+            if(!editor && frame.absoluteFile)
+               editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, false, true, null, no, normal, false);
+            if(editor)
+               ide.RepositionWindows(false);
             ide.Update(null);
             if(editor && frame.line)
             {
@@ -901,20 +853,18 @@ class Debugger
 
    void SelectThread(int thread)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectThread(", thread, ")");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectThread(", thread, ")");
+      _ChangeUserAction(selectThread);
       if(state == stopped)
       {
          if(thread != activeThread)
          {
             activeFrameLevel = -1;
             ide.callStackView.Clear();
-            GdbCommand(false, "-thread-select %d", thread);
+            GdbCommand(0, false, "-thread-select %d", thread);
             GdbGetStack();
-            // Why was SelectFrame missing here?
-            SelectFrame(activeFrameLevel);
-            GoToStackFrameLine(activeFrameLevel, true);
-            WatchesCodeEditorLinkRelease();
-            WatchesCodeEditorLinkInit();
+            InternalSelectFrame(activeFrameLevel);
+            GoToStackFrameLine(activeFrameLevel, true, false);
             EvaluateWatches();
             ide.Update(null);
          }
@@ -924,32 +874,35 @@ class Debugger
 
    void SelectFrame(int frame)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectFrame(", frame, ")");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectFrame(", frame, ")");
+      _ChangeUserAction(selectFrame);
       if(state == stopped)
       {
-         if(frame != activeFrameLevel || !codeEditor || !codeEditor.visible)
+         if(frame != activeFrameLevel)
          {
-            activeFrameLevel = frame;  // there is no active frame number in the gdb reply
-            GdbCommand(false, "-stack-select-frame %d", activeFrameLevel);
-            for(activeFrame = stackFrames.first; activeFrame; activeFrame = activeFrame.next)
-               if(activeFrame.level == activeFrameLevel)
-                  break;
-
-            WatchesCodeEditorLinkRelease();
-            WatchesCodeEditorLinkInit();
+            InternalSelectFrame(frame);
             EvaluateWatches();
             ide.Update(null);
          }
       }
    }
 
+   void InternalSelectFrame(int frame)
+   {
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::InternalSelectFrame(", frame, ")");
+      activeFrameLevel = frame;  // there is no active frame number in the gdb reply
+      GdbCommand(0, false, "-stack-select-frame %d", activeFrameLevel);
+      for(activeFrame = stackFrames.first; activeFrame; activeFrame = activeFrame.next)
+         if(activeFrame.level == activeFrameLevel)
+            break;
+   }
+
    void HandleExit(char * reason, char * code)
    {
-      bool returnedExitCode = false;
       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
+
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::HandleExit(", reason, ", ", code, ")");
+      _ChangeState(loaded); // this state change seems to be superfluous, might be in case of gdb crash
       targetProcessId = 0;
 
       if(code)
@@ -959,7 +912,7 @@ class Debugger
       }
       else
          verboseExitCode[0] = '\0';
-      
+
       event = exit;
 
       // ClearBreakDisplay();
@@ -1006,11 +959,11 @@ class Debugger
       }
       ide.Update(null);
    }
-      
-   DebuggerState StartSession(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool restart, bool userBreakOnInternalBreakpoint, bool ignoreBreakpoints/*, bool runToCursorDebugStart*/)
+
+   DebuggerState StartSession(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool restart, bool ignoreBreakpoints)
    {
       DebuggerState result = none;
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StartSession(restart(", restart, "), userBreakOnInternalBreakpoint(", userBreakOnInternalBreakpoint, "), ignoreBreakpoints(", ignoreBreakpoints, ")"/*, runToCursorDebugStart(", runToCursorDebugStart, ")"*/);
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::StartSession(restart(", restart, "), ignoreBreakpoints(", ignoreBreakpoints, ")");
       if(restart && state == running && targetProcessId)
       {
          breakType = DebuggerAction::restart;
@@ -1039,32 +992,29 @@ class Debugger
                bp.breaks = 0;
             }
 
-            //this.runToCursorDebugStart = runToCursorDebugStart;
-
             if(GdbInit(compiler, config, bitDepth, useValgrind))
                result = state;
             else
                result = error;
          }
          this.ignoreBreakpoints = ignoreBreakpoints;
-         this.userBreakOnInternalBreakpoint = userBreakOnInternalBreakpoint;
-         if(ignoreBreakpoints && (result == loaded || result == stopped))
-            GdbBreakpointsDelete(false, false);
       }
       return result;
    }
 
    void Start(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Start()");
-      if(StartSession(compiler, config, bitDepth, useValgrind, true, false, false/*, false*/) == loaded)
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::Start()");
+      _ChangeUserAction(start);
+      if(StartSession(compiler, config, bitDepth, useValgrind, true, false) == loaded)
          GdbExecRun();
    }
 
    void StepInto(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepInto()");
-      switch(StartSession(compiler, config, bitDepth, useValgrind, false, true, false/*, false*/))
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::StepInto()");
+      _ChangeUserAction(stepInto);
+      switch(StartSession(compiler, config, bitDepth, useValgrind, false, false))
       {
          case loaded:  GdbExecRun();  break;
          case stopped: GdbExecStep(); break;
@@ -1073,38 +1023,47 @@ class Debugger
 
    void StepOver(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool ignoreBreakpoints)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOver()");
-      switch(StartSession(compiler, config, bitDepth, useValgrind, false, true, ignoreBreakpoints/*, false*/))
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOver()");
+      _ChangeUserAction(stepOver);
+      switch(StartSession(compiler, config, bitDepth, useValgrind, false, ignoreBreakpoints))
       {
          case loaded:  GdbExecRun();  break;
          case stopped: GdbExecNext(); break;
       }
    }
 
+   void StepUntil(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool ignoreBreakpoints)
+   {
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::StepUntil()");
+      _ChangeUserAction(stepUntil);
+      switch(StartSession(compiler, config, bitDepth, useValgrind, false, ignoreBreakpoints))
+      {
+         case loaded:  GdbExecRun();          break;
+         case stopped: GdbExecUntil(null, 0); break;
+      }
+   }
+
    void StepOut(bool ignoreBreakpoints)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOut()");
+      _dpcl(_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, const 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");
-      //}
-      if(!ide.projectView.project.GetRelativePath(absoluteFilePath, relativeFilePath))
-         strcpy(relativeFilePath, absoluteFilePath);
+      const char * objectFileExt = compiler ? compiler.objectFileExt : objectDefaultFileExt;
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::RunToCursor()");
+      _ChangeUserAction(runToCursor);
+      ide.workspace.GetRelativePath(absoluteFilePath, relativeFilePath, null, objectFileExt);
 
       if(bpRunToCursor && bpRunToCursor.inserted && symbols)
       {
@@ -1112,28 +1071,43 @@ 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, ignoreBreakpoints);
 
-      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);
+         }
       }
    }
 
    void GetCallStackCursorLine(bool * error, int * lineCursor, int * lineTopFrame)
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GetCallStackCursorLine()");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GetCallStackCursorLine()");
       if(activeFrameLevel == -1)
       {
          *error = false;
@@ -1148,13 +1122,13 @@ class Debugger
       }
    }
 
-   int GetMarginIconsLineNumbers(char * fileName, int lines[], bool enabled[], int max, bool * error, int * lineCursor, int * lineTopFrame)
+   int GetMarginIconsLineNumbers(const char * fileName, int lines[], bool enabled[], int max, bool * error, int * lineCursor, int * lineTopFrame)
    {
       char winFilePath[MAX_LOCATION];
       char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
       int count = 0;
       Iterator<Breakpoint> it { ide.workspace.breakpoints };
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GetMarginIconsLineNumbers()");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GetMarginIconsLineNumbers()");
       while(it.Next() && count < max)
       {
          Breakpoint bp = it.data;
@@ -1187,7 +1161,7 @@ class Debugger
             *lineTopFrame = stopItem.frame.line;
          else
             *lineTopFrame = 0;
-         
+
          if(*lineTopFrame == *lineCursor && *lineTopFrame)
             *lineTopFrame = 0;
       }
@@ -1196,8 +1170,8 @@ class Debugger
 
    void ChangeWatch(DataRow row, char * expression)
    {
-      Watch wh = (Watch)row.tag;
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ChangeWatch(", expression, ")");
+      Watch wh = (Watch)(intptr)row.tag;
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::ChangeWatch(", expression, ")");
       if(wh)
       {
          delete wh.expression;
@@ -1213,7 +1187,7 @@ class Debugger
       else if(expression)
       {
          wh = Watch { };
-         row.tag = (int64)wh;
+         row.tag = (int64)(intptr)wh;
          ide.workspace.watches.Add(wh);
          wh.row = row;
          wh.expression = CopyString(expression);
@@ -1224,16 +1198,16 @@ class Debugger
          ResolveWatch(wh);
    }
 
-   void MoveIcons(char * fileName, int lineNumber, int move, bool start)
+   void MoveIcons(const char * fileName, int lineNumber, int move, bool start)
    {
       char winFilePath[MAX_LOCATION];
-      char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
+      const char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
 
       Link bpLink, next;
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::MoveIcons()");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::MoveIcons()");
       for(bpLink = ide.workspace.breakpoints.first; bpLink; bpLink = next)
       {
-         Breakpoint bp = (Breakpoint)bpLink.data;
+         Breakpoint bp = (Breakpoint)(intptr)bpLink.data;
          next = bpLink.next;
 
          if(bp.type == user && bp.absoluteFilePath && !fstrcmp(bp.absoluteFilePath, absoluteFilePath))
@@ -1251,17 +1225,16 @@ class Debugger
             }
          }
       }
-      
+
       // moving code cursors is futile, on next step, stop, hit, cursors will be offset anyways
    }
 
-   bool SourceDirDialog(char * title, char * startDir, char * test, char * sourceDir)
+   bool SourceDirDialog(const char * title, const char * startDir, const char * test, char * sourceDir)
    {
       bool result;
-      bool retry;
       String srcDir = null;
 
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SourceDirDialog()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::SourceDirDialog()");
       debuggerFileDialog.text = title;
       debuggerFileDialog.currentDirectory = startDir;
       debuggerFileDialog.master = ide;
@@ -1269,9 +1242,9 @@ class Debugger
       while(debuggerFileDialog.Modal())
       {
          strcpy(sourceDir, debuggerFileDialog.filePath);
-         if(!fstrcmp(ide.workspace.projectDir, sourceDir) && 
-                  MessageBox { type = yesNo, master = ide, 
-                              contents = $"This is the project directory.\nWould you like to try again?", 
+         if(!fstrcmp(ide.workspace.projectDir, sourceDir) &&
+                  MessageBox { type = yesNo, master = ide,
+                              contents = $"This is the project directory.\nWould you like to try again?",
                               text = $"Invalid Source Directory" }.Modal() == no)
             return false;
          else
@@ -1284,10 +1257,10 @@ class Debugger
                   break;
                }
             }
-            
-            if(srcDir && 
-                  MessageBox { type = yesNo, master = ide, 
-                              contents = $"This source directory is already specified.\nWould you like to try again?", 
+
+            if(srcDir &&
+                  MessageBox { type = yesNo, master = ide,
+                              contents = $"This source directory is already specified.\nWould you like to try again?",
                               text = $"Invalid Source Directory" }.Modal() == no)
                return false;
             else
@@ -1298,15 +1271,15 @@ class Debugger
                   strcpy(file, sourceDir);
                   PathCat(file, test);
                   result = FileExists(file);
-                  if(!result && 
-                        MessageBox { type = yesNo, master = ide, 
-                                    contents = $"Unable to locate source file.\nWould you like to try again?", 
+                  if(!result &&
+                        MessageBox { type = yesNo, master = ide,
+                                    contents = $"Unable to locate source file.\nWould you like to try again?",
                                     text = $"Invalid Source Directory" }.Modal() == no)
                         return false;
                }
                else
                   result = true;
-               
+
                if(result)
                   return true;
             }
@@ -1315,12 +1288,12 @@ class Debugger
       return false;
    }
 
-   void AddSourceDir(char * sourceDir)
+   void AddSourceDir(const char * sourceDir)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::AddSourceDir(", sourceDir, ")");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::AddSourceDir(", sourceDir, ")");
       ide.workspace.sourceDirs.Add(CopyString(sourceDir));
       ide.workspace.Save();
-      
+
       if(targeted)
       {
          DebuggerState oldState = state;
@@ -1331,7 +1304,7 @@ class Debugger
                   GdbDebugBreak(true);
             case stopped:
             case loaded:
-               GdbCommand(false, "-environment-directory \"%s\"", sourceDir);
+               GdbCommand(0, false, "-environment-directory \"%s\"", sourceDir);
                break;
          }
          if(oldState == running)
@@ -1339,17 +1312,14 @@ class Debugger
       }
    }
 
-   void ToggleBreakpoint(char * fileName, int lineNumber, Project prj)
+   void ToggleBreakpoint(const char * fileName, int lineNumber)
    {
-      char winFilePath[MAX_LOCATION];
-      char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
       char absolutePath[MAX_LOCATION];
-      char relativePath[MAX_LOCATION];
-      char sourceDir[MAX_LOCATION];
       Breakpoint bp = null;
 
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ToggleBreakpoint(", fileName, ":", lineNumber, ")");
-      strcpy(absolutePath, absoluteFilePath);
+      _dpcl(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::ToggleBreakpoint(", fileName, ":", lineNumber, ")");
+
+      GetSlashPathBuffer(absolutePath, fileName);
       for(i : ide.workspace.breakpoints; i.type == user && i.absoluteFilePath && !fstrcmp(i.absoluteFilePath, absolutePath) && i.line == lineNumber)
       {
          bp = i;
@@ -1367,22 +1337,19 @@ class Debugger
       }
       else
       {
-         // FIXED: This is how it should have been... Source locations are only for files not in project
-         // if(IsPathInsideOf(absolutePath, ide.workspace.projectDir))
-         //   MakePathRelative(absolutePath, ide.workspace.projectDir, relativePath);
-         bool result = false;
-         if(prj)
-            result = prj.GetRelativePath(absolutePath, relativePath);
-         else
-            result = ide.projectView.project.GetRelativePath(absolutePath, relativePath);
-         //if(ide.projectView.project.GetRelativePath(absolutePath, relativePath));
-         //else
-         if(!result)
+         Project owner;
+         char relativePath[MAX_LOCATION];
+         const char * objectFileExt = currentCompiler ? currentCompiler.objectFileExt : objectDefaultFileExt;
+
+         ide.workspace.GetRelativePath(absolutePath, relativePath, &owner, objectFileExt);
+
+         if(!owner && !FileExists(absolutePath))
          {
             char title[MAX_LOCATION];
             char directory[MAX_LOCATION];
+            char sourceDir[MAX_LOCATION];
             StripLastDirectory(absolutePath, directory);
-            snprintf(title, sizeof(title), $"Provide source files location directory for %s", absolutePath);
+            snprintf(title, sizeof(title), $"Provide source files location directory for %s", relativePath);
             title[sizeof(title)-1] = 0;
             while(true)
             {
@@ -1391,35 +1358,33 @@ class Debugger
                {
                   if(IsPathInsideOf(absolutePath, dir))
                   {
-                     MakePathRelative(absoluteFilePath, dir, relativePath);
+                     MakePathRelative(absolutePath, dir, relativePath);
                      srcDir = dir;
                      break;
                   }
                }
                if(srcDir)
                   break;
-               
+
                if(SourceDirDialog(title, directory, null, sourceDir))
                {
                   if(IsPathInsideOf(absolutePath, sourceDir))
                   {
                      AddSourceDir(sourceDir);
-                     MakePathRelative(absoluteFilePath, sourceDir, relativePath);
+                     MakePathRelative(absolutePath, sourceDir, relativePath);
                      break;
                   }
-                  else if(MessageBox { type = yesNo, master = ide, 
-                                 contents = $"You must provide a valid source directory in order to place a breakpoint in this file.\nWould you like to try again?", 
+                  else if(MessageBox { type = yesNo, master = ide,
+                                 contents = $"You must provide a valid source directory in order to place a breakpoint in this file.\nWould you like to try again?",
                                  text = $"Invalid Source Directory" }.Modal() == no)
                      return;
                }
-               else if(MessageBox { type = yesNo, master = ide, 
-                                 contents = $"You must provide a source directory in order to place a breakpoint in this file.\nWould you like to try again?", 
-                                 text = $"No Source Directory Provided" }.Modal() == no)
+               else
                   return;
             }
          }
          ide.workspace.bpCount++;
-         bp = { line = lineNumber, type = user, enabled = true, level = -1 };
+         bp = { line = lineNumber, type = user, enabled = true, level = -1, project = owner };
          ide.workspace.breakpoints.Add(bp);
          bp.absoluteFilePath = absolutePath;
          bp.relativeFilePath = relativePath;
@@ -1436,7 +1401,8 @@ class Debugger
                   GdbDebugBreak(true);
             case stopped:
             case loaded:
-               SetBreakpoint(bp, false);
+               if(!SetBreakpoint(bp, false))
+                  SetBreakpoint(bp, true);
                break;
          }
          if(oldState == running)
@@ -1448,7 +1414,7 @@ class Debugger
 
    void UpdateRemovedBreakpoint(Breakpoint bp)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::UpdateRemovedBreakpoint()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::UpdateRemovedBreakpoint()");
       if(targeted && bp.inserted)
       {
          DebuggerState oldState = state;
@@ -1477,8 +1443,8 @@ class Debugger
       Array<char *> argumentTokens { minAllocSize = 50 };
       DebugListItem item { };
       Argument arg;
-      
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseFrame()");
+
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseFrame()");
       TokenizeList(string, ',', frameTokens);
       for(i = 0; i < frameTokens.count; i++)
       {
@@ -1520,10 +1486,10 @@ class Debugger
                               arg.val = item.value;
                            }
                            else
-                              _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "frame args item (", item.name, "=", item.value, ") is unheard of");
+                              _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "frame args item (", item.name, "=", item.value, ") is unheard of");
                         }
                         else
-                           _dpl(0, "Bad frame args item");
+                           _dplf(0, "Bad frame args item");
                      }
                      argumentTokens.RemoveAll();
                   }
@@ -1538,24 +1504,25 @@ class Debugger
             else if(!strcmp(item.name, "line"))
                frame.line = atoi(item.value);
             else if(!strcmp(item.name, "fullname"))
-               frame.absoluteFile = item.value;
-            /*{
+            {
                // GDB 6.3 on OS X is giving "fullname" and "dir", all in absolute, but file name only in 'file'
-               String path = ide.workspace.GetPathWorkspaceRelativeOrAbsolute(item.value);
-               if(strcmp(frame.file, path))
+               Workspace ws = ide.workspace;
+               if(ws)
                {
-                  frame.file = path;
-                  frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
+                  String path = ide.workspace.CopyUnixPathWorkspaceRelativeOrAbsolute(item.value);
+                  if(strcmp(frame.file, path))
+                     frame.file = path;
+                  delete path;
                }
-               delete path;
-            }*/
+               frame.absoluteFile = item.value;
+            }
             else
-               _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "frame member (", item.name, "=", item.value, ") is unheard of");
+               _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "frame member (", item.name, "=", item.value, ") is unheard of");
          }
          else
-            _dpl(0, "Bad frame");
+            _dplf(0, "Bad frame");
       }
-      
+
       delete frameTokens;
       delete argsTokens;
       delete argumentTokens;
@@ -1565,7 +1532,7 @@ class Debugger
    Breakpoint GetBreakpointById(int id, bool * isInternal)
    {
       Breakpoint bp = null;
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GetBreakpointById(", id, ")");
+      //_dpcl(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::GetBreakpointById(", id, ")");
       if(isInternal)
          *isInternal = false;
       if(id)
@@ -1597,7 +1564,7 @@ class Debugger
       GdbDataBreakpoint bp { };
       DebugListItem item { };
       Array<char *> bpTokens { minAllocSize = 16 };
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseBreakpoint()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseBreakpoint()");
       string = StripCurlies(string);
       TokenizeList(string, ',', bpTokens);
       for(i = 0; i < bpTokens.count; i++)
@@ -1645,17 +1612,19 @@ class Debugger
             else if(!strcmp(item.name, "times"))
                bp.times = atoi(item.value);
             else if(!strcmp(item.name, "original-location") || !strcmp(item.name, "thread-groups"))
-               _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "breakpoint member (", item.name, "=", item.value, ") is ignored");
+               _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, "breakpoint member (", item.name, "=", item.value, ") is ignored");
             else
-               _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "breakpoint member (", item.name, "=", item.value, ") is unheard of");
+               _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "breakpoint member (", item.name, "=", item.value, ") is unheard of");
          }
       }
+      delete bpTokens;
+      delete item;
       return bp;
    }
 
    void ShowDebuggerViews()
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ShowDebuggerViews()");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::ShowDebuggerViews()");
       ide.outputView.Show();
       ide.outputView.SelectTab(debug);
       ide.threadsView.Show();
@@ -1666,14 +1635,16 @@ class Debugger
 
    void HideDebuggerViews()
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::HideDebuggerViews()");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::HideDebuggerViews()");
       ide.RepositionWindows(true);
    }
 
-   void ::GdbCommand(bool focus, char * format, ...)
+   bool ::GdbCommand(Time timeOut, bool focus, const char * format, ...)
    {
+      bool result = false;
       if(gdbHandle)
       {
+         Time startTime;
          // TODO: Improve this limit
          static char string[MAX_F_STRING*4];
          va_list args;
@@ -1681,12 +1652,12 @@ class Debugger
          vsnprintf(string, sizeof(string), format, args);
          string[sizeof(string)-1] = 0;
          va_end(args);
-         
+
          gdbReady = false;
          ide.debugger.serialSemaphore.TryWait();
 
 #ifdef GDB_DEBUG_CONSOLE
-         _dpl2(_dpct, dplchan::gdbCommand, 0, string);
+         _dpcl(_dpct, dplchan::gdbCommand, 0, string);
 #endif
 #ifdef GDB_DEBUG_OUTPUT
          ide.outputView.gdbBox.Logf("cmd: %s\n", string);
@@ -1703,14 +1674,39 @@ class Debugger
             Process_ShowWindows(targetProcessId);
 
          app.Unlock();
-         ide.debugger.serialSemaphore.Wait();
+
+         if(timeOut)
+         {
+            startTime = GetTime();
+            while(true)
+            {
+               if(ide.debugger.serialSemaphore.TryWait())
+               {
+                  result = true;
+                  break;
+               }
+               else
+               {
+                  if(GetTime() - startTime > timeOut)
+                     break;
+                  Sleep(0.01);
+               }
+            }
+         }
+         else
+         {
+            ide.debugger.serialSemaphore.Wait();
+            result = true;
+         }
+
          app.Lock();
-      } 
+      }
+      return result;
    }
 
    bool ValidateBreakpoint(Breakpoint bp)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ValidateBreakpoint()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::ValidateBreakpoint()");
       if(modules && bp.line && bp.bp)
       {
          if(bp.bp.line != bp.line)
@@ -1736,93 +1732,114 @@ class Debugger
       return true;
    }
 
-   void GdbBreakpointsInsert()
+   void BreakpointsMaintenance()
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbBreakpointsInsert()");
+      //_dpcl(_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)
+               {
+                  if(!SetBreakpoint(bp, false))
+                     SetBreakpoint(bp, true);
+               }
             }
-            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(!SetBreakpoint(bpRunToCursor, false))
+               SetBreakpoint(bpRunToCursor, true);
+         }
 
-         if(!ignoreBreakpoints)
+         if(ignoreBreakpoints)
+         {
+            for(bp : ide.workspace.breakpoints; bp.inserted)
+               UnsetBreakpoint(bp);
+         }
+         else
          {
             for(bp : ide.workspace.breakpoints; !bp.inserted && bp.type == user)
             {
@@ -1835,8 +1852,9 @@ class Debugger
                {
 #ifdef _DEBUG
                   if(bp.bp)
-                     _dpl(0, "problem");
+                     _dplf(0, "problem");
 #endif
+                  delete bp.bp;
                   bp.bp = GdbDataBreakpoint { };
                }
             }
@@ -1846,121 +1864,120 @@ class Debugger
 
    void UnsetBreakpoint(Breakpoint bp)
    {
-      char * s; _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::UnsetBreakpoint(", s=bp.CopyLocationString(false), ")"); delete s;
+      char * s = null; _dpcl(_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);
+         GdbCommand(0, false, "-break-delete %s", bp.bp.number);
          bp.inserted = false;
+         delete bp.bp;
          bp.bp = { };
       }
    }
 
    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 = null; _dpcl(_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.GetTargetType(bp.project.config) == staticLibrary || bp.project == ide.project || projectsLibraryLoaded[bp.project.name]))
       {
-         char * location = bp.CopyLocationString(removePath);
          sentBreakInsert = true;
-         GdbCommand(false, "-break-insert %s", location);
-         delete location;
+         if(bp.address)
+            GdbCommand(0, false, "-break-insert *%s", bp.address);
+         else
+         {
+            char * location = bp.CopyLocationString(removePath);
+            GdbCommand(0, false, "-break-insert %s", location);
+            delete location;
+         }
          if(!breakpointError)
          {
-            if(bpItem.multipleBPs && bpItem.multipleBPs.count)
+            char * address = null;
+            if(bpItem && bpItem.multipleBPs && bpItem.multipleBPs.count)
             {
                int count = 0;
                GdbDataBreakpoint first = null;
                for(n : bpItem.multipleBPs)
                {
-                  if(!fstrcmp(n.fullname, bp.absoluteFilePath))
+                  if(!fstrcmp(n.fullname, bp.absoluteFilePath) && !first)
                   {
                      count++;
-                     if(!first)
-                        first = n;
+                     first = n;
+                     break;
                   }
-                  else
+                  /*else
                   {
                      if(n.enabled)
                      {
-                        GdbCommand(false, "-break-disable %s", n.number);
+                        GdbCommand(0, false, "-break-disable %s", n.number);
                         n.enabled = false;
                      }
                      else
-                        _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error breakpoint already disabled.");
-                  }
+                        _dpcl(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error breakpoint already disabled.");
+                  }*/
                }
                if(first)
                {
+                  address = CopyString(first.addr);
                   bpItem.addr = first.addr;
                   bpItem.func = first.func;
                   bpItem.file = first.file;
                   bpItem.fullname = first.fullname;
                   bpItem.line = first.line;
-                  //bpItem.thread-groups = first.thread-groups;
-                  bpItem.multipleBPs.Free();
-                  delete bpItem.multipleBPs;
+                  //bpItem.thread-groups = first.thread-groups;*/
                }
                else if(count == 0)
-                  _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints all disabled.");
+                  _dpcl(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints all disabled.");
                else
-                  _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints in exact same file not supported.");
+                  _dpcl(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints in exact same file not supported.");
+               bpItem.multipleBPs.Free();
+               delete bpItem.multipleBPs;
             }
+            delete bp.bp;
             bp.bp = bpItem;
             bpItem = null;
             bp.inserted = (bp.bp && bp.bp.number && strcmp(bp.bp.number, "0"));
             if(bp.inserted)
                ValidateBreakpoint(bp);
-            /*if(bp == bpRunToCursor)
-               runToCursorDebugStart = false;*/
-         }
-      }
-      return !breakpointError;
-   }
 
-   void GdbBreakpointsDelete(bool deleteRunToCursor, bool deleteInternalBreakpoints)
-   {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbBreakpointsDelete(deleteRunToCursor(", deleteRunToCursor, "))");
-      if(symbols)
-      {
-         if(deleteInternalBreakpoints)
-         {
-            for(bp : sysBPs)
+            if(address)
+            {
                UnsetBreakpoint(bp);
+               bp.address = address;
+               delete address;
+               SetBreakpoint(bp, removePath);
+            }
          }
-         for(bp : ide.workspace.breakpoints)
-            UnsetBreakpoint(bp);
-         if(deleteRunToCursor && bpRunToCursor)
-            UnsetBreakpoint(bpRunToCursor);
+         return !breakpointError;
       }
+      return false;
    }
 
    void GdbGetStack()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbGetStack()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbGetStack()");
       activeFrame = null;
       stackFrames.Free(Frame::Free);
-      GdbCommand(false, "-stack-info-depth");
+      GdbCommand(0, false, "-stack-info-depth");
       if(!frameCount)
-         GdbCommand(false, "-stack-info-depth 192");
+         GdbCommand(0, false, "-stack-info-depth 192");
       if(frameCount && frameCount <= 192)
-         GdbCommand(false, "-stack-list-frames 0 %d", Min(frameCount-1, 191));
+         GdbCommand(0, false, "-stack-list-frames 0 %d", Min(frameCount-1, 191));
       else
       {
-         GdbCommand(false, "-stack-list-frames 0 %d", Min(frameCount-1, 95));
-         GdbCommand(false, "-stack-list-frames %d %d", Max(frameCount - 96, 96), frameCount - 1);
+         GdbCommand(0, false, "-stack-list-frames 0 %d", Min(frameCount-1, 95));
+         GdbCommand(0, false, "-stack-list-frames %d %d", Max(frameCount - 96, 96), frameCount - 1);
       }
-      GdbCommand(false, "");
+      GdbCommand(0, false, "");
    }
 
    bool GdbTargetSet()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbTargetSet()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbTargetSet()");
       if(!targeted)
       {
          char escaped[MAX_LOCATION];
          strescpy(escaped, targetFile);
-         GdbCommand(false, "file \"%s\"", escaped);  //GDB/MI Missing Implementation -symbol-file, -target-attach
+         GdbCommand(0, 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;
@@ -1968,13 +1985,15 @@ class Debugger
          if(usingValgrind)
          {
             const char *vgdbCommand = "/usr/bin/vgdb"; // TODO: vgdb command config option
-            //GdbCommand(false, "-target-select remote | %s --pid=%d", "vgdb", targetProcessId);
+            //GdbCommand(0, false, "-target-select remote | %s --pid=%d", "vgdb", targetProcessId);
             printf("target remote | %s --pid=%d\n", vgdbCommand, targetProcessId);
-            GdbCommand(false, "target remote | %s --pid=%d", vgdbCommand, targetProcessId); // TODO: vgdb command config option
+            GdbCommand(0, false, "target remote | %s --pid=%d", vgdbCommand, targetProcessId); // TODO: vgdb command config option
          }
+         else
+            GdbCommand(0, 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);*/
+            GdbCommand(0, false, "-environment-directory \"%s\"", prj.topNode.path);*/
 
          for(dir : ide.workspace.sourceDirs; dir && dir[0])
          {
@@ -1988,7 +2007,7 @@ class Debugger
               }
            }
            if(!interference && dir[0])
-              GdbCommand(false, "-environment-directory \"%s\"", dir);
+              GdbCommand(0, false, "-environment-directory \"%s\"", dir);
          }
 
          targeted = true;
@@ -2000,8 +2019,8 @@ class Debugger
    {
       if(targeted)
       {
-         GdbBreakpointsDelete(true, true);
-         GdbCommand(false, "file");  //GDB/MI Missing Implementation -target-detach
+         BreakpointsDeleteAll();
+         GdbCommand(0, false, "file");  //GDB/MI Missing Implementation -target-detach
          targeted = false;
          symbols = true;
       }
@@ -2009,7 +2028,7 @@ class Debugger
 
    void GdbDebugBreak(bool internal)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbDebugBreak()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbDebugBreak()");
       if(targetProcessId)
       {
          if(internal)
@@ -2017,11 +2036,11 @@ class Debugger
 
          if(ide) ide.Update(null);
          app.Unlock();
-         if(Process_Break(targetProcessId))  //GdbCommand(false, "-exec-interrupt");
+         if(Process_Break(targetProcessId))  //GdbCommand(0, false, "-exec-interrupt");
             serialSemaphore.Wait();
          else
          {
-            ChangeState(loaded);
+            _ChangeState(loaded);
             targetProcessId = 0;
          }
          app.Lock();
@@ -2032,55 +2051,134 @@ class Debugger
 
    void GdbExecRun()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecRun()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecRun()");
       GdbTargetSet();
+      if(!usingValgrind)
+         gdbExecution = run;
       GdbExecCommon();
       ShowDebuggerViews();
       if(usingValgrind)
-         GdbCommand(true, "-exec-continue");
-      else
-         GdbCommand(true, "-exec-run");
+         GdbExecContinue(true);
+      else if(!GdbCommand(3, true, "-exec-run"))
+         gdbExecution = none;
    }
 
    void GdbExecContinue(bool focus)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecContinue()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecContinue()");
+      gdbExecution = run;
       GdbExecCommon();
-      GdbCommand(focus, "-exec-continue");
+      GdbCommand(0, focus, "-exec-continue");
    }
 
    void GdbExecNext()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecNext()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecNext()");
+      gdbExecution = next;
+      GdbExecCommon();
+      GdbCommand(0, true, "-exec-next");
+   }
+
+   void ForceUpdateCurrentFrame()
+   {
+      GdbGetStack();
+      GdbCommand(0, false, "-thread-list-ids");
+      InternalSelectFrame(activeFrameLevel);
+      GoToStackFrameLine(activeFrameLevel, true, false);
+      EvaluateWatches();
+      ide.ShowCodeEditor();
+      ide.AdjustDebugMenus();
+      ideMainFrame.Activate();   // TOFIX: ide.Activate() is not reliable (app inactive)
+      ide.Update(null);
+   }
+
+   void GdbExecUntil(const char * absoluteFilePath, int lineNumber)
+   {
+      bool forceUpdate = false;
+      char relativeFilePath[MAX_LOCATION];
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecUntil()");
+      gdbExecution = until;
       GdbExecCommon();
-      GdbCommand(true, "-exec-next");
+      if(absoluteFilePath)
+      {
+         const char * objectFileExt = currentCompiler ? currentCompiler.objectFileExt : objectDefaultFileExt;
+         ide.workspace.GetRelativePath(absoluteFilePath, relativeFilePath, null, objectFileExt);
+         if(!GdbCommand(0.1, true, "-exec-until %s:%d", relativeFilePath, lineNumber))
+         {
+            GetLastDirectory(relativeFilePath, relativeFilePath);
+            if(GdbCommand(1, true, "-exec-until %s:%d", relativeFilePath, lineNumber))
+               forceUpdate = true;
+         }
+      }
+      else
+         GdbCommand(0, true, "-exec-until");
+
+      // This is to handle GDB 6.3 on OS X not giving us *running then *stopped:
+      // (It may not be ideal, we may need to wait?)
+      if(forceUpdate)
+         ForceUpdateCurrentFrame();
+   }
+
+   void GdbExecAdvance(const char * absoluteFilePathOrLocation, int lineNumber)
+   {
+      bool forceUpdate = false;
+      char relativeFilePath[MAX_LOCATION];
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecAdvance()");
+      gdbExecution = advance;
+      GdbExecCommon();
+      if(lineNumber)
+      {
+         const char * objectFileExt = currentCompiler ? currentCompiler.objectFileExt : objectDefaultFileExt;
+         ide.workspace.GetRelativePath(absoluteFilePathOrLocation, relativeFilePath, null, objectFileExt);
+         if(!GdbCommand(0.1, true, "advance %s:%d", relativeFilePath, lineNumber)) // should use -exec-advance -- GDB/MI implementation missing
+         {
+            GetLastDirectory(relativeFilePath, relativeFilePath);
+            if(GdbCommand(1, true, "advance %s:%d", relativeFilePath, lineNumber))
+               forceUpdate = true;
+         }
+      }
+      else
+      {
+         if(!GdbCommand(0.1, true, "advance %s", absoluteFilePathOrLocation)) // should use -exec-advance -- GDB/MI implementation missing
+         {
+            GetLastDirectory(absoluteFilePathOrLocation, relativeFilePath);
+            if(GdbCommand(1, true, "advance %s", relativeFilePath))
+               forceUpdate = true;
+         }
+      }
+
+      // This is to handle GDB 6.3 on OS X not giving us *running then *stopped:
+      // (It may not be ideal, we may need to wait?)
+      if(forceUpdate)
+         ForceUpdateCurrentFrame();
    }
 
    void GdbExecStep()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecStep()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecStep()");
+      gdbExecution = step;
       GdbExecCommon();
-      GdbCommand(true, "-exec-step");
+      GdbCommand(0, true, "-exec-step");
    }
 
    void GdbExecFinish()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecFinish()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecFinish()");
+      gdbExecution = finish;
       GdbExecCommon();
-      GdbCommand(true, "-exec-finish");
+      GdbCommand(0, true, "-exec-finish");
    }
 
    void GdbExecCommon()
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecCommon()");
-      ClearBreakDisplay();
-      GdbBreakpointsInsert();
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecCommon()");
+      BreakpointsMaintenance();
    }
 
 #ifdef GDB_DEBUG_GUI
-   void SendGDBCommand(char * command)
+   void SendGDBCommand(const char * command)
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SendGDBCommand()");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::SendGDBCommand()");
       DebuggerState oldState = state;
       switch(state)
       {
@@ -2089,7 +2187,7 @@ class Debugger
                GdbDebugBreak(true);
          case stopped:
          case loaded:
-            GdbCommand(false, command);
+            GdbCommand(0, false, command);
             break;
       }
       if(oldState == running)
@@ -2099,7 +2197,7 @@ class Debugger
 
    void ClearBreakDisplay()
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ClearBreakDisplay()");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::ClearBreakDisplay()");
       activeThread = 0;
       activeFrameLevel = -1;
       hitThread = 0;
@@ -2112,7 +2210,6 @@ class Debugger
       event = none;
       activeFrame = null;
       stackFrames.Free(Frame::Free);
-      WatchesCodeEditorLinkRelease();
       ide.callStackView.Clear();
       ide.threadsView.Clear();
       ide.Update(null);
@@ -2120,9 +2217,9 @@ class Debugger
 
    bool GdbAbortExec()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbAbortExec()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbAbortExec()");
       sentKill = true;
-      GdbCommand(false, "-interpreter-exec console \"kill\""); // should use -exec-abort -- GDB/MI implementation incomplete
+      GdbCommand(0, false, "-interpreter-exec console \"kill\""); // should use -exec-abort -- GDB/MI implementation incomplete
       return true;
    }
 
@@ -2132,12 +2229,12 @@ class Debugger
       char oldDirectory[MAX_LOCATION];
       char tempPath[MAX_LOCATION];
       char command[MAX_F_STRING*4];
-      bool vgFullLeakCheck = ide.workspace.vgFullLeakCheck;
       Project project = ide.project;
       DirExpression targetDirExp = project.GetTargetDir(compiler, config, bitDepth);
       PathBackup pathBackup { };
+      Map<String, String> envBackup { };
 
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbInit()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbInit()");
       if(currentCompiler != compiler)
       {
          delete currentCompiler;
@@ -2148,7 +2245,7 @@ class Debugger
       this.bitDepth = bitDepth;
       usingValgrind = useValgrind;
 
-      ChangeState(loaded);
+      _ChangeState(loaded);
       sentKill = false;
       sentBreakInsert = false;
       breakpointError = false;
@@ -2157,7 +2254,9 @@ class Debugger
       targeted = false;
       modules = false;
       needReset = false;
-      
+      entryPoint = false;
+      projectsLibraryLoaded.Free();
+
       ide.outputView.ShowClearSelectTab(debug);
       ide.outputView.debugBox.Logf($"Starting debug mode\n");
 
@@ -2183,7 +2282,7 @@ class Debugger
       }
       else
          ChangeWorkingDir(ide.workspace.projectDir);
-      
+
       ide.SetPath(true, compiler, config, bitDepth);
 
       // TODO: This pollutes the environment, but at least it works
@@ -2192,6 +2291,8 @@ class Debugger
       // gdb set environment commands don't seem to take effect
       for(e : ide.workspace.environmentVars)
       {
+         // Backing up the environment variables until we use DualPipeOpenEnv()
+         envBackup[e.name] = CopyString(getenv(e.name));
          SetEnvironment(e.name, e.string);
       }
 
@@ -2199,6 +2300,9 @@ class Debugger
       {
          char * clArgs = ide.workspace.commandLineArgs;
          const char *valgrindCommand = "valgrind"; // TODO: valgrind command config option //TODO: valgrind options
+         ValgrindLeakCheck vgLeakCheck = ide.workspace.vgLeakCheck;
+         int vgRedzoneSize = ide.workspace.vgRedzoneSize;
+         bool vgTrackOrigins = ide.workspace.vgTrackOrigins;
          vgLogFile = CreateTemporaryFile(vgLogPath, "ecereidevglog");
          if(vgLogFile)
          {
@@ -2217,9 +2321,11 @@ class Debugger
          }
          if(result)
          {
-            sprintf(command, "%s --vgdb=yes --vgdb-error=0 --log-file=%s%s %s%s%s",
-                  valgrindCommand, vgLogPath, vgFullLeakCheck ? " --leak-check=full" : "", targetFile, clArgs ? " " : "", clArgs ? clArgs : "");
-            vgTargetHandle = DualPipeOpen(PipeOpenMode { output = 1, error = 2, input = 1 }, command);
+            char * vgRedzoneSizeFlag = PrintString(" --redzone-size=", vgRedzoneSize);
+            sprintf(command, "%s --vgdb=yes --vgdb-error=0 --log-file=%s --leak-check=%s%s --track-origins=%s %s%s%s",
+                  valgrindCommand, vgLogPath, (char*)vgLeakCheck, vgRedzoneSize > -1 ? vgRedzoneSizeFlag : "", vgTrackOrigins ? "yes" : "no", targetFile, clArgs ? " " : "", clArgs ? clArgs : "");
+            delete vgRedzoneSizeFlag;
+            vgTargetHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
             if(!vgTargetHandle)
             {
                ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start Valgrind\n");
@@ -2249,10 +2355,17 @@ class Debugger
 
       if(result)
       {
-         strcpy(command,
-            (compiler.targetPlatform == win32 && bitDepth == 64) ? "x86_64-w64-mingw32-gdb" :
-            (compiler.targetPlatform == win32 && bitDepth == 32) ? "i686-w64-mingw32-gdb" :
-            "gdb");
+         if(compiler.targetPlatform == win32)
+         {
+            strcpy(command,
+#if !((defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__))
+               1 ||
+#endif
+               bitDepth == 32 ? "i686-w64-mingw32-gdb" : "gdb");  // x86_64-w64-mingw32-gdb
+         }
+         else
+            // We really should have a box to select GDB in the compiler/toolchain options
+            strcpy(command, "gdb");
          if(!CheckCommandAvailable(command))
          {
             ide.outputView.debugBox.Logf($"Debugger Fatal Error: Command %s for GDB is not available.\n", command);
@@ -2262,7 +2375,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");
@@ -2288,17 +2401,17 @@ class Debugger
          serialSemaphore.Wait();
          app.Lock();
 
-         GdbCommand(false, "-gdb-set verbose off");
-         //GdbCommand(false, "-gdb-set exec-done-display on");
-         GdbCommand(false, "-gdb-set step-mode off");
-         GdbCommand(false, "-gdb-set unwindonsignal on");
-         //GdbCommand(false, "-gdb-set shell on");
-         GdbCommand(false, "set print elements 992");
-         GdbCommand(false, "-gdb-set backtrace limit 100000");
+         GdbCommand(0, false, "-gdb-set verbose off");
+         //GdbCommand(0, false, "-gdb-set exec-done-display on");
+         GdbCommand(0, false, "-gdb-set step-mode off");
+         GdbCommand(0, false, "-gdb-set unwindonsignal on");
+         //GdbCommand(0, false, "-gdb-set shell on");
+         GdbCommand(0, false, "set print elements 992");
+         GdbCommand(0, false, "-gdb-set backtrace limit 100000");
 
          if(!GdbTargetSet())
          {
-            //ChangeState(terminated);
+            //_ChangeState(terminated);
             result = false;
          }
       }
@@ -2329,26 +2442,33 @@ class Debugger
 #endif
 
 #if defined(__WIN32__)
-         GdbCommand(false, "-gdb-set new-console on");
+         GdbCommand(0, false, "-gdb-set new-console on");
 #endif
 
 #if defined(__unix__)
          if(!usingValgrind)
-            GdbCommand(false, "-inferior-tty-set %s", progFifoPath);
+            GdbCommand(0, false, "-inferior-tty-set %s", progFifoPath);
 #endif
 
          if(!usingValgrind)
-            GdbCommand(false, "-gdb-set args %s", ide.workspace.commandLineArgs ? ide.workspace.commandLineArgs : "");
+            GdbCommand(0, false, "-gdb-set args %s", ide.workspace.commandLineArgs ? ide.workspace.commandLineArgs : "");
          /*
          for(e : ide.workspace.environmentVars)
          {
-            GdbCommand(false, "set environment %s=%s", e.name, e.string);
+            GdbCommand(0, false, "set environment %s=%s", e.name, e.string);
          }
          */
       }
 
       ChangeWorkingDir(oldDirectory);
 
+      for(e : envBackup)
+      {
+         SetEnvironment(&e, e);
+      }
+      envBackup.Free();
+      delete envBackup;
+
       delete pathBackup;
 
       if(!result)
@@ -2359,10 +2479,11 @@ class Debugger
 
    void GdbExit()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExit()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExit()");
       if(gdbHandle && gdbProcessId)
       {
-         GdbCommand(false, "-gdb-exit");
+         gdbTimer.Stop();
+         GdbCommand(0, false, "-gdb-exit");
 
          if(gdbThread)
          {
@@ -2370,6 +2491,21 @@ class Debugger
             gdbThread.Wait();
             app.Lock();
          }
+         if(vgLogFile)
+            vgLogFile.CloseInput();
+         if(vgLogThread.created)
+         {
+            app.Unlock();
+            vgLogThread.Wait();
+            app.Lock();
+         }
+         delete vgLogFile;
+         if(vgTargetThread)
+         {
+            app.Unlock();
+            vgTargetThread.Wait();
+            app.Lock();
+         }
          if(gdbHandle)
          {
             gdbHandle.Wait();
@@ -2377,32 +2513,20 @@ class Debugger
          }
       }
       gdbTimer.Stop();
-      ChangeState(terminated); // this state change seems to be superfluous, is it safety for something?
-      prjConfig = null;
+      _ChangeState(terminated); // this state change seems to be superfluous, is it safety for something?
       needReset = false;
 
       if(ide.workspace)
       {
          for(bp : ide.workspace.breakpoints)
-         {
-            bp.inserted = false;
-            delete bp.bp;
-         }
+            bp.Reset();
       }
       for(bp : sysBPs)
-      {
-         bp.inserted = false;
-         delete bp.bp;
-      }
+         bp.Reset();
       if(bpRunToCursor)
-      {
-         bpRunToCursor.inserted = false;
-         delete bpRunToCursor.bp;
-      }
-      
+         bpRunToCursor.Reset();
+
       ide.outputView.debugBox.Logf($"Debugging stopped\n");
-      ClearBreakDisplay();
-      ide.Update(null);
 
 #if defined(__unix__)
       if(!usingValgrind && FileExists(progFifoPath)) //fileCreated)
@@ -2415,78 +2539,57 @@ class Debugger
             progThread.Wait();
             app.Lock();
             delete fifoFile;
-         }         
+         }
          DeleteFile(progFifoPath);
          progFifoPath[0] = '\0';
          rmdir(progFifoDir);
       }
 #endif
+
+      CleanUp();
+      ide.Update(null);
    }
 
-   void WatchesCodeEditorLinkInit()
+   bool WatchesLinkCodeEditor()
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesCodeEditorLinkInit()");
-      /*
-      char tempPath[MAX_LOCATION];
-      char path[MAX_LOCATION];
-      
-      //void MakeFilePathProjectRelative(char * path, char * relativePath)
-      if(!ide.projectView.project.GetRelativePath(activeFrame.file, tempPath))
-         strcpy(tempPath, activeFrame.file);
-      
-      strcpy(path, ide.workspace.projectDir);
-      PathCat(path, tempPath);
-      codeEditor = (CodeEditor)ide.OpenFile(path, Normal, false, null, no, normal, false);
-      if(!codeEditor)
+      bool goodFrame = activeFrame && activeFrame.absoluteFile;
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesLinkCodeEditor()");
+      if(codeEditor && (!goodFrame || fstrcmp(codeEditor.fileName, activeFrame.absoluteFile)))
+         WatchesReleaseCodeEditor();
+
+      if(!codeEditor && goodFrame)
       {
-         for(srcDir : ide.workspace.sourceDirs)
+         codeEditor = (CodeEditor)ide.OpenFile(activeFrame.absoluteFile, false, false, null, no, normal, false);
+         if(codeEditor)
          {
-            strcpy(path, srcDir);
-            PathCat(path, tempPath);
-            codeEditor = (CodeEditor)ide.OpenFile(path, Normal, false, null, no, normal, false);
-            if(codeEditor) break;
+            codeEditor.inUseDebug = true;
+            incref codeEditor;
          }
       }
-      */
-
-      /*if(activeFrame && !activeFrame.absoluteFile && activeFrame.file)
-         activeFrame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(activeFrame.file);*/
-      if(!activeFrame || !activeFrame.absoluteFile)
-         codeEditor = null;
-      else
-         codeEditor = (CodeEditor)ide.OpenFile(activeFrame.absoluteFile, normal, false, null, no, normal, false);
-      if(codeEditor)
-      {
-         codeEditor.inUseDebug = true;
-         incref codeEditor;
-      }
-      //watchesInit = true;
+      return codeEditor != null;
    }
 
-   void WatchesCodeEditorLinkRelease()
+   void WatchesReleaseCodeEditor()
    {
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesCodeEditorLinkRelease()");
-      //if(watchesInit)
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesReleaseCodeEditor()");
+      if(codeEditor)
       {
-         if(codeEditor)
-         {
-            codeEditor.inUseDebug = false;
-            if(!codeEditor.visible)
-               codeEditor.Destroy(0);
-            delete codeEditor;
-         }
+         codeEditor.inUseDebug = false;
+         if(!codeEditor.visible)
+            codeEditor.Destroy(0);
+         delete codeEditor;
       }
    }
 
    bool ResolveWatch(Watch wh)
    {
       bool result = false;
-      
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ResolveWatch()");
+
+      _dpcl(_dpct, dplchan::debuggerWatches, 0, "Debugger::ResolveWatch()");
       wh.Reset();
 
       /*delete wh.value;
-      if(wh.type) 
+      if(wh.type)
       {
          FreeType(wh.type);
          wh.type = null;
@@ -2495,6 +2598,7 @@ class Debugger
       if(wh.expression)
       {
          char watchmsg[MAX_F_STRING];
+         watchmsg[0] = 0;
          if(state == stopped && !codeEditor)
             wh.value = CopyString($"No source file found for selected frame");
          //if(codeEditor && state == stopped || state != stopped)
@@ -2504,7 +2608,6 @@ class Debugger
             Context backupContext;
             Class backupThisClass;
             Expression exp;
-            parseError = false;
 
             backupPrivateModule = GetPrivateModule();
             backupContext = GetCurrentContext();
@@ -2517,26 +2620,115 @@ class Debugger
                SetGlobalContext(codeEditor.globalContext);
                SetGlobalData(&codeEditor.globalData);
             }
-         
+
             exp = ParseExpressionString(wh.expression);
-            
-            if(exp && !parseError)
+
+            if(exp && !GetParseError())
             {
                char expString[4096];
                expString[0] = 0;
                PrintExpression(exp, expString);
 
-               if(GetPrivateModule())
-               {
-                  if(codeEditor)
-                     DebugFindCtxTree(codeEditor.ast, activeFrame.line, 0);
-                  ProcessExpressionType(exp);
-               }
+               SetInDebugger(true);
+
+               SetThisClass(null);
+               // NOTE: DebugFindCtxTree() should be called only once for evaluating all watches in the watch window
+               if(codeEditor && activeFrame)
+                  DebugFindCtxTree(codeEditor.ast, activeFrame.line, 0);
+               ProcessExpressionType(exp);
+
                wh.type = exp.expType;
                if(wh.type)
                   wh.type.refCount++;
                DebugComputeExpression(exp);
-               if(ExpressionIsError(exp))
+               // e.g. Meters * Degrees has no type set yet for some reason
+               if(!wh.type && exp.expType)
+               {
+                  wh.type = exp.expType;
+                  exp.expType.refCount++;
+               }
+
+               // This makes Degrees { 45 } work
+               if(exp.type == constantExp && exp.isConstant && exp.expType && exp.expType.kind == classType &&
+                  exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == unitClass && exp.expType._class.registered.base.type == unitClass)
+               {
+                  ApplyUnitConverters(exp);
+               }
+               else if(exp.type == instanceExp && exp.instance.data)
+               {
+                  Symbol s = exp.instance._class ? exp.instance._class.symbol : null;
+                  Class c = s ? s.registered : null;
+                  if(c)
+                  {
+                     char tmp[4096];
+                     bool needClass = false;
+                     char * s = ((char * (*)(void *, void *, void *, void *, void *))(void *)c._vTbl[__ecereVMethodID_class_OnGetString])(c, exp.instance.data, tmp, null, &needClass);
+                     if(s)
+                     {
+                        FreeExpContents(exp);
+                        exp.type = constantExp;
+                        exp.isConstant = true;
+                        exp.constant = CopyString(s);
+                     }
+                  }
+               }
+               else if(exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == bitClass)
+               {
+                  Class c = exp.expType._class.registered;
+                  char tmp[4096];
+                  bool needClass = false;
+                  Operand op = GetOperand(exp);
+                  char * s = null;
+                  char * (* onGetString)(void *, void *, void *, void *, void *) = (void *)c._vTbl[__ecereVMethodID_class_OnGetString];
+                  if(op.type)
+                  {
+                     if(op.type) op.type.refCount++;
+                     switch(op.kind)
+                     {
+                        case charType: s = onGetString(c, &op.c, tmp, null, &needClass); break;
+                        case shortType: s = onGetString(c, &op.s, tmp, null, &needClass); break;
+                        case intType: s = onGetString(c, &op.i, tmp, null, &needClass); break;
+                        case int64Type: s = onGetString(c, &op.i64, tmp, null, &needClass); break;
+                     }
+                  }
+                  if(s)
+                  {
+                     FreeExpContents(exp);
+                     exp.type = constantExp;
+                     exp.isConstant = true;
+                     exp.constant = CopyString(s);
+                  }
+                  FreeType(op.type);
+               }
+               else if(exp.expType && exp.expType.kind == classType && exp.expType._class && exp.expType._class.registered && exp.expType._class.registered.type == structClass && exp.hasAddress)
+               {
+                  Class c = exp.expType._class.registered;
+                  char structString[1024];
+                  strcpy(structString, "*(struct ");
+                  FullClassNameCat(structString, c.fullName, false);
+                  strcat(structString, " *)");
+                  strcatf(structString, "0x%p", exp.address);
+                  GDBFallBack(exp, structString);
+                  /*
+                  byte * data = GdbReadMemory(exp.address, c.structSize);
+                  if(data)
+                  {
+                     char tmp[4096];
+                     bool needClass = false;
+                     char * s = ((char * (*)(void *, void *, void *, void *, void *))(void *)c._vTbl[__ecereVMethodID_class_OnGetString])(c, data, tmp, null, &needClass);
+                     if(s)
+                     {
+                        FreeExpContents(exp);
+                        exp.type = constantExp;
+                        exp.isConstant = true;
+                        exp.constant = CopyString(s);
+                     }
+                     delete data;
+                  }
+                  */
+               }
+
+               if(ExpressionIsError(exp) && exp.type != functionCallErrorExp)
                {
                   GDBFallBack(exp, expString);
                }
@@ -2580,7 +2772,7 @@ class Debugger
                            long v = (long)exp.val.f;
                            sprintf(temp, "%i", v);
                            break;
-                        } 
+                        }
                         case doubleType:
                         {
                            long v = (long)exp.val.d;
@@ -2617,7 +2809,7 @@ class Debugger
                            long v = (long)exp.val.f;
                            sprintf(temp, "0x%x", v);
                            break;
-                        } 
+                        }
                         case doubleType:
                         {
                            long v = (long)exp.val.d;
@@ -2654,7 +2846,7 @@ class Debugger
                            long v = (long)exp.val.f;
                            sprintf(temp, "0o%o", v);
                            break;
-                        } 
+                        }
                         case doubleType:
                         {
                            long v = (long)exp.val.d;
@@ -2677,22 +2869,27 @@ class Debugger
                   case symbolErrorExp:
                      snprintf(watchmsg, sizeof(watchmsg), $"Symbol \"%s\" not found", exp.identifier.string);
                      break;
-                  case structMemberSymbolErrorExp:
-                     // todo get info as in next case (ExpClassMemberSymbolError)
-                     snprintf(watchmsg, sizeof(watchmsg), $"Error: Struct member not found for \"%s\"", wh.expression);
-                     break;
-                  case classMemberSymbolErrorExp:
+                  case memberSymbolErrorExp:
+                  {
+                     Expression memberExp = exp.member.exp;
+                     Identifier memberID = exp.member.member;
+                     Type type = memberExp.expType;
+                     if(type)
                      {
-                        Class _class;
-                        Expression memberExp = exp.member.exp;
-                        Identifier memberID = exp.member.member;
-                        Type type = memberExp.expType;
-                        if(type)
+                        if(type.kind == structType || type.kind == unionType)
+                        {
+                           char string[1024] = "";
+                           if(!type.name)
+                              PrintTypeNoConst(type, string, false, true);
+                           snprintf(watchmsg, sizeof(watchmsg), $"Member \"%s\" not found in %s \"%s\"",
+                              memberID ? memberID.string : "", type.kind == unionType ? "union" : "struct", type.name ? type.name : string);
+                        }
+                        else
                         {
-                           _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
+                           Class _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
+                           char string[1024] = "";
                            if(!_class)
                            {
-                              char string[256] = "";
                               Symbol classSym;
                               PrintTypeNoConst(type, string, false, true);
                               classSym = FindClass(string);
@@ -2701,50 +2898,73 @@ class Debugger
                            if(_class)
                               snprintf(watchmsg, sizeof(watchmsg), $"Member \"%s\" not found in class \"%s\"", memberID ? memberID.string : "", _class.name);
                            else
-                              snprintf(watchmsg, sizeof(watchmsg), "Member \"%s\" not found in unregistered class? (Should never get this message)", memberID ? memberID.string : "");
+                              // NOTE: This should probably never happen, only classes and struct can be dereferenced, a dereferenceErrorExp should be displayed instead
+                              snprintf(watchmsg, sizeof(watchmsg), $"Member \"%s\" not found in type \"%s\"", memberID ? memberID.string : "", string);
                         }
-                        else
-                           snprintf(watchmsg, sizeof(watchmsg), "Member \"%s\" not found in no type? (Should never get this message)", memberID ? memberID.string : "");
                      }
+                     else
+                        // NOTE: This should probably never happen, the error causing the unresolved expression should be displayed instead
+                        snprintf(watchmsg, sizeof(watchmsg), $"Accessing member \"%s\" from unresolved expression", memberID ? memberID.string : "");
+                     break;
+                  }
+                  case memberPropertyErrorExp:
+                  {
+                     Expression memberExp = exp.member.exp;
+                     Identifier memberID = exp.member.member;
+                     Type type = memberExp.expType;
+                     Class _class = (type && memberID) ? (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null) : null;
+                     if(_class && memberID && memberID.string)
+                        snprintf(watchmsg, sizeof(watchmsg), $"Missing property evaluation for \"%s\" in class \"%s\"", memberID.string, _class.name);
+                     else
+                        snprintf(watchmsg, sizeof(watchmsg), $"Missing property evaluation for \"%s\"", wh.expression);
+                     break;
+                  }
+                  case functionCallErrorExp:
+                     if(exp.call.exp && exp.call.exp.type == identifierExp && exp.call.exp.identifier.string)
+                        snprintf(watchmsg, sizeof(watchmsg), $"Missing function evaluation for call to \"%s\"", exp.call.exp.identifier.string);
+                     else
+                        snprintf(watchmsg, sizeof(watchmsg), $"Missing function evaluation for \"%s\"", wh.expression);
                      break;
                   case memoryErrorExp:
                      // Need to ensure when set to memoryErrorExp, constant is set
                      snprintf(watchmsg, sizeof(watchmsg), $"Memory can't be read at %s", /*(exp.type == constantExp) ? */exp.constant /*: null*/);
                      break;
                   case dereferenceErrorExp:
-                     snprintf(watchmsg, sizeof(watchmsg), $"Dereference failure for \"%s\"", wh.expression);
+                     snprintf(watchmsg, sizeof(watchmsg), $"Dereferencing error evaluating \"%s\"", wh.expression);
                      break;
-                  case unknownErrorExp:
-                     snprintf(watchmsg, sizeof(watchmsg), $"Unknown error for \"%s\"", wh.expression);
+                  case divideBy0ErrorExp:
+                     snprintf(watchmsg, sizeof(watchmsg), "%s", $"Integer division by 0");
                      break;
                   case noDebuggerErrorExp:
                      snprintf(watchmsg, sizeof(watchmsg), $"Debugger required for symbol evaluation in \"%s\"", wh.expression);
                      break;
-                  case debugStateErrorExp:
-                     snprintf(watchmsg, sizeof(watchmsg), $"Incorrect debugger state for symbol evaluation in \"%s\"", wh.expression);
+                  case unknownErrorExp:
+                     // NOTE: This should never happen
+                     snprintf(watchmsg, sizeof(watchmsg), $"Error evaluating \"%s\"", wh.expression);
                      break;
                   case 0:
+                     // NOTE: This should never happen
                      snprintf(watchmsg, sizeof(watchmsg), $"Null type for \"%s\"", wh.expression);
                      break;
-                  case constantExp:
                   case stringExp:
+                     wh.value = CopyString(exp.string);
+                     break;
+                  case constantExp:
                      // Temporary Code for displaying Strings
-                     if((exp.expType && ((exp.expType.kind == pointerType || 
-                              exp.expType.kind == arrayType) && exp.expType.type.kind == charType)) || 
-                           (wh.type && wh.type.kind == classType && wh.type._class && 
+                     if((exp.expType && ((exp.expType.kind == pointerType ||
+                              exp.expType.kind == arrayType) && exp.expType.type.kind == charType)) ||
+                           (wh.type && wh.type.kind == classType && wh.type._class &&
                               wh.type._class.registered && wh.type._class.registered.type == normalClass &&
                               !strcmp(wh.type._class.registered.name, "String")))
                      {
 
-                        if(exp.expType.kind != arrayType || exp.hasAddress)
+                        if(exp.expType && (exp.expType.kind != arrayType || exp.hasAddress))
                         {
                            uint64 address;
-                           char * string;
                            char value[4196];
-                           int len;
                            //char temp[MAX_F_STRING * 32];
 
-                           ExpressionType evalError = dummyExp;
+                           //ExpressionType evalError = dummyExp;
                            /*if(exp.expType.kind == arrayType)
                               sprintf(temp, "(char*)0x%x", exp.address);
                            else
@@ -2753,78 +2973,107 @@ class Debugger
                            //evaluation = Debugger::EvaluateExpression(temp, &evalError);
                            // address = strtoul(exp.constant, null, 0);
                            address = _strtoui64(exp.constant, null, 0);
-                           //_dpl(0, "0x", address);
+                           //_dplf(0, "0x", address);
                            // snprintf(value, sizeof(value), "0x%08x ", address);
 
                            if(address > 0xFFFFFFFFLL)
-                              snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%016I64x " : "0x%016llx ", address);
+                              snprintf(value, sizeof(value), (__runtimePlatform == win32) ? "0x%016I64x " : "0x%016llx ", address);
                            else
-                              snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%08I64x " : "0x%08llx ", address);
+                              snprintf(value, sizeof(value), (__runtimePlatform == win32) ? "0x%08I64x " : "0x%08llx ", address);
                            value[sizeof(value)-1] = 0;
-                           
+
                            if(!address)
                               strcat(value, $"Null string");
                            else
                            {
-                              int size = 4096;
-                              len = strlen(value);
-                              string = null;
-                              while(!string && size > 2)
+                              String string = new char[4097];
+                              int start = 0;
+                              bool success = false;
+                              int size = 256;
+                              bool done = false;
+
+                              for(start = 0; !done && start + size <= 4096; start += size)
                               {
-                                 string = GdbReadMemory(address, size);
-                                 size /= 2;
+                                 byte * s = null;
+                                 while(!done && !s)
+                                 {
+                                    // Try to read 256 bytes at a time, then half if that fails
+                                    s = GdbReadMemory(address + start, size);
+                                    if(s)
+                                    {
+                                       success = true;
+                                       memcpy(string + start, s, size);
+                                       string[start + size] = 0;
+                                       if(size == 1 || memchr(s, 0, size))
+                                          done = true;
+                                    }
+                                    else if(size > 1)
+                                       size /= 2;
+                                    else
+                                       done = true;
+                                 }
+                                 delete s;
                               }
-                              if(string && string[0])
+                              if(success)
                               {
-                                 value[len++] = '(';
-                                 if(UTF8Validate(string))
+                                 if(string[0])
                                  {
-                                    int c;
-                                    char ch;
-                                    
-                                    for(c = 0; (ch = string[c]) && c<4096; c++)
-                                       value[len++] = ch;                                 
-                                    value[len++] = ')';
-                                    value[len++] = '\0';
-                                    
+                                    int len = strlen(value);
+                                    value[len++] = '(';
+                                    if(UTF8Validate(string))
+                                    {
+                                       int c;
+                                       char ch;
+
+                                       for(c = 0; (ch = string[c]); c++)
+                                          value[len++] = ch;
+                                       value[len++] = ')';
+                                       value[len++] = '\0';
+
+                                    }
+                                    else
+                                    {
+                                       ISO8859_1toUTF8(string, value + len, strlen(value) - len - 30);
+                                       strcat(value, ") (ISO8859-1)");
+                                    }
                                  }
                                  else
-                                 {
-                                    ISO8859_1toUTF8(string, value + len, 4096 - len - 30);
-                                    strcat(value, ") (ISO8859-1)");
-                                 }
-
-                                 delete string;
-                              }
-                              else if(string)
-                              {
-                                 strcat(value, $"Empty string");
-                                 delete string;
+                                    strcat(value, $"Empty string");
                               }
                               else
                                  strcat(value, $"Couldn't read memory");
+                              delete string;
                            }
                            wh.value = CopyString(value);
                         }
                      }
-                     else if(wh.type && wh.type.kind == classType && wh.type._class && 
+                     else if(wh.type && wh.type.kind == classType && wh.type._class &&
                               wh.type._class.registered && wh.type._class.registered.type == enumClass)
                      {
-                        uint64 value = strtoul(exp.constant, null, 0);
                         Class enumClass = eSystem_FindClass(GetPrivateModule(), wh.type._class.registered.name);
                         EnumClassData enumeration = (EnumClassData)enumClass.data;
-                        NamedLink item;
+                        NamedLink64 item;
+                        int64 value;
+
+                        if(!strcmp(enumClass.dataTypeString, "uint64"))
+                        {
+                           uint64 v = strtoull(exp.constant, null, 0);
+                           value = *(int64*)&v;
+                        }
+                        else
+                           value = strtoll(exp.constant, null, 0);
+
                         for(item = enumeration.values.first; item; item = item.next)
-                           if((int)item.data == value)
+                           if(item.data == value)
                               break;
                         if(item)
                            wh.value = CopyString(item.name);
                         else
-                           wh.value = CopyString($"Invalid Enum Value");
+                           wh.value = PrintString($"Invalid Enum Value (", value, ")");
                         result = true;
                      }
-                     else if(wh.type && (wh.type.kind == charType || (wh.type.kind == classType && wh.type._class && 
-                              wh.type._class.registered && !strcmp(wh.type._class.registered.fullName, "ecere::com::unichar"))) )
+                     else if(wh.type && (wh.type.kind == charType || (wh.type.kind == classType && wh.type._class &&
+                              wh.type._class.registered && !strcmp(wh.type._class.registered.fullName, "unichar"))) )
                      {
                         unichar value;
                         int signedValue;
@@ -2882,14 +3131,14 @@ class Debugger
                         else if(value > 256 || wh.type.kind != charType)
                         {
                            if(value > 0x10FFFF || !GetCharCategory(value))
-                              snprintf(string, sizeof(string), $"Invalid Unicode Keypoint (0x%08X)", value);
+                              snprintf(string, sizeof(string), $"Invalid Unicode Codepoint (0x%08X)", value);
                            else
                               snprintf(string, sizeof(string), "\'%s\' (U+%04X)", charString, value);
                         }
                         else
                            snprintf(string, sizeof(string), "\'%s\' (%d)", charString, value);
                         string[sizeof(string)-1] = 0;
-                        
+
                         wh.value = CopyString(string);
                         result = true;
                      }
@@ -2900,37 +3149,63 @@ class Debugger
                      }
                      break;
                   default:
-                     if(exp.hasAddress)
-                     {
-                        wh.value = PrintHexUInt64(exp.address);
-                        result = true;
-                     }
-                     else
+                  {
+                     bool genericError = true;
+                     if(exp.expType && exp.hasAddress)
                      {
-                        char tempString[256];
-                        if(exp.member.memberType == propertyMember)
-                           snprintf(watchmsg, sizeof(watchmsg), $"Missing property evaluation support for \"%s\"", wh.expression);
-                        else
-                           snprintf(watchmsg, sizeof(watchmsg), $"Evaluation failed for \"%s\" of type \"%s\"", wh.expression, 
-                                 exp.type.OnGetString(tempString, null, null));
+                        bool showAddress = false;
+                        switch(exp.expType.kind)
+                        {
+                           case pointerType:
+                           case functionType:
+                           case methodType:
+                           case arrayType:
+                           case subClassType:
+                           case thisClassType:
+                              showAddress = true;
+                              break;
+                           case classType:
+                           {
+                              Symbol s = exp.expType._class;
+                              if(s)
+                              {
+                                 Class c = s.registered;
+                                 if(c.type == noHeadClass || c.type == normalClass)
+                                    showAddress = true;
+                              }
+                              break;
+                           }
+                        }
+                        if(showAddress)
+                        {
+                           wh.value = PrintHexUInt64(exp.address);
+                           result = true;
+                           genericError = false;
+                        }
                      }
+                     if(genericError)
+                        // NOTE: This should ideally be handled with a specific error message
+                        snprintf(watchmsg, sizeof(watchmsg), $"Error evaluating \"%s\"", wh.expression);
                      break;
+                  }
                }
+
+               SetInDebugger(false);
             }
             else
                snprintf(watchmsg, sizeof(watchmsg), $"Invalid expression: \"%s\"", wh.expression);
             if(exp) FreeExpression(exp);
 
-            
+
             SetPrivateModule(backupPrivateModule);
             SetCurrentContext(backupContext);
             SetTopContext(backupContext);
             SetGlobalContext(backupContext);
             SetThisClass(backupThisClass);
          }
-         //else 
+         //else
          //   wh.value = CopyString("No source file found for selected frame");
-         
+
          watchmsg[sizeof(watchmsg)-1] = 0;
          if(!wh.value)
             wh.value = CopyString(watchmsg);
@@ -2941,17 +3216,21 @@ class Debugger
 
    void EvaluateWatches()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::EvaluateWatches()");
-      for(wh : ide.workspace.watches)
-         ResolveWatch(wh);
+      _dpcl(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateWatches()");
+      WatchesLinkCodeEditor();
+      if(state == stopped)
+      {
+         for(wh : ide.workspace.watches)
+            ResolveWatch(wh);
+      }
    }
 
    char * ::GdbEvaluateExpression(char * expression)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbEvaluateExpression(", expression, ")");
+      _dpcl(_dpct, dplchan::debuggerWatches, 0, "Debugger::GdbEvaluateExpression(", expression, ")");
       eval.active = true;
       eval.error = none;
-      GdbCommand(false, "-data-evaluate-expression \"%s\"", expression);
+      GdbCommand(0, false, "-data-evaluate-expression \"%s\"", expression);
       if(eval.active)
          ide.outputView.debugBox.Logf("Debugger Error: GdbEvaluateExpression\n");
       return eval.result;
@@ -2960,18 +3239,15 @@ class Debugger
    // to be removed... use GdbReadMemory that returns a byte array instead
    char * ::GdbReadMemoryString(uint64 address, int size, char format, int rows, int cols)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemoryString(", address, ")");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemoryString(", address, ")");
       eval.active = true;
       eval.error = none;
 #ifdef _DEBUG
       if(!size)
-         _dpl(0, "GdbReadMemoryString called with size = 0!");
+         _dplf(0, "GdbReadMemoryString called with size = 0!");
 #endif
-      // GdbCommand(false, "-data-read-memory 0x%08x %c, %d, %d, %d", address, format, size, rows, cols);
-      if(GetRuntimePlatform() == win32)
-         GdbCommand(false, "-data-read-memory 0x%016I64x %c, %d, %d, %d", address, format, size, rows, cols);
-      else
-         GdbCommand(false, "-data-read-memory 0x%016llx %c, %d, %d, %d", address, format, size, rows, cols);
+      GdbCommand(0, false,
+         (__runtimePlatform == win32) ? "-data-read-memory 0x%016I64x %c, %d, %d, %d" : "-data-read-memory 0x%016llx %c, %d, %d, %d", address, format, size, rows, cols);
       if(eval.active)
          ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemoryString\n");
       return eval.result;
@@ -2979,24 +3255,22 @@ class Debugger
 
    byte * ::GdbReadMemory(uint64 address, int bytes)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemory(", address, ")");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemory(", address, ")");
       eval.active = true;
       eval.error = none;
-      //GdbCommand(false, "-data-read-memory 0x%08x %c, 1, 1, %d", address, 'u', bytes);
-      if(GetRuntimePlatform() == win32)
-         GdbCommand(false, "-data-read-memory 0x%016I64x %c, 1, 1, %d", address, 'u', bytes);
-      else
-         GdbCommand(false, "-data-read-memory 0x%016llx %c, 1, 1, %d", address, 'u', bytes);
+      GdbCommand(0, false,
+         (__runtimePlatform == win32) ? "-data-read-memory 0x%016I64x %c, 1, 1, %d" : "-data-read-memory 0x%016llx %c, 1, 1, %d",
+         address, 'u', bytes);
 #ifdef _DEBUG
       if(!bytes)
-         _dpl(0, "GdbReadMemory called with bytes = 0!");
+         _dplf(0, "GdbReadMemory called with bytes = 0!");
 #endif
       if(eval.active)
          ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemory\n");
       else if(eval.result && strcmp(eval.result, "N/A"))
       {
          byte * result = new byte[bytes];
-         byte * string = eval.result;
+         char * string = eval.result;
          int c = 0;
          while(true)
          {
@@ -3011,70 +3285,86 @@ class Debugger
             else
                break;
          }
+         delete eval.result;
          return result;
       }
       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(",
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::BreakpointHit(",
             "bpInternal(", bpInternal ? s1=bpInternal.CopyLocationString(false) : null, "), ",
             "bpUser(", bpUser ? s2=bpUser.CopyLocationString(false) : null, ")) -- ",
             "ignoreBreakpoints(", ignoreBreakpoints, "), ",
             "hitCursorBreakpoint(", bpUser && bpUser.type == runToCursor,  ")");
       delete s1; delete s2;
 
-      if(bpUser && stopItem.frame.line && bpUser.line != stopItem.frame.line)
-      {
-         // updating user breakpoint on hit location difference
-         // todo, print something?
-         bpUser.line = stopItem.frame.line;
-         ide.breakpointsView.UpdateBreakpoint(bpUser.row);
-         ide.workspace.Save();
-      }
-      if(bpInternal)
-      {
-         bpInternal.hits++;
-         if(bpInternal.type == internalModulesLoaded)
-            modules = true;
-         if(!bpUser && !userBreakOnInternalBreakpoint)
-            GdbExecContinue(false);
-      }
       if(bpUser)
       {
          bool conditionMet = true;
          if(bpUser.condition)
-            conditionMet = ResolveWatch(bpUser.condition);
+         {
+            if(WatchesLinkCodeEditor())
+               conditionMet = ResolveWatch(bpUser.condition);
+            else
+               conditionMet = false;
+         }
          bpUser.hits++;
-         if(!ignoreBreakpoints && (bpUser.level == -1 || bpUser.level == frameCount-1) && conditionMet)
+         if(conditionMet)
          {
             if(!bpUser.ignore)
                bpUser.breaks++;
             else
             {
                bpUser.ignore--;
-               GdbExecContinue(false);
+               result = false;
             }
          }
          else
-            GdbExecContinue(false);
-         ide.breakpointsView.UpdateBreakpoint(bpUser.row);
-         if(bpUser == bpRunToCursor)
+            result = false;
+         if(stopItem.frame.line && bpUser.line != stopItem.frame.line)
+         {
+            // updating user breakpoint on hit location difference
+            // todo, print something?
+            bpUser.line = stopItem.frame.line;
+            ide.breakpointsView.UpdateBreakpoint(bpUser.row);
+            ide.workspace.Save();
+         }
+         else
+            ide.breakpointsView.UpdateBreakpoint(bpUser.row);
+      }
+      if(bpInternal)
+      {
+         bpInternal.hits++;
+         if(bpInternal.type == internalModulesLoaded)
+            modules = true;
+         if(userAction == stepOver)
+         {
+            if((bpInternal.type == internalEntry && ((intBpMain && intBpMain.inserted) || (intBpWinMain && intBpWinMain.inserted))) ||
+                  (bpInternal.type == internalMain && intBpWinMain && intBpWinMain.inserted))
+               result = false;
+         }
+         if(!bpUser && !userAction.breaksOnInternalBreakpoint)
          {
-            UnsetBreakpoint(bpUser);
-            delete bpRunToCursor;
+            if(userAction == stepOut)
+               StepOut(ignoreBreakpoints);
+            else
+               result = false;
          }
       }
 
       if(!bpUser && !bpInternal)
-         GdbExecContinue(false);
+         result = false;
+
+      return result;
    }
 
    void ValgrindTargetThreadExit()
    {
-      ide.outputView.debugBox.Logf($"ValgrindTargetThreadExit\n");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::ValgrindTargetThreadExit()");
       if(vgTargetHandle)
       {
          vgTargetHandle.Wait();
@@ -3085,43 +3375,44 @@ class Debugger
 
    void GdbThreadExit()
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbThreadExit()");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbThreadExit()");
       if(state != terminated)
       {
-         ChangeState(terminated);
+         _ChangeState(terminated);
          targetProcessId = 0;
          ClearBreakDisplay();
 
-         if(vgLogFile)
-            delete vgLogFile;
+         delete vgLogFile;
          if(gdbHandle)
          {
             serialSemaphore.Release();
             gdbTimer.Stop();
             gdbHandle.Wait();
             delete gdbHandle;
-            
+
             ide.outputView.debugBox.Logf($"Debugger Fatal Error: GDB lost\n");
             ide.outputView.debugBox.Logf($"Debugging stopped\n");
             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 { };
       DebugListItem item2 { };
       bool setWaitingForPID = false;
-      
+
 #if defined(GDB_DEBUG_CONSOLE) || defined(GDB_DEBUG_GUI)
 #ifdef GDB_DEBUG_CONSOLE
-      _dpl2(_dpct, dplchan::gdbOutput, 0, output);
+      // _dpcl(_dpct, dplchan::gdbOutput, 0, output);
+      puts(output);
 #endif
 #ifdef GDB_DEBUG_OUTPUT
       {
@@ -3154,7 +3445,7 @@ class Debugger
          if(ide.gdbDialog) ide.gdbDialog.AddOutput(output);
 #endif
 #endif
-      
+
       switch(output[0])
       {
          case '~':
@@ -3164,6 +3455,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;
@@ -3174,7 +3482,7 @@ class Debugger
                   if(sentKill)
                   {
                      sentKill = false;
-                     ChangeState(loaded);
+                     _ChangeState(loaded);
                      targetProcessId = 0;
                      if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
                      {
@@ -3199,7 +3507,7 @@ class Debugger
                            }
                         }
                         else
-                           _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "kill reply (", item.name, "=", item.value, ") is unheard of");
+                           _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "kill reply (", item.name, "=", item.value, ") is unheard of");
                      }
                      else
                         HandleExit(null, null);
@@ -3212,8 +3520,9 @@ class Debugger
                      sentBreakInsert = false;
 #ifdef _DEBUG
                      if(bpItem)
-                        _dpl(0, "problem");
+                        _dplf(0, "problem");
 #endif
+                     delete bpItem;
                      bpItem = ParseBreakpoint(item.value, outTokens);
                      //breakType = bpValidation;
                   }
@@ -3244,10 +3553,10 @@ class Debugger
                               item.value = StripCurlies(item.value);
                               ParseFrame(frame, item.value);
                               if(frame.file && frame.from)
-                                 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "unexpected frame file and from members present");
+                                 _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "unexpected frame file and from members present");
                               if(frame.file)
                               {
-                                 char * s;
+                                 char * s = null;
                                  if(activeFrameLevel == -1)
                                  {
                                     if(ide.projectView.IsModuleInProject(frame.file));
@@ -3281,7 +3590,7 @@ class Debugger
 
                                  if(frame.from)
                                  {
-                                    char * s;
+                                    char * s = null;
                                     ide.callStackView.Logf($"inside %s, %s\n", frame.func, (s = CopySystemPath(frame.from)));
                                     delete s;
                                  }
@@ -3292,7 +3601,7 @@ class Debugger
                               }
                            }
                            else
-                              _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "stack content (", item.name, "=", item.value, ") is unheard of");
+                              _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "stack content (", item.name, "=", item.value, ") is unheard of");
                         }
                      }
                      if(activeFrameLevel == -1)
@@ -3327,7 +3636,7 @@ class Debugger
                               ide.threadsView.Logf("%3d \n", value);
                            }
                            else
-                              _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "threads content (", item.name, "=", item.value, ") is unheard of");
+                              _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "threads content (", item.name, "=", item.value, ") is unheard of");
                         }
                         if(!i)
                            break;
@@ -3392,19 +3701,20 @@ class Debugger
                      }
                   }
                   else if(!strcmp(item.name, "source-path") || !strcmp(item.name, "BreakpointTable"))
-                     _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "command reply (", item.name, "=", item.value, ") is ignored");
+                     _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, "command reply (", item.name, "=", item.value, ") is ignored");
                   else
-                     _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "command reply (", item.name, "=", item.value, ") is unheard of");
+                     _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "command reply (", item.name, "=", item.value, ") is unheard of");
                }
             }
             else if(!strcmp(outTokens[0], "^running"))
             {
                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;
@@ -3442,12 +3752,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."))
@@ -3455,17 +3765,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
@@ -3473,7 +3783,7 @@ class Debugger
 #ifdef _DEBUG
                         if(strlen(item.value) < MAX_F_STRING)
                         {
-                           char * s;
+                           char * s = null;
                            ide.outputView.debugBox.Logf("GDB: %s\n", (s = CopyUnescapedString(item.value)));
                            delete s;
                         }
@@ -3484,32 +3794,34 @@ class Debugger
                   }
                }
                else
-                  _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "error content (", item.name, "=", item.value, ") is unheard of");
+                  _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "error content (", item.name, "=", item.value, ") is unheard of");
             }
             else
-               _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "result-record: ", outTokens[0]);
+               _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "result-record: ", outTokens[0]);
             outTokens.RemoveAll();
             break;
          case '+':
-            _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "status-async-output: ", outTokens[0]);
+            _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "status-async-output: ", outTokens[0]);
             break;
          case '=':
             if(TokenizeList(output, ',', outTokens))
             {
                if(!strcmp(outTokens[0], "=library-loaded"))
-                  FGODetectLoadedLibraryForAddedProjectIssues(outTokens);
+                  FGODetectLoadedLibraryForAddedProjectIssues(outTokens, false);
+               else if(!strcmp(outTokens[0], "=shlibs-added"))
+                  FGODetectLoadedLibraryForAddedProjectIssues(outTokens, true);
                else if(!strcmp(outTokens[0], "=thread-group-created") || !strcmp(outTokens[0], "=thread-group-added") ||
                         !strcmp(outTokens[0], "=thread-group-started") || !strcmp(outTokens[0], "=thread-group-exited") ||
                         !strcmp(outTokens[0], "=thread-created") || !strcmp(outTokens[0], "=thread-exited") ||
                         !strcmp(outTokens[0], "=cmd-param-changed") || !strcmp(outTokens[0], "=library-unloaded") ||
                         !strcmp(outTokens[0], "=breakpoint-modified"))
-                  _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, outTokens[0], outTokens.count>1 ? outTokens[1] : "",
+                  _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, outTokens[0], outTokens.count>1 ? outTokens[1] : "",
                            outTokens.count>2 ? outTokens[2] : "", outTokens.count>3 ? outTokens[3] : "",
                            outTokens.count>4 ? outTokens[4] : "", outTokens.count>5 ? outTokens[5] : "",
                            outTokens.count>6 ? outTokens[6] : "", outTokens.count>7 ? outTokens[7] : "",
                            outTokens.count>8 ? outTokens[8] : "", outTokens.count>9 ? outTokens[9] : "");
                else
-                  _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "notify-async-output: ", outTokens[0]);
+                  _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "notify-async-output: ", outTokens[0]);
             }
             outTokens.RemoveAll();
             break;
@@ -3525,7 +3837,7 @@ class Debugger
                else if(!strcmp(outTokens[0], "*stopped"))
                {
                   int tk;
-                  ChangeState(stopped);
+                  _ChangeState(stopped);
 
                   for(tk = 1; tk < outTokens.count; tk++)
                   {
@@ -3552,71 +3864,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"))
-                           {
-      #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"))
+                           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
+                              char r = reason[0];
+#ifdef _DEBUG
+                              if(stopItem) _dplf(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++)
                               {
@@ -3629,45 +3888,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"))
+                                    _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Advanced thread debugging not handled");
+                                 else if(!strcmp(item.name, "core"))
+                                    _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Information (core) not used");
+                                 else if(!strcmp(item.name, "disp"))
+                                    _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": (", item.name, "=", item.value, ")");
                                  else
-                                    _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown signal reveived item name (", item.name, "=", item.value, ")");
+                                    _dpcl(_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)
                                  {
@@ -3683,21 +3924,20 @@ 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"))
-                              _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint trigger not handled");
+                              _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint trigger not handled");
                            else if(!strcmp(reason, "read-watchpoint-trigger"))
-                              _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason read watchpoint trigger not handled");
+                              _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, "Reason read watchpoint trigger not handled");
                            else if(!strcmp(reason, "access-watchpoint-trigger"))
-                              _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason access watchpoint trigger not handled");
+                              _dpcl(_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");
+                              _dpcl(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint scope not handled");
                            else
-                              _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown reason: ", reason);
+                              _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown reason: ", reason);
                         }
                         else
                         {
@@ -3711,7 +3951,7 @@ class Debugger
                }
             }
             else
-               _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown exec-async-output: ", outTokens[0]);
+               _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown exec-async-output: ", outTokens[0]);
             outTokens.RemoveAll();
             break;
          case '(':
@@ -3719,6 +3959,7 @@ class Debugger
             {
                if(waitingForPID)
                {
+                  Time startTime = GetTime();
                   char exeFile[MAX_LOCATION];
                   int oldProcessID = targetProcessId;
                   GetLastDirectory(targetFile, exeFile);
@@ -3726,19 +3967,23 @@ class Debugger
                   while(!targetProcessId/*true*/)
                   {
                      targetProcessId = Process_GetChildExeProcessId(gdbProcessId, exeFile);
-                     if(targetProcessId || gdbHandle.Peek()) break;
+                     if(targetProcessId) break;
+                     // Can't break on Peek(), GDB is giving us =library and other info before the process is listed in /proc
+                     // if(gdbHandle.Peek()) break;
                      Sleep(0.01);
+                     if(gdbHandle.Peek() && GetTime() - startTime > 2.5)  // Give the process 2.5 seconds to show up in /proc
+                        break;
                   }
 
                   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)
@@ -3778,7 +4023,7 @@ class Debugger
                serialSemaphore.Release();
             }
             else
-               _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown prompt", output);
+               _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown prompt", output);
 
             break;
          case '&':
@@ -3792,7 +4037,7 @@ class Debugger
                   content++;
                if(content)
                {
-                  char * s;
+                  char * s = null;
                   ide.outputView.debugBox.LogRaw((s = CopyUnescapedString(content)));
                   delete s;
                   ide.Update(null);
@@ -3800,7 +4045,7 @@ class Debugger
             }
             break;
          default:
-            _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown output: ", output);
+            _dpcl(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown output: ", output);
       }
       if(!setWaitingForPID)
          waitingForPID = false;
@@ -3813,13 +4058,13 @@ class Debugger
    }
 
    // From GDB Output functions
-   void FGODetectLoadedLibraryForAddedProjectIssues(Array<char *> outTokens)
+   void FGODetectLoadedLibraryForAddedProjectIssues(Array<char *> outTokens, bool shlibs)
    {
       char path[MAX_LOCATION] = "";
       char file[MAX_FILENAME] = "";
-      bool symbolsLoaded;
+      //bool symbolsLoaded = false;
       DebugListItem item { };
-      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::FGODetectLoadedLibraryForAddedProjectIssues()");
+      //_dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::FGODetectLoadedLibraryForAddedProjectIssues()");
       for(token : outTokens)
       {
          if(TokenizeListItem(token, item))
@@ -3832,7 +4077,30 @@ class Debugger
             }
             else if(!strcmp(item.name, "symbols-loaded"))
             {
-               symbolsLoaded = (atoi(item.value) == 1);
+               //symbolsLoaded = (atoi(item.value) == 1);
+            }
+            else if(!strcmp(item.name, "shlib-info"))
+            {
+               DebugListItem subItem { };
+               Array<char *> tokens { minAllocSize = 50 };
+               item.value = StripBrackets(item.value);
+               TokenizeList(item.value, ',', tokens);
+               for(t : tokens)
+               {
+                  if(TokenizeListItem(t, subItem))
+                  {
+                     if(!strcmp(subItem.name, "path"))
+                     {
+                        StripQuotes(subItem.value, path);
+                        MakeSystemPath(path);
+                        GetLastDirectory(path, file);
+                        //symbolsLoaded = true;
+                     }
+                  }
+               }
+               tokens.RemoveAll();
+               delete tokens;
+               delete subItem;
             }
          }
       }
@@ -3848,6 +4116,7 @@ class Debugger
             DirExpression targetDirExp = prj.GetTargetDir(currentCompiler, prj.config, bitDepth);
             strcpy(prjTargetPath, prj.topNode.path);
             PathCat(prjTargetPath, targetDirExp.dir);
+            delete targetDirExp;
             prjTargetFile[0] = '\0';
             prj.CatTargetFileName(prjTargetFile, currentCompiler, prj.config);
             PathCat(prjTargetPath, prjTargetFile);
@@ -3890,7 +4159,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;
             }
@@ -3900,7 +4171,7 @@ class Debugger
 
    void FGOBreakpointModified(Array<char *> outTokens)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::FGOBreakpointModified() -- TODO only if needed: support breakpoint modified");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::FGOBreakpointModified() -- TODO only if needed: support breakpoint modified");
 #if 0
       DebugListItem item { };
       if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
@@ -3917,7 +4188,7 @@ class Debugger
 
    ExpressionType ::DebugEvalExpTypeError(char * result)
    {
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::DebugEvalExpTypeError()");
+      _dpcl(_dpct, dplchan::debuggerWatches, 0, "Debugger::DebugEvalExpTypeError()");
       if(result)
          return dummyExp;
       switch(eval.error)
@@ -3933,7 +4204,7 @@ class Debugger
    char * ::EvaluateExpression(char * expression, ExpressionType * error)
    {
       char * result;
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::EvaluateExpression(", expression, ")");
+      _dpcl(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateExpression(", expression, ")");
       if(ide.projectView && ide.debugger.state == stopped)
       {
          result = GdbEvaluateExpression(expression);
@@ -3951,7 +4222,7 @@ class Debugger
    {
       // check for state
       char * result = GdbReadMemoryString(address, size, format, 1, 1);
-      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ReadMemory(", address, ")");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "Debugger::ReadMemory(", address, ")");
       if(!result || !strcmp(result, "N/A"))
          *error = memoryErrorExp;
       else
@@ -3967,18 +4238,20 @@ class ValgrindLogThread : Thread
    unsigned int Main()
    {
       static char output[4096];
+      bool lastLineEmpty = true;
       Array<char> dynamicBuffer { minAllocSize = 4096 };
       File oldValgrindHandle = vgLogFile;
       incref oldValgrindHandle;
 
       app.Lock();
-      while(debugger.state != terminated && vgLogFile)
+      while(debugger.state != terminated && vgLogFile && vgLogFile.input)
       {
-         int result;
+         int result = 0;
          app.Unlock();
-         result = vgLogFile.Read(output, 1, sizeof(output));
+         if(vgLogFile)
+            result = vgLogFile.Read(output, 1, sizeof(output));
          app.Lock();
-         if(debugger.state == terminated || !vgLogFile/* || vgLogFile.Eof()*/)
+         if(debugger.state == terminated || !vgLogFile) // || vgLogFile.Eof()
             break;
          if(result)
          {
@@ -3993,16 +4266,85 @@ class ValgrindLogThread : Thread
                   dynamicBuffer.size += c - start;
                   memcpy(&dynamicBuffer[pos], output + start, c - start);
                   if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
-                  // COMMENTED OUT DUE TO ISSUE #135, FIXED
-                  //if(dynamicBuffer.array[dynamicBuffer.count - 1] != '\r')
                      dynamicBuffer.size++;
                   dynamicBuffer[dynamicBuffer.count - 1] = '\0';
 #ifdef _DEBUG
                   // printf("%s\n", dynamicBuffer.array);
 #endif
-                  if(strstr(&dynamicBuffer[0], "vgdb me"))
+                  if(strstr(&dynamicBuffer[0], "vgdb me ..."))
                      debugger.serialSemaphore.Release();
-                  ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
+                  {
+                     char * s = strstr(&dynamicBuffer[0], "==");
+                     if(s)
+                        s = strstr(s+2, "== ");
+                     if(s)
+                     {
+                        s += 3;
+                        if(s[0] == '\0' && !lastLineEmpty)
+                        {
+                           s = null;
+                           lastLineEmpty = true;
+                           dynamicBuffer[0] = '\0';
+                        }
+                     }
+                     if(s)
+                     {
+                        char * t = s;
+                        switch(s[0])
+                        {
+                           case '(':
+                              if(strstr(s, "vgdb me ..."))
+                              {
+                                 if(strstr(s, "(action on error) vgdb me ..."))
+                                    ide.outputView.debugBox.Logf($"...breaked on Valgrind error (F5 to resume)\n");
+                                 s[0] = '\0';
+                              }
+                              else
+                                 s = null;
+                              break;
+                           case 'T':
+                              if(strstr(s, "TO DEBUG THIS PROCESS USING GDB: start GDB like this"))
+                                 s[0] = '\0';
+                              else
+                                 s = null;
+                              break;
+                           case 'a':
+                              if(strstr(s, "and then give GDB the following command"))
+                                 s[0] = '\0';
+                              else
+                                 s = null;
+                              break;
+                           case ' ':
+                              if(strstr(s, "/path/to/gdb") || strstr(s, "target remote | /usr/lib/valgrind/../../bin/vgdb --pid="))
+                                 s[0] = '\0';
+                              else
+                                 s = null;
+                              break;
+                           case '-':
+                              if(strstr(s, "--pid is optional if only one valgrind process is running"))
+                                 s[0] = '\0';
+                              else
+                                 s = null;
+                              break;
+                           case 'U':
+                              if((s = strstr(s, "; rerun with -h for copyright info")))
+                              {
+                                 s[0] = '\0';
+                                 s = null;
+                              }
+                              break;
+                           case '\0':
+                              break;
+                           default:
+                              s = null;
+                              break;
+                        }
+                        if(lastLineEmpty && t[0] != '\0')
+                           lastLineEmpty = false;
+                     }
+                     if(!s)
+                        ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
+                  }
                   dynamicBuffer.size = 0;
                   start = c + 1;
                }
@@ -4025,7 +4367,7 @@ class ValgrindLogThread : Thread
          }
       }
       delete dynamicBuffer;
-      ide.outputView.debugBox.Logf($"ValgrindLogThreadExit\n");
+      _dpcl(_dpct, dplchan::debuggerCall, 0, "ValgrindLogThreadExit");
       //if(oldValgrindHandle == vgLogFile)
          debugger.GdbThreadExit/*ValgrindLogThreadExit*/();
       delete oldValgrindHandle;
@@ -4141,7 +4483,7 @@ class GdbThread : Thread
                      dynamicBuffer.size++;
                   dynamicBuffer[dynamicBuffer.count - 1] = '\0';
 #ifdef _DEBUG
-                  // _dpl(0, dynamicBuffer.array);
+                  // _dplf(0, dynamicBuffer.array);
 #endif
                   debugger.GdbThreadMain(&dynamicBuffer[0]);
                   dynamicBuffer.size = 0;
@@ -4158,7 +4500,7 @@ class GdbThread : Thread
          else
          {
 #ifdef _DEBUG
-            _dpl(0, "Got end of file from GDB!");
+            _dplf(0, "Got end of file from GDB!");
 #endif
          }
       }
@@ -4189,11 +4531,11 @@ class ProgramThread : Thread
    bool terminate;
    unsigned int Main()
    {
-      bool result = true;
-      bool fileCreated = false;
-      mode_t mask = 0600;
+      //bool result = true;
+      //bool fileCreated = false;
+      //mode_t mask = 0600;
       static char output[1000];
-      int fd;
+      int fd = 0;
 
       /*if(!mkfifo(progFifoPath, mask))
       {
@@ -4226,14 +4568,14 @@ class ProgramThread : Thread
       {
          fd_set rs, es;
          struct timeval time;
-         int selectResult;
+         //int selectResult;
          time.tv_sec = 1;
          time.tv_usec = 0;
          FD_ZERO(&rs);
          FD_ZERO(&es);
          FD_SET(fd, &rs);
          FD_SET(fd, &es);
-         selectResult = select(fd + 1, &rs, null, null, &time);
+         /*selectResult = */select(fd + 1, &rs, null, null, &time);
          if(FD_ISSET(fd, &rs))
          {
             int result = (int)read(fd, output, sizeof(output)-1);
@@ -4328,7 +4670,7 @@ class Frame : struct
 
 class GdbDataStop : struct
 {
-   char * reason;
+   DebuggerReason reason;
    int threadid;
    union
    {
@@ -4353,17 +4695,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();
    }
@@ -4401,7 +4742,7 @@ class GdbDataBreakpoint : struct
 
    void Print()
    {
-   _dpl(0, "");
+   _dplf(0, "");
       PrintLn("{", "#", number, " T", type, " D", disp, " E", enabled, " H", times, " (", func, ") (", file, ":", line, ") (", fullname, ") (", addr, ") (", at, ")", "}");
    }
 
@@ -4415,6 +4756,8 @@ class GdbDataBreakpoint : struct
       delete at;
       if(multipleBPs) multipleBPs.Free();
       delete multipleBPs;
+      delete number;
+      delete fullname;
    }
 
    ~GdbDataBreakpoint()
@@ -4428,11 +4771,13 @@ class Breakpoint : struct
    class_no_expansion;
 
    char * function;
-   property char * function { set { delete function; if(value) function = CopyString(value); } }
+   property const char * function { set { delete function; if(value) function = CopyString(value); } }
    char * relativeFilePath;
-   property char * relativeFilePath { set { delete relativeFilePath; if(value) relativeFilePath = CopyString(value); } }
+   property const char * relativeFilePath { set { delete relativeFilePath; if(value) relativeFilePath = CopyString(value); } }
    char * absoluteFilePath;
-   property char * absoluteFilePath { set { delete absoluteFilePath; if(value) absoluteFilePath = CopyString(value); } }
+   property const char * absoluteFilePath { set { delete absoluteFilePath; if(value) absoluteFilePath = CopyString(value); } }
+   char * location;
+   property const char * location { set { delete location; if(value) location = CopyString(value); } }
    int line;
    bool enabled;
    int hits;
@@ -4444,6 +4789,67 @@ class Breakpoint : struct
    BreakpointType type;
    DataRow row;
    GdbDataBreakpoint bp;
+   Project project;
+   char * address;
+   property const char * address { set { delete address; if(value) address = CopyString(value); } }
+
+   void ParseLocation()
+   {
+      char * prjName = null;
+      char * filePath = null;
+      char * file;
+      char * line;
+      char fullPath[MAX_LOCATION];
+      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))
+            {
+               if(prj.GetAbsoluteFromRelativePath(filePath, fullPath, null))
+               {
+                  property::absoluteFilePath = fullPath;
+                  project = prj;
+                  break;
+               }
+            }
+         }
+         if(line[0])
+            this.line = atoi(line);
+      }
+      else
+      {
+         Project prj = ide.project;
+         if(prj.GetAbsoluteFromRelativePath(filePath, fullPath, null))
+         {
+            property::absoluteFilePath = fullPath;
+            project = prj;
+         }
+      }
+      if(!absoluteFilePath)
+         property::absoluteFilePath = "";
+      delete prjName;
+      delete filePath;
+   }
 
    char * CopyLocationString(bool removePath)
    {
@@ -4475,12 +4881,15 @@ class Breakpoint : struct
       char * location;
       char * loc = CopyLocationString(false);
       Project prj = null;
-      for(p : ide.workspace.projects)
+      if(absoluteFilePath)
       {
-         if(p.topNode.FindByFullPath(absoluteFilePath, false))
+         for(p : ide.workspace.projects; p != ide.workspace.projects.firstIterator.data)
          {
-            prj = p;
-            break;
+            if(p.topNode.FindByFullPath(absoluteFilePath, false))
+            {
+               prj = p;
+               break;
+            }
          }
       }
       if(prj)
@@ -4497,7 +4906,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);
       }
@@ -4505,12 +4916,20 @@ class Breakpoint : struct
 
    void Free()
    {
-      if(bp)
-         bp.Free();
-      delete bp;
+      Reset();
       delete function;
       delete relativeFilePath;
       delete absoluteFilePath;
+      delete location;
+   }
+
+   void Reset()
+   {
+      inserted = false;
+      delete address;
+      if(bp)
+         bp.Free();
+      delete bp;
    }
 
    ~Breakpoint()
@@ -4523,7 +4942,7 @@ class Breakpoint : struct
 class Watch : struct
 {
    class_no_expansion;
-   
+
    Type type;
    char * expression;
    char * value;
@@ -4585,7 +5004,7 @@ class CodeLocation : struct
          char * temp;
          char loc[MAX_LOCATION];
          strcpy(loc, location);
-         for(temp = loc; temp = strstr(temp, ":"); temp++)
+         for(temp = loc; (temp = strstr(temp, ":")); temp++)
             colon = temp;
          if(colon)
          {
@@ -4598,7 +5017,7 @@ class CodeLocation : struct
                {
                   CodeLocation codloc { line = line };
                   codloc.file = CopyString(loc);
-                  codloc.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(loc);
+                  codloc.absoluteFile = ide.workspace.CopyAbsolutePathFromRelative(loc);
                   return codloc;
                }
             }
@@ -4626,6 +5045,7 @@ void GDBFallBack(Expression exp, String expString)
    result = Debugger::EvaluateExpression(expString, &evalError);
    if(result)
    {
+      FreeExpContents(exp);
       exp.constant = result;
       exp.type = constantExp;
    }