ide;debugger; (#1030) fix new memory leaks.
[sdk] / ide / src / debugger / Debugger.ec
index e4820fd..c5228f8 100644 (file)
@@ -22,6 +22,7 @@ extern char * strrchr(const char * s, int c);
 #define strlen _strlen
 #include <stdarg.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #ifdef __APPLE__
 #define __unix__
@@ -57,7 +58,7 @@ char * PrintNow()
 
 // use =0 to disable printing of specific channels
 #ifdef _DEBUG_INST
-static enum dplchan { none, gdbProtoIgnored=0/*1*/, gdbProtoUnknown=2, gdbOutput=0/*3*/, gdbCommand=0/*4*/, debuggerCall=0/*5*/, debuggerProblem=6,
+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 };
 #else
 static enum dplchan { none, gdbProtoIgnored=0, gdbProtoUnknown=0, gdbOutput=0, gdbCommand=0, debuggerCall=0, debuggerProblem=0,
@@ -169,55 +170,26 @@ 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)
@@ -254,54 +226,33 @@ static char * CopyUnescapedString(char * s)
 
 static void struscpy(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 '\\':
             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];
+               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;
+      j++, k++;
    }
-   d[k] = s[j];
+   d[k] = '\0';
 }
 
 static char * StripBrackets(char * string)
@@ -348,10 +299,10 @@ static int StringGetInt(char * string, int start)
 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)
@@ -396,11 +347,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)
@@ -429,6 +378,7 @@ static bool CheckCommandAvailable(const char * command)
                if(fl.stats.attribs.isFile && !fstrcmp(fl.name, name))
                {
                   available = true;
+                  fl.Stop();
                   break;
                }
             }
@@ -454,26 +404,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 }; //, bpValidation
+enum DebuggerAction { none, internal, restart, stop, selectFrame, advance }; //, bpValidation
 enum DebuggerReason
 {
-   unknown, endSteppingRange, functionFinished, signalReceived, breakpointHit
-   //watchpointTrigger, readWatchpointTrigger, accessWatchpointTrigger, watchpointScope, locationReached,
+   unknown, endSteppingRange, functionFinished, signalReceived, breakpointHit, locationReached
+   //watchpointTrigger, readWatchpointTrigger, accessWatchpointTrigger, watchpointScope,
    //exited, exitedNormally, exitedSignalled;
 };
 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, stepOut, runToCursor };
+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 };
 
@@ -498,11 +457,8 @@ class Debugger
    bool sentKill;
    bool sentBreakInsert;
    bool ignoreBreakpoints;
-   bool userBreakOnInternalBreakpoint;
-   //bool runToCursorDebugStart;
    bool signalOn;
    bool needReset;
-   //bool watchesInit;
    bool usingValgrind;
 
    int ideProcessId;
@@ -516,19 +472,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;
 
@@ -541,6 +502,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;
@@ -591,6 +556,7 @@ class Debugger
                   if(bp)
                      _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "gdb stopped by a breakpoint: ", bp.type, "(", s=bp.CopyLocationString(false), ")"); delete s;
                }
+               delete bpReport;
             }
 #endif
          }
@@ -631,13 +597,8 @@ class Debugger
          if(curEvent == none)
             return false;
 
-         switch (curEvent)
+         switch(curEvent)
          {
-            case breakEvent:
-               activeThread = stopItem.threadid;
-               GdbCommand(false, "-thread-list-ids");
-               GdbGetStack();
-               break;
             case hit:
                {
                   bool isInternal;
@@ -670,44 +631,33 @@ class Debugger
                      else
                         _dpl2(_dpct, dplchan::debuggerProblem, 0, "Invalid stopItem!");
                      if(bpUser && strcmp(stopItem.frame.addr, bpUser.bp.addr))
-                        bpUser = null;
+                        _dpl2(_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))
+                  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;
@@ -724,26 +674,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);
+            GdbGetStack();
+            activeThread = stopItem.threadid;
+            GdbCommand(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)
-            BreakpointHit(stopItem, bpInternal, bpUser);
-
          if(stopItem)
          {
             stopItem.Free();
             delete stopItem;
          }
-         if(userBreakOnInternalBreakpoint)
-            userBreakOnInternalBreakpoint = false;
          return false;
       }
    };
@@ -780,7 +757,7 @@ class Debugger
       __dpl2(file, line, _dpct, dplchan::debuggerState, 0, state, same ? " *** == *** " : " -> ", value);
 #endif
       state = value;
-      if(!same && ide) ide.AdjustDebugMenus();
+      if(!same) ide.AdjustDebugMenus();
    }
 
    void CleanUp()
@@ -804,8 +781,6 @@ class Debugger
       sentKill = false;
       sentBreakInsert = false;
       ignoreBreakpoints = false;
