ide;debugger; added internalModuleLoad breakpoint (using InternalModuleLoadBreakpoint...
[sdk] / ide / src / debugger / Debugger.ec
index 849b223..841ee08 100644 (file)
@@ -7,7 +7,7 @@ import "debugTools"
 #define GDB_DEBUG_CONSOLE
 #endif
 
-extern char * strrchr(char * s, char c);
+extern char * strrchr(const char * s, int c);
 
 #define uint _uint
 #include <stdarg.h>
@@ -305,7 +305,7 @@ char progFifoDir[MAX_LOCATION];
 enum DebuggerState { none, prompt, loaded, running, stopped, terminated };
 enum DebuggerEvent { none, hit, breakEvent, signal, stepEnd, functionEnd, exit };
 enum DebuggerAction { none, internal, restart, stop, selectFrame }; //, bpValidation
-enum BreakpointType { none, internalMain, internalWinMain, internalModulesLoaded, user, runToCursor };
+enum BreakpointType { none, internalMain, internalWinMain, internalModulesLoaded, user, runToCursor, internalModuleLoad };
 enum DebuggerEvaluationError { none, symbolNotFound, memoryCantBeRead, unknown };
 
 FileDialog debuggerFileDialog { type = selectDir };
@@ -456,7 +456,8 @@ class Debugger
                   bpHit = bp;
                   
                   if(!(!userBreakOnInternBreak && 
-                        bp && (bp.type == internalMain || bp.type == internalWinMain || bp.type == internalModulesLoaded)))
+                        bp && (bp.type == internalMain || bp.type == internalWinMain ||
+                        bp.type == internalModulesLoaded || bp.type == internalModuleLoad)))
                      monitor = true;
                   hitThread = stopItem.threadid;
                }
@@ -607,7 +608,7 @@ class Debugger
       sysBPs.Add(Breakpoint { type = internalWinMain, enabled = true, level = -1 });
 #endif
       sysBPs.Add(Breakpoint { type = internalModulesLoaded, enabled = true, level = -1 });
-      
+      sysBPs.Add(Breakpoint { type = internalModuleLoad, enabled = true, level = -1 });
    }
 
    ~Debugger()
@@ -1041,7 +1042,7 @@ class Debugger
       else if(expression)
       {
          wh = Watch { };
-         row.tag = (int)wh;
+         row.tag = (int64)wh;
          ide.workspace.watches.Add(wh);
          wh.row = row;
          wh.expression = CopyString(expression);
@@ -1551,11 +1552,40 @@ class Debugger
                            bp.bp = bpItem;
                            bpItem = null;
                            bp.inserted = (bp.bp && bp.bp.number != 0);
-                           ValidateBreakpoint(bp);
                         }
                         delete f;
                      }
-                     break;
+                  }
+                  else if(bp.type == internalModuleLoad && modules)
+                  {
+                     Project ecerePrj = null;
+                     for(p : ide.workspace.projects)
+                     {
+                        if(!strcmp(p.topNode.name, "ecere.epj"))
+                        {
+                           ecerePrj = p;
+                           break;
+                        }
+                     }
+                     if(ecerePrj)
+                     {
+                        ProjectNode node = ecerePrj.topNode.Find("instance.c", false);
+                        if(node)
+                        {
+                           char path[MAX_LOCATION];
+                           char relative[MAX_LOCATION];
+                           node.GetFullFilePath(path);
+                           bp.absoluteFilePath = CopyString(path);
+                           MakePathRelative(path, ecerePrj.topNode.path, relative);
+                           delete bp.relativeFilePath;
+                           bp.relativeFilePath = CopyString(relative);
+                           sentBreakInsert = true;
+                           GdbCommand(false, "-break-insert %s:InternalModuleLoadBreakpoint", bp.relativeFilePath);
+                           bp.bp = bpItem;
+                           bpItem = null;
+                           bp.inserted = (bp.bp && bp.bp.number != 0);
+                        }
+                     }
                   }
                }
             }