-      userBreakOnInternalBreakpoint = false;
-      //runToCursorDebugStart = false;
       signalOn = false;
 
       activeFrameLevel = 0;
@@ -816,33 +791,38 @@ class Debugger
 
       targetDir = null;
       targetFile = null;
-      
+
       _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");
       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 });
@@ -907,7 +887,7 @@ class Debugger
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Restart");
       _ChangeUserAction(restart);
-      if(StartSession(compiler, config, bitDepth, useValgrind, true, false, false/*, false*/) == loaded)
+      if(StartSession(compiler, config, bitDepth, useValgrind, true, false) == loaded)
          GdbExecRun();
    }
 
@@ -995,11 +975,8 @@ class Debugger
             ide.callStackView.Clear();
             GdbCommand(false, "-thread-select %d", thread);
             GdbGetStack();
-            // Why was SelectFrame missing here?
-            SelectFrame(activeFrameLevel);
+            InternalSelectFrame(activeFrameLevel);
             GoToStackFrameLine(activeFrameLevel, true, false);
-            WatchesCodeEditorLinkRelease();
-            WatchesCodeEditorLinkInit();
             EvaluateWatches();
             ide.Update(null);
          }
@@ -1010,30 +987,33 @@ class Debugger
    void SelectFrame(int frame)
    {
       //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectFrame(", frame, ")");
-      _ChangeUserAction(selectFrame); // not always user action, right? doesn't matter for now.
+      _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)
+   {
+      //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::InternalSelectFrame(", frame, ")");
+      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;
+   }
+
    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
       targetProcessId = 0;
@@ -1045,7 +1025,7 @@ class Debugger
       }
       else
          verboseExitCode[0] = '\0';
-      
+
       event = exit;
 
       // ClearBreakDisplay();
@@ -1092,11 +1072,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, ")"*/);
+      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StartSession(restart(", restart, "), ignoreBreakpoints(", ignoreBreakpoints, ")");
       if(restart && state == running && targetProcessId)
       {
          breakType = DebuggerAction::restart;
@@ -1125,17 +1105,12 @@ 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(result == loaded || result == stopped)
-            GdbBreakpointsDelete(false, (userAction == stepOver || userAction == stepOut), ignoreBreakpoints);
       }
       return result;
    }
@@ -1144,7 +1119,7 @@ class Debugger
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Start()");
       _ChangeUserAction(start);
-      if(StartSession(compiler, config, bitDepth, useValgrind, true, false, false/*, false*/) == loaded)
+      if(StartSession(compiler, config, bitDepth, useValgrind, true, false) == loaded)
          GdbExecRun();
    }
 
@@ -1152,7 +1127,7 @@ class Debugger
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepInto()");
       _ChangeUserAction(stepInto);
-      switch(StartSession(compiler, config, bitDepth, useValgrind, false, true, false/*, false*/))
+      switch(StartSession(compiler, config, bitDepth, useValgrind, false, false))
       {
          case loaded:  GdbExecRun();  break;
          case stopped: GdbExecStep(); break;
@@ -1163,13 +1138,24 @@ class Debugger
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOver()");
       _ChangeUserAction(stepOver);
-      switch(StartSession(compiler, config, bitDepth, useValgrind, false, true, ignoreBreakpoints/*, false*/))
+      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)
+   {
+      _dpl2(_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()");
@@ -1177,7 +1163,6 @@ class Debugger
       if(state == stopped)
       {
          this.ignoreBreakpoints = ignoreBreakpoints;
-         GdbBreakpointsDelete(true, true, ignoreBreakpoints);
          if(frameCount > 1)
             GdbExecFinish();
          else
@@ -1185,19 +1170,12 @@ class Debugger
       }
    }
 
-   void RunToCursor(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, char * absoluteFilePath, int lineNumber, bool ignoreBreakpoints, bool atSameLevel)
+   void RunToCursor(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, char * absoluteFilePath, int lineNumber, bool ignoreBreakpoints, bool atSameLevel, bool oldImplementation)
    {
       char relativeFilePath[MAX_LOCATION];
-      DebuggerState st = state;
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::RunToCursor()");
       _ChangeUserAction(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);
+      WorkspaceGetRelativePath(absoluteFilePath, relativeFilePath, null);
 
       if(bpRunToCursor && bpRunToCursor.inserted && symbols)
       {
@@ -1205,22 +1183,37 @@ class Debugger
          delete bpRunToCursor;
       }
 
-      bpRunToCursor = Breakpoint { };
-      bpRunToCursor.absoluteFilePath = absoluteFilePath;
-      bpRunToCursor.relativeFilePath = relativeFilePath;
-      bpRunToCursor.line = lineNumber;
-      bpRunToCursor.type = runToCursor;
-      bpRunToCursor.enabled = true;
-      bpRunToCursor.level = atSameLevel ? frameCount - activeFrameLevel -1 : -1;
+      StartSession(compiler, config, bitDepth, useValgrind, false, 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);
+         }
       }
    }
 
@@ -1280,7 +1273,7 @@ class Debugger
             *lineTopFrame = stopItem.frame.line;
          else
             *lineTopFrame = 0;
-         
+
          if(*lineTopFrame == *lineCursor && *lineTopFrame)
             *lineTopFrame = 0;
       }
@@ -1344,7 +1337,7 @@ class Debugger
             }
          }
       }
-      
+
       // moving code cursors is futile, on next step, stop, hit, cursors will be offset anyways
    }
 
@@ -1362,9 +1355,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
@@ -1377,10 +1370,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
@@ -1391,15 +1384,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;
             }
@@ -1413,7 +1406,7 @@ class Debugger
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::AddSourceDir(", sourceDir, ")");
       ide.workspace.sourceDirs.Add(CopyString(sourceDir));
       ide.workspace.Save();
-      
+
       if(targeted)
       {
          DebuggerState oldState = state;
@@ -1432,17 +1425,14 @@ class Debugger
       }
    }
 
-   void ToggleBreakpoint(char * fileName, int lineNumber, Project prj)
+   void ToggleBreakpoint(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::debuggerBreakpoints, 0, "Debugger::ToggleBreakpoint(", fileName, ":", lineNumber, ")");
-      strcpy(absolutePath, absoluteFilePath);
+
+      GetSlashPathBuffer(absolutePath, fileName);
       for(i : ide.workspace.breakpoints; i.type == user && i.absoluteFilePath && !fstrcmp(i.absoluteFilePath, absolutePath) && i.line == lineNumber)
       {
          bp = i;
@@ -1460,22 +1450,18 @@ 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];
+
+         WorkspaceGetRelativePath(absolutePath, relativePath, &owner);
+
+         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)
             {
@@ -1484,35 +1470,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;
@@ -1570,7 +1554,7 @@ class Debugger
       Array<char *> argumentTokens { minAllocSize = 50 };
       DebugListItem item { };
       Argument arg;
-      
+
       //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseFrame()");
       TokenizeList(string, ',', frameTokens);
       for(i = 0; i < frameTokens.count; i++)
@@ -1648,7 +1632,7 @@ class Debugger
          else
             _dpl(0, "Bad frame");
       }
-      
+
       delete frameTokens;
       delete argsTokens;
       delete argumentTokens;
@@ -1743,6 +1727,8 @@ class Debugger
                _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "breakpoint member (", item.name, "=", item.value, ") is unheard of");
          }
       }
+      delete bpTokens;
+      delete item;
       return bp;
    }
 
@@ -1774,7 +1760,7 @@ class Debugger
          vsnprintf(string, sizeof(string), format, args);
          string[sizeof(string)-1] = 0;
          va_end(args);
-         
+
          gdbReady = false;
          ide.debugger.serialSemaphore.TryWait();
 
@@ -1798,7 +1784,7 @@ class Debugger
          app.Unlock();
          ide.debugger.serialSemaphore.Wait();
          app.Lock();
-      } 
+      }
    }
 
    bool ValidateBreakpoint(Breakpoint bp)
@@ -1829,12 +1815,17 @@ class Debugger
       return true;
    }
 
-   void GdbBreakpointsInsert()
+   void BreakpointsMaintenance()
    {
-      //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::GdbBreakpointsInsert()");
+      //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::BreakpointsMaintenance()");
       if(symbols)
       {
-         if(userAction != stepOut && (userAction != stepOver || state == loaded))
+         if(gdbExecution.suspendInternalBreakpoints)
+         {
+            for(bp : sysBPs; bp.inserted)
+               UnsetBreakpoint(bp);
+         }
+         else
          {
             DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig, bitDepth);
             for(bp : sysBPs; !bp.inserted)
@@ -1915,10 +1906,17 @@ class Debugger
             delete objDir;
          }
 
+         if(userAction != runToCursor && bpRunToCursor && bpRunToCursor.inserted)
+            UnsetBreakpoint(bpRunToCursor);
          if(bpRunToCursor && !bpRunToCursor.inserted)
             SetBreakpoint(bpRunToCursor, false);
 
-         if(!ignoreBreakpoints)
+         if(ignoreBreakpoints)
+         {
+            for(bp : ide.workspace.breakpoints; bp.inserted)
+               UnsetBreakpoint(bp);
+         }
+         else
          {
             for(bp : ide.workspace.breakpoints; !bp.inserted && bp.type == user)
             {
@@ -1933,6 +1931,7 @@ class Debugger
                   if(bp.bp)
                      _dpl(0, "problem");
 #endif
+                  delete bp.bp;
                   bp.bp = GdbDataBreakpoint { };
                }
             }
@@ -1947,6 +1946,7 @@ class Debugger
       {
          GdbCommand(false, "-break-delete %s", bp.bp.number);
          bp.inserted = false;
+         delete bp.bp;
          bp.bp = { };
       }
    }