@@ -2327,7 +2357,7 @@ class Debugger
 
                         if(exp.expType.kind != arrayType || exp.hasAddress)
                         {
-                           uint address;
+                           uint64 address;
                            char * string;
                            char value[4196];
                            int len;
@@ -2340,9 +2370,15 @@ class Debugger
                               sprintf(temp, "(char*)%s", exp.constant);*/
 
                            //evaluation = Debugger::EvaluateExpression(temp, &evalError);
-                           address = strtoul(exp.constant, null, 0);
+                           // address = strtoul(exp.constant, null, 0);
+                           address = _strtoui64(exp.constant, null, 0);
                            //printf("%x\n", address);
-                           snprintf(value, sizeof(value), "0x%08x ", address);
+                           // snprintf(value, sizeof(value), "0x%08x ", address);
+
+                           if(address > 0xFFFFFFFFLL)
+                              snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%016I64x " : "0x%016llx ", address);
+                           else
+                              snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%08I64x " : "0x%08llx ", address);
                            value[sizeof(value)-1] = 0;
                            
                            if(!address)
@@ -2485,7 +2521,7 @@ class Debugger
                   default:
                      if(exp.hasAddress)
                      {
-                        wh.value = PrintHexUInt(exp.address);
+                        wh.value = PrintHexUInt64(exp.address);
                         result = (bool)exp.address;
                      }
                      else
@@ -2539,7 +2575,7 @@ class Debugger
    }
 
    // to be removed... use GdbReadMemory that returns a byte array instead
-   char * ::GdbReadMemoryString(uint address, int size, char format, int rows, int cols)
+   char * ::GdbReadMemoryString(uint64 address, int size, char format, int rows, int cols)
    {
       eval.active = true;
       eval.error = none;
@@ -2547,17 +2583,25 @@ class Debugger
       if(!size)
          printf("GdbReadMemoryString called with size = 0!\n");
 #endif
-      GdbCommand(false, "-data-read-memory 0x%08x %c, %d, %d, %d", address, format, size, rows, cols);
+      // 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);
       if(eval.active)
          ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemoryString\n");
       return eval.result;
    }
 
-   byte * ::GdbReadMemory(uint address, int bytes)
+   byte * ::GdbReadMemory(uint64 address, int bytes)
    {
       eval.active = true;
       eval.error = none;
-      GdbCommand(false, "-data-read-memory 0x%08x %c, 1, 1, %d", address, 'u', bytes);
+      //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);
 #ifdef _DEBUG
       if(!bytes)
          printf("GdbReadMemory called with bytes = 0!\n");
@@ -2627,6 +2671,11 @@ class Debugger
                break;
             case internalModulesLoaded:
                modules = true;
+               GdbInsertInternalBreakpoint();
+               GdbBreakpointsInsert();
+               GdbExecContinue(false);
+               break;
+            case internalModuleLoad:
                GdbBreakpointsInsert();
                GdbExecContinue(false);
                break;
@@ -2976,7 +3025,7 @@ class Debugger
                            else if(!strcmp(item.name, "next-row"))
                            {
                               StripQuotes(item.value, item.value);
-                              eval.nextBlockAddress = strtoul(item.value, null, 0);
+                              eval.nextBlockAddress = _strtoui64(item.value, null, 0);
                            }
                            else if(!strcmp(item.name, "memory"))
                            {
@@ -3469,7 +3518,7 @@ class Debugger
       return result;
    }
 
-   char * ::ReadMemory(uint address, int size, char format, ExpressionType * error)
+   char * ::ReadMemory(uint64 address, int size, char format, ExpressionType * error)
    {
       // check for state
       char * result = GdbReadMemoryString(address, size, format, 1, 1);
@@ -3879,7 +3928,7 @@ struct DebugEvaluationData
    bool active;
    char * result;
    int bytes;
-   uint nextBlockAddress;
+   uint64 nextBlockAddress;
 
    DebuggerEvaluationError error;
 };