@@ -1955,27 +1955,33 @@ class Debugger
    {
       char * s; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::SetBreakpoint(", s=bp.CopyLocationString(false), ", ", removePath ? "**** removePath(true) ****" : "", ") -- ", bp.type); delete s;
       breakpointError = false;
-      if(symbols)
+      if(symbols && bp.enabled && (!bp.project || bp.project.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(false, "-break-insert *%s", bp.address);
+         else
+         {
+            char * location = bp.CopyLocationString(removePath);
+            GdbCommand(false, "-break-insert %s", location);
+            delete location;
+         }
          if(!breakpointError)
          {
+            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)
                      {
@@ -1984,54 +1990,42 @@ class Debugger
                      }
                      else
                         _dpl2(_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.");
                else
                   _dpl2(_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, bool deleteUserBreakpoints)
-   {
-      _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::GdbBreakpointsDelete(deleteRunToCursor(", deleteRunToCursor, "))");
-      if(symbols)
-      {
-         if(deleteInternalBreakpoints)
-         {
-            for(bp : sysBPs)
-               UnsetBreakpoint(bp);
-         }
-         if(deleteUserBreakpoints)
-         {
-            for(bp : ide.workspace.breakpoints)
+            if(address)
+            {
                UnsetBreakpoint(bp);
+               bp.address = address;
+               delete address;
+               SetBreakpoint(bp, removePath);
+            }
          }
-         if(deleteRunToCursor && bpRunToCursor)
-            UnsetBreakpoint(bpRunToCursor);
       }
+      return !breakpointError;
    }
 
    void GdbGetStack()
@@ -2059,7 +2053,7 @@ class Debugger
       {
          char escaped[MAX_LOCATION];
          strescpy(escaped, targetFile);
-         GdbCommand(false, "file \"%s\"", escaped);  //GDB/MI Missing Implementation -symbol-file, -target-attach
+         GdbCommand(false, "file \"%s\"", escaped); //GDB/MI Missing Implementation in 5.1.1 but we now have -file-exec-and-symbols / -file-exec-file / -file-symbol-file
 
          if(!symbols)
             return true;
@@ -2071,6 +2065,8 @@ class Debugger
             printf("target remote | %s --pid=%d\n", vgdbCommand, targetProcessId);
             GdbCommand(false, "target remote | %s --pid=%d", vgdbCommand, targetProcessId); // TODO: vgdb command config option
          }
+         else
+            GdbCommand(false, "info target"); //GDB/MI Missing Implementation -file-list-symbol-files and -file-list-exec-sections
 
          /*for(prj : ide.workspace.projects; prj != ide.workspace.projects.firstIterator.data)
             GdbCommand(false, "-environment-directory \"%s\"", prj.topNode.path);*/
@@ -2099,7 +2095,7 @@ class Debugger
    {
       if(targeted)
       {
-         GdbBreakpointsDelete(true, true, true);
+         BreakpointsDeleteAll();
          GdbCommand(false, "file");  //GDB/MI Missing Implementation -target-detach
          targeted = false;
          symbols = true;
@@ -2133,10 +2129,12 @@ class Debugger
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecRun()");
       GdbTargetSet();
+      if(!usingValgrind)
+         gdbExecution = run;
       GdbExecCommon();
       ShowDebuggerViews();
       if(usingValgrind)
-         GdbCommand(true, "-exec-continue");
+         GdbExecContinue(true);
       else
          GdbCommand(true, "-exec-run");
    }
@@ -2144,6 +2142,7 @@ class Debugger
    void GdbExecContinue(bool focus)
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecContinue()");
+      gdbExecution = run;
       GdbExecCommon();
       GdbCommand(focus, "-exec-continue");
    }
@@ -2151,13 +2150,45 @@ class Debugger
    void GdbExecNext()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecNext()");
+      gdbExecution = next;
       GdbExecCommon();
       GdbCommand(true, "-exec-next");
    }
 
+   void GdbExecUntil(char * absoluteFilePath, int lineNumber)
+   {
+      char relativeFilePath[MAX_LOCATION];
+      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecUntil()");
+      gdbExecution = until;
+      GdbExecCommon();
+      if(absoluteFilePath)
+      {
+         WorkspaceGetRelativePath(absoluteFilePath, relativeFilePath, null);
+         GdbCommand(true, "-exec-until %s:%d", relativeFilePath, lineNumber);
+      }
+      else
+         GdbCommand(true, "-exec-until");
+   }
+
+   void GdbExecAdvance(char * absoluteFilePathOrLocation, int lineNumber)
+   {
+      char relativeFilePath[MAX_LOCATION];
+      _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecAdvance()");
+      gdbExecution = advance;
+      GdbExecCommon();
+      if(lineNumber)
+      {
+         WorkspaceGetRelativePath(absoluteFilePathOrLocation, relativeFilePath, null);
+         GdbCommand(true, "advance %s:%d", relativeFilePath, lineNumber); // should use -exec-advance -- GDB/MI implementation missing
+      }
+      else
+         GdbCommand(true, "advance %s", absoluteFilePathOrLocation); // should use -exec-advance -- GDB/MI implementation missing
+   }
+
    void GdbExecStep()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecStep()");
+      gdbExecution = step;
       GdbExecCommon();
       GdbCommand(true, "-exec-step");
    }
@@ -2165,6 +2196,7 @@ class Debugger
    void GdbExecFinish()
    {
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecFinish()");
+      gdbExecution = finish;
       GdbExecCommon();
       GdbCommand(true, "-exec-finish");
    }
@@ -2172,7 +2204,7 @@ class Debugger
    void GdbExecCommon()
    {
       //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecCommon()");
-      GdbBreakpointsInsert();
+      BreakpointsMaintenance();
    }
 
 #ifdef GDB_DEBUG_GUI
@@ -2210,7 +2242,6 @@ class Debugger
       event = none;
       activeFrame = null;
       stackFrames.Free(Frame::Free);
-      WatchesCodeEditorLinkRelease();
       ide.callStackView.Clear();
       ide.threadsView.Clear();
       ide.Update(null);
@@ -2254,7 +2285,8 @@ class Debugger
       targeted = false;
       modules = false;
       needReset = false;
-      
+      projectsLibraryLoaded.Free();
+
       ide.outputView.ShowClearSelectTab(debug);
       ide.outputView.debugBox.Logf($"Starting debug mode\n");
 
@@ -2280,7 +2312,7 @@ class Debugger
       }
       else
          ChangeWorkingDir(ide.workspace.projectDir);
-      
+
       ide.SetPath(true, compiler, config, bitDepth);
 
       // TODO: This pollutes the environment, but at least it works
@@ -2465,6 +2497,7 @@ class Debugger
       _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExit()");
       if(gdbHandle && gdbProcessId)
       {
+         gdbTimer.Stop();
          GdbCommand(false, "-gdb-exit");
 
          if(gdbThread)
@@ -2473,6 +2506,21 @@ class Debugger
             gdbThread.Wait();
             app.Lock();
          }
+         if(vgLogThread)
+         {
+            app.Unlock();
+            vgLogThread.Wait();
+            app.Lock();
+         }
+         if(vgTargetThread)
+         {
+            app.Unlock();
+            vgTargetThread.Wait();
+            app.Lock();
+         }
+
+         if(vgLogFile)
+            delete vgLogFile;
          if(gdbHandle)
          {
             gdbHandle.Wait();
@@ -2487,22 +2535,13 @@ class Debugger
       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);
@@ -2518,7 +2557,7 @@ class Debugger
             progThread.Wait();
             app.Lock();
             delete fifoFile;
-         }         
+         }
          DeleteFile(progFifoPath);
          progFifoPath[0] = '\0';
          rmdir(progFifoDir);
@@ -2526,70 +2565,46 @@ class Debugger
 #endif
    }
 
-   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;
+      //_dpl2(_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, normal, 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)
+      //_dpl2(_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::debuggerWatches, 0, "Debugger::ResolveWatch()");
       wh.Reset();
 
       /*delete wh.value;
-      if(wh.type) 
+      if(wh.type)
       {
          FreeType(wh.type);
          wh.type = null;
@@ -2620,9 +2635,9 @@ class Debugger
                SetGlobalContext(codeEditor.globalContext);
                SetGlobalData(&codeEditor.globalData);
             }
-         
+
             exp = ParseExpressionString(wh.expression);
-            
+
             if(exp && !parseError)
             {
                char expString[4096];
@@ -2683,7 +2698,7 @@ class Debugger
                            long v = (long)exp.val.f;
                            sprintf(temp, "%i", v);
                            break;
-                        } 
+                        }
                         case doubleType:
                         {
                            long v = (long)exp.val.d;
@@ -2720,7 +2735,7 @@ class Debugger
                            long v = (long)exp.val.f;
                            sprintf(temp, "0x%x", v);
                            break;
-                        } 
+                        }
                         case doubleType:
                         {
                            long v = (long)exp.val.d;
@@ -2757,7 +2772,7 @@ class Debugger
                            long v = (long)exp.val.f;
                            sprintf(temp, "0o%o", v);
                            break;
-                        } 
+                        }
                         case doubleType:
                         {
                            long v = (long)exp.val.d;
@@ -2832,9 +2847,9 @@ class Debugger
                   case constantExp:
                   case stringExp:
                      // 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")))
                      {
@@ -2864,7 +2879,7 @@ class Debugger
                            else
                               snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%08I64x " : "0x%08llx ", address);
                            value[sizeof(value)-1] = 0;
-                           
+
                            if(!address)
                               strcat(value, $"Null string");
                            else
@@ -2884,12 +2899,12 @@ class Debugger
                                  {
                                     int c;
                                     char ch;
-                                    
+
                                     for(c = 0; (ch = string[c]) && c<4096; c++)
-                                       value[len++] = ch;                                 
+                                       value[len++] = ch;
                                     value[len++] = ')';
                                     value[len++] = '\0';
-                                    
+
                                  }
                                  else
                                  {
@@ -2910,7 +2925,7 @@ class Debugger
                            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);
@@ -2926,7 +2941,7 @@ class Debugger
                            wh.value = CopyString($"Invalid Enum Value");
                         result = true;
                      }
-                     else if(wh.type && (wh.type.kind == charType || (wh.type.kind == classType && wh.type._class && 
+                     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"))) )
                      {
                         unichar value;
@@ -2992,7 +3007,7 @@ class Debugger
                         else
                            snprintf(string, sizeof(string), "\'%s\' (%d)", charString, value);
                         string[sizeof(string)-1] = 0;
-                        
+
                         wh.value = CopyString(string);
                         result = true;
                      }
@@ -3014,7 +3029,7 @@ class Debugger
                         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, 
+                           snprintf(watchmsg, sizeof(watchmsg), $"Evaluation failed for \"%s\" of type \"%s\"", wh.expression,
                                  exp.type.OnGetString(tempString, null, null));
                      }
                      break;
@@ -3024,16 +3039,16 @@ class Debugger
                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);
@@ -3045,8 +3060,12 @@ class Debugger
    void EvaluateWatches()
    {
       _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateWatches()");
-      for(wh : ide.workspace.watches)
-         ResolveWatch(wh);
+      WatchesLinkCodeEditor();
+      if(state == stopped)
+      {
+         for(wh : ide.workspace.watches)
+            ResolveWatch(wh);
+      }
    }
 
    char * ::GdbEvaluateExpression(char * expression)
@@ -3119,8 +3138,9 @@ class Debugger
       return null;
    }
 
-   void BreakpointHit(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::BreakpointHit(",
             "bpInternal(", bpInternal ? s1=bpInternal.CopyLocationString(false) : null, "), ",
@@ -3129,55 +3149,64 @@ class Debugger
             "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)
-         {
-            if(userAction == stepOut)//if(prevStopItem.reason == functionFinished)
-               StepOut(ignoreBreakpoints);
-            else
-               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)
          {
-            UnsetBreakpoint(bpUser);
-            delete bpRunToCursor;
+            // 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)
+         {
+            if(userAction == stepOut)
+               StepOut(ignoreBreakpoints);
+            else
+               result = false;
          }
       }
 
       if(!bpUser && !bpInternal)
-         GdbExecContinue(false);
+         result = false;
+
+      return result;
    }
 
    void ValgrindTargetThreadExit()
@@ -3208,7 +3237,7 @@ class Debugger
             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);
@@ -3221,15 +3250,17 @@ class Debugger
    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);
+      // _dpl2(_dpct, dplchan::gdbOutput, 0, output);
+      puts(output);
 #endif
 #ifdef GDB_DEBUG_OUTPUT
       {
@@ -3262,7 +3293,7 @@ class Debugger
          if(ide.gdbDialog) ide.gdbDialog.AddOutput(output);
 #endif
 #endif
-      
+
       switch(output[0])
       {
          case '~':
@@ -3272,6 +3303,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;
@@ -3322,6 +3370,7 @@ class Debugger
                      if(bpItem)
                         _dpl(0, "problem");
 #endif
+                     delete bpItem;
                      bpItem = ParseBreakpoint(item.value, outTokens);
                      //breakType = bpValidation;
                   }
@@ -3661,73 +3710,18 @@ class Debugger
                               HandleExit(reason, exitCode);
                               needReset = true;
                            }
-                           else if(!strcmp(reason, "breakpoint-hit"))
-                           {
-      #ifdef _DEBUG
-                              if(stopItem)
-                                 _dpl(0, "problem");
-      #endif
-                              stopItem = GdbDataStop { };
-                              stopItem.reason = breakpointHit;
-
-                              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 { };
-                              stopItem.reason = endSteppingRange;
-
-                              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) _dpl(0, "problem");
+#endif
                               stopItem = GdbDataStop { };
-                              stopItem.reason = functionFinished;
+                              stopItem.reason = r == 'b' ? breakpointHit : r == 'f' ? functionFinished : r == 'e' ? endSteppingRange : r == 'l' ? locationReached : signalReceived;
 
                               for(i = tk+1; i < outTokens.count; i++)
                               {
@@ -3740,45 +3734,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 = signalReceived;
-
-                              for(i = tk+1; i < outTokens.count; i++)
-                              {
-                                 TokenizeListItem(outTokens[i], item);
-                                 StripQuotes(item.value, item.value);
-                                 if(!strcmp(item.name, "signal-name"))
+                                 else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-name"))
                                     stopItem.name = CopyString(item.value);
-                                 else if(!strcmp(item.name, "signal-meaning"))
+                                 else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-meaning"))
                                     stopItem.meaning = CopyString(item.value);
-                                 else if(!strcmp(item.name, "thread-id"))
-                                    stopItem.threadid = atoi(item.value);
-                                 else if(!strcmp(item.name, "frame"))
-                                 {
-                                    item.value = StripCurlies(item.value);
-                                    ParseFrame(stopItem.frame, item.value);
-                                 }
+                                 else if(!strcmp(item.name, "stopped-threads"))
+                                    _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Advanced thread debugging not handled");
+                                 else if(!strcmp(item.name, "core"))
+                                    _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Information (core) not used");
+                                 else if(!strcmp(item.name, "disp"))
+                                    _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": (", item.name, "=", item.value, ")");
                                  else
-                                    _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown signal reveived item name (", item.name, "=", item.value, ")");
+                                    _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown ", reason, " item name (", item.name, "=", item.value, ")");
                               }
-                              if(!strcmp(stopItem.name, "SIGTRAP"))
+
+                              if(stopItem.reason == signalReceived && !strcmp(stopItem.name, "SIGTRAP"))
                               {
                                  switch(breakType)
                                  {
@@ -3794,7 +3770,8 @@ class Debugger
                               }
                               else
                               {
-                                 event = signal;
+                                 event = r == 'b' ? hit : r == 'f' ? functionEnd : r == 'e' ? stepEnd : r == 'l' ? locationReached : signal;
+                                 ide.Update(null);
                               }
                            }
                            else if(!strcmp(reason, "watchpoint-trigger"))
@@ -3805,8 +3782,6 @@ class Debugger
                               _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason access watchpoint trigger not handled");
                            else if(!strcmp(reason, "watchpoint-scope"))
                               _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint scope not handled");
-                           else if(!strcmp(reason, "location-reached"))
-                              _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason location reached not handled");
                            else
                               _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown reason: ", reason);
                         }
@@ -3959,6 +3934,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);
@@ -4001,7 +3977,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;
             }
@@ -4113,7 +4091,48 @@ class ValgrindLogThread : Thread
 #endif
                   if(strstr(&dynamicBuffer[0], "vgdb me"))
                      debugger.serialSemaphore.Release();
-                  ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
+                  {
+                     char * msg = strstr(&dynamicBuffer[0], "==");
+                     if(msg)
+                        msg = strstr(msg+2, "== ");
+                     if(msg)
+                     {
+                        msg += 3;
+                        switch(msg[0])
+                        {
+                           case '(':
+                              msg = strstr(msg, "(action ");
+                              if(msg)
+                              {
+                                 msg += 8;
+                                 if(!strstr(msg, "at startup) vgdb me ...") || !strstr(msg, "on error) vgdb me ..."))
+                                    msg = null;
+                              }
+                              break;
+                           case 'T':
+                              if(!strstr(msg, "TO DEBUG THIS PROCESS USING GDB: start GDB like this"))
+                                 msg = null;
+                              break;
+                           case 'a':
+                              if(!strstr(msg, "and then give GDB the following command"))
+                                 msg = null;
+                              break;
+                           case ' ':
+                              if(!strstr(msg, "/path/to/gdb") && !strstr(msg, "target remote | /usr/lib/valgrind/../../bin/vgdb --pid="))
+                                 msg = null;
+                              break;
+                           case '-':
+                              if(!strstr(msg, "--pid is optional if only one valgrind process is running"))
+                                 msg = null;
+                              break;
+                           default:
+                              msg = null;
+                              break;
+                        }
+                     }
+                     if(!msg)
+                        ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
+                  }
                   dynamicBuffer.size = 0;
                   start = c + 1;
                }
@@ -4525,6 +4544,8 @@ class GdbDataBreakpoint : struct
       delete at;
       if(multipleBPs) multipleBPs.Free();
       delete multipleBPs;
+      delete number;
+      delete fullname;
    }
 
    ~GdbDataBreakpoint()
@@ -4543,6 +4564,8 @@ class Breakpoint : struct
    property char * relativeFilePath { set { delete relativeFilePath; if(value) relativeFilePath = CopyString(value); } }
    char * absoluteFilePath;
    property char * absoluteFilePath { set { delete absoluteFilePath; if(value) absoluteFilePath = CopyString(value); } }
+   char * location;
+   property char * location { set { delete location; if(value) location = CopyString(value); } }
    int line;
    bool enabled;
    int hits;
@@ -4554,6 +4577,67 @@ class Breakpoint : struct
    BreakpointType type;
    DataRow row;
    GdbDataBreakpoint bp;
+   Project project;
+   char * address;
+   property 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(ProjectGetAbsoluteFromRelativePath(prj, filePath, fullPath))
+               {
+                  property::absoluteFilePath = fullPath;
+                  project = prj;
+                  break;
+               }
+            }
+         }
+         if(line[0])
+            this.line = atoi(line);
+      }
+      else
+      {
+         Project prj = ide.project;
+         if(ProjectGetAbsoluteFromRelativePath(prj, filePath, fullPath))
+         {
+            property::absoluteFilePath = fullPath;
+            project = prj;
+         }
+      }
+      if(!absoluteFilePath)
+         property::absoluteFilePath = "";
+      delete prjName;
+      delete filePath;
+   }
 
    char * CopyLocationString(bool removePath)
    {
@@ -4585,12 +4669,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)
@@ -4607,7 +4694,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);
       }
@@ -4615,12 +4704,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()
@@ -4633,7 +4730,7 @@ class Breakpoint : struct
 class Watch : struct
 {
    class_no_expansion;
-   
+
    Type type;
    char * expression;
    char * value;
@@ -4740,3 +4837,101 @@ void GDBFallBack(Expression exp, String expString)
       exp.type = constantExp;
    }
 }
+
+static Project WorkspaceGetFileOwner(char * absolutePath)
+{
+   Project owner = null;
+   for(prj : ide.workspace.projects)
+   {
+      if(prj.topNode.FindByFullPath(absolutePath, false))
+      {
+         owner = prj;
+         break;
+      }
+   }
+   if(!owner)
+      WorkspaceGetObjectFileNode(absolutePath, &owner);
+   return owner;
+}
+
+static ProjectNode WorkspaceGetObjectFileNode(char * filePath, Project * project)
+{
+   ProjectNode node = null;
+   char ext[MAX_EXTENSION];
+   GetExtension(filePath, ext);
+   if(ext[0])
+   {
+      IntermediateFileType type = IntermediateFileType::FromExtension(ext);
+      if(type)
+      {
+         char fileName[MAX_FILENAME];
+         GetLastDirectory(filePath, fileName);
+         if(fileName[0])
+         {
+            DotMain dotMain = DotMain::FromFileName(fileName);
+            for(prj : ide.workspace.projects)
+            {
+               if((node = prj.FindNodeByObjectFileName(fileName, type, dotMain, null)))
+               {
+                  if(project)
+                     *project = prj;
+                  break;
+               }
+            }
+         }
+      }
+   }
+   return node;
+}
+
+static ProjectNode ProjectGetObjectFileNode(Project project, char * filePath)
+{
+   ProjectNode node = null;
+   char ext[MAX_EXTENSION];
+   GetExtension(filePath, ext);
+   if(ext[0])
+   {
+      IntermediateFileType type = IntermediateFileType::FromExtension(ext);
+      if(type)
+      {
+         char fileName[MAX_FILENAME];
+         GetLastDirectory(filePath, fileName);
+         if(fileName[0])
+         {
+            DotMain dotMain = DotMain::FromFileName(fileName);
+            node = project.FindNodeByObjectFileName(fileName, type, dotMain, null);
+         }
+      }
+   }
+   return node;
+}
+
+static void WorkspaceGetRelativePath(char * absolutePath, char * relativePath, Project * owner)
+{
+   Project prj = WorkspaceGetFileOwner(absolutePath);
+   if(owner)
+      *owner = prj;
+   if(!prj)
+      prj = ide.workspace.projects.firstIterator.data;
+   if(prj)
+   {
+      MakePathRelative(absolutePath, prj.topNode.path, relativePath);
+      MakeSlashPath(relativePath);
+   }
+   else
+      relativePath[0] = '\0';
+}
+
+static bool ProjectGetAbsoluteFromRelativePath(Project project, char * relativePath, char * absolutePath)
+{
+   ProjectNode node = project.topNode.FindWithPath(relativePath, false);
+   if(!node)
+      node = ProjectGetObjectFileNode(project, relativePath);
+   if(node)
+   {
+      strcpy(absolutePath, node.project.topNode.path);
+      PathCat(absolutePath, relativePath);
+      MakeSlashPath(absolutePath);
+   }
+   return node != null;
+}