Merge branch 'charm' into virtualDebug
[charm.git] / src / ck-core / debug-charm.C
index ee31def9499813bb1e295327fc9de546c662f9c7..fe9e4ac07461d307ae624439163f14c702fdd64e 100644 (file)
@@ -362,7 +362,7 @@ void hostInfo(void *itemIter, pup_er pp, CpdListItemsRequest *req) {
 }
 
 /************ Message CPD Lists ****************/
-CpvCExtern(void *,debugQueue);
+CkpvExtern(void *,debugQueue);
 CpvCExtern(int, skipBreakpoint);
 
 // Interpret data in a message in a user-friendly way.
@@ -429,7 +429,7 @@ void CpdPupMessage(PUP::er &p, void *msg)
   p.synchronize(PUP::sync_end_object);
 }
 
-CpvStaticDeclare(void *, lastBreakPointMsg);
+CkpvStaticDeclare(void *, lastBreakPointMsg);
 
 //Cpd Lists for local and scheduler queues
 class CpdList_localQ : public CpdListAccessor {
@@ -438,20 +438,20 @@ public:
   CpdList_localQ() {}
   virtual const char * getPath(void) const {return "converse/localqueue";}
   virtual size_t getLength(void) const {
-    int x = CdsFifo_Length((CdsFifo)(CpvAccess(debugQueue)));
+    int x = CdsFifo_Length((CdsFifo)(CkpvAccess(debugQueue)));
     //CmiPrintf("*******Returning fifo length %d*********\n", x);
     //return CdsFifo_Length((CdsFifo)(CpvAccess(CmiLocalQueue)));
-    if (CpvAccess(lastBreakPointMsg) != NULL) x++;
+    if (CkpvAccess(lastBreakPointMsg) != NULL) x++;
     return x;
   }
   virtual void pup(PUP::er &p, CpdListItemsRequest &req) {
-    int length = CdsFifo_Length((CdsFifo)(CpvAccess(debugQueue)));
-    void ** messages = CdsFifo_Enumerate(CpvAccess(debugQueue));
+    int length = CdsFifo_Length((CdsFifo)(CkpvAccess(debugQueue)));
+    void ** messages = CdsFifo_Enumerate(CkpvAccess(debugQueue));
     int curObj=0;
 
-    if (CpvAccess(lastBreakPointMsg) != NULL) {
+    if (CkpvAccess(lastBreakPointMsg) != NULL) {
       beginItem(p, -1);
-      envelope *env=(envelope *)UsrToEnv(CpvAccess(lastBreakPointMsg));
+      envelope *env=(envelope *)UsrToEnv(CkpvAccess(lastBreakPointMsg));
       p.comment("name");
       char *type=(char*)"Breakpoint";
       p(type,strlen(type));
@@ -471,8 +471,12 @@ public:
         const char *type="Converse";
         p.comment("name");
         char name[128];
+#if ! CMK_BLUEGENE_CHARM
         if (CmiGetHandler(msg)==_charmHandlerIdx) {isCharm=1; type="Local Charm";}
         if (CmiGetXHandler(msg)==_charmHandlerIdx) {isCharm=1; type="Network Charm";}
+#else
+        isCharm=1; type="BG";
+#endif
         sprintf(name,"%s %d: %s (%d)","Message",curObj,type,CmiGetHandler(msg));
         p(name, strlen(name));
 
@@ -543,30 +547,32 @@ extern int  CpdIsFrozen(void);
 CpvStaticDeclare(int, _debugMsg);
 CpvStaticDeclare(int, _debugChare);
 
-CpvStaticDeclare(CpdBpFuncTable_t *, breakPointEntryTable);
+CkpvStaticDeclare(CpdBpFuncTable_t *, breakPointEntryTable);
 
 //CpvStaticDeclare(void *, lastBreakPointMsg);
-CpvStaticDeclare(void *, lastBreakPointObject);
-CpvStaticDeclare(int, lastBreakPointIndex);
+CkpvStaticDeclare(void *, lastBreakPointObject);
+CkpvStaticDeclare(int, lastBreakPointIndex);
 
 void CpdBreakPointInit()
 {
-  CpvInitialize(void *, lastBreakPointMsg);
-  CpvInitialize(void *, lastBreakPointObject);
-  CpvInitialize(int, lastBreakPointIndex);
+  CkpvInitialize(void *, lastBreakPointMsg);
+  CkpvInitialize(void *, lastBreakPointObject);
+  CkpvInitialize(int, lastBreakPointIndex);
   CpvInitialize(int, _debugMsg);
   CpvInitialize(int, _debugChare);
-  CpvInitialize(CpdBpFuncTable_t *, breakPointEntryTable);
-  CpvAccess(lastBreakPointMsg) = NULL;
-  CpvAccess(lastBreakPointObject) = NULL;
-  CpvAccess(lastBreakPointIndex) = 0;
+  CkpvInitialize(CpdBpFuncTable_t *, breakPointEntryTable);
+  CkpvAccess(lastBreakPointMsg) = NULL;
+  CkpvAccess(lastBreakPointObject) = NULL;
+  CkpvAccess(lastBreakPointIndex) = 0;
   CpvAccess(_debugMsg) = CkRegisterMsg("debug_msg",0,0,0,0);
   CpvAccess(_debugChare) = CkRegisterChare("debug_Chare",0,TypeChare);
   CkRegisterChareInCharm(CpvAccess(_debugChare));
-  CpvAccess(breakPointEntryTable) = new CpdBpFuncTable_t(10,0.5,CkHashFunction_int,CkHashCompare_int );
+  CkpvAccess(breakPointEntryTable) = new CpdBpFuncTable_t(10,0.5,CkHashFunction_int,CkHashCompare_int );
 }
 
-
+#if CMK_BLUEGENE_CHARM
+#include "blue_impl.h"
+#endif
 
 static void _call_freeze_on_break_point(void * msg, void * object)
 {
@@ -576,17 +582,21 @@ static void _call_freeze_on_break_point(void * msg, void * object)
 
   // If the counter "skipBreakpoint" is not zero we actually do not freeze and deliver the regular message
   if (CpvAccess(skipBreakpoint) > 0) {
-    EntryInfo * breakPointEntryInfo = CpvAccess(breakPointEntryTable)->get(CkMessageToEpIdx(msg));
+    EntryInfo * breakPointEntryInfo = CkpvAccess(breakPointEntryTable)->get(CkMessageToEpIdx(msg));
     CkAssert(breakPointEntryInfo != NULL);
     breakPointEntryInfo->call(msg, object);
     CpvAccess(skipBreakpoint) --;
   } else {
-      CpvAccess(lastBreakPointMsg) = msg;
-      CpvAccess(lastBreakPointObject) = object;
-      CpvAccess(lastBreakPointIndex) = CkMessageToEpIdx(msg);
-      EntryInfo * breakPointEntryInfo = CpvAccess(breakPointEntryTable)->get(CpvAccess(lastBreakPointIndex));
+      CkpvAccess(lastBreakPointMsg) = msg;
+      CkpvAccess(lastBreakPointObject) = object;
+      CkpvAccess(lastBreakPointIndex) = CkMessageToEpIdx(msg);
+      EntryInfo * breakPointEntryInfo = CkpvAccess(breakPointEntryTable)->get(CkpvAccess(lastBreakPointIndex));
       CpdNotify(CPD_BREAKPOINT,breakPointEntryInfo->name);
       CpdFreeze();
+#if CMK_BLUEGENE_CHARM
+      stopVTimer();
+      ((workThreadInfo*)cta(threadinfo))->scheduler(-1);
+#endif
   }
 }
 
@@ -594,20 +604,27 @@ static void _call_freeze_on_break_point(void * msg, void * object)
 extern "C"
 void CpdDeliverSingleMessage () {
   if (!CpdIsFrozen()) return; /* Do something only if we are in freeze mode */
-  if ( (CpvAccess(lastBreakPointMsg) != NULL) && (CpvAccess(lastBreakPointObject) != NULL) ) {
-    EntryInfo * breakPointEntryInfo = CpvAccess(breakPointEntryTable)->get(CpvAccess(lastBreakPointIndex));
+  if ( (CkpvAccess(lastBreakPointMsg) != NULL) && (CkpvAccess(lastBreakPointObject) != NULL) ) {
+    EntryInfo * breakPointEntryInfo = CkpvAccess(breakPointEntryTable)->get(CkpvAccess(lastBreakPointIndex));
     if (breakPointEntryInfo != NULL) {
-      breakPointEntryInfo->call(CpvAccess(lastBreakPointMsg), CpvAccess(lastBreakPointObject));
+      breakPointEntryInfo->call(CkpvAccess(lastBreakPointMsg), CkpvAccess(lastBreakPointObject));
     }
-    CpvAccess(lastBreakPointMsg) = NULL;
-    CpvAccess(lastBreakPointObject) = NULL;
+    CkpvAccess(lastBreakPointMsg) = NULL;
+    CkpvAccess(lastBreakPointObject) = NULL;
+#if CMK_BLUEGENE_CHARM
+    ((workThreadInfo*)cta(threadinfo))->stopScheduler();
+#endif
   }
   else {
     // we were not stopped at a breakpoint, then deliver the first message in the debug queue
-    if (!CdsFifo_Empty(CpvAccess(debugQueue))) {
+    if (!CdsFifo_Empty(CkpvAccess(debugQueue))) {
       CpvAccess(skipBreakpoint) = 1;
-      char *queuedMsg = (char *)CdsFifo_Dequeue(CpvAccess(debugQueue));
+      char *queuedMsg = (char *)CdsFifo_Dequeue(CkpvAccess(debugQueue));
+#if CMK_BLUEGENE_CHARM
+      BgProcessMessageDefault(cta(threadinfo), queuedMsg);
+#else
       CmiHandleMessage(queuedMsg);
+#endif
       CpvAccess(skipBreakpoint) = 0;
     }
   }
@@ -618,18 +635,21 @@ extern "C"
 void CpdContinueFromBreakPoint ()
 {
     CpdUnFreeze();
-    if ( (CpvAccess(lastBreakPointMsg) != NULL) && (CpvAccess(lastBreakPointObject) != NULL) )
+    if ( (CkpvAccess(lastBreakPointMsg) != NULL) && (CkpvAccess(lastBreakPointObject) != NULL) )
     {
-        EntryInfo * breakPointEntryInfo = CpvAccess(breakPointEntryTable)->get(CpvAccess(lastBreakPointIndex));
+        EntryInfo * breakPointEntryInfo = CkpvAccess(breakPointEntryTable)->get(CkpvAccess(lastBreakPointIndex));
         if (breakPointEntryInfo != NULL) {
-           breakPointEntryInfo->call(CpvAccess(lastBreakPointMsg), CpvAccess(lastBreakPointObject));
+           breakPointEntryInfo->call(CkpvAccess(lastBreakPointMsg), CkpvAccess(lastBreakPointObject));
+#if CMK_BLUEGENE_CHARM
+           ((workThreadInfo*)cta(threadinfo))->stopScheduler();
+#endif
         } else {
           // This means that the breakpoint got deleted in the meanwhile
           
         }
     }
-    CpvAccess(lastBreakPointMsg) = NULL;
-    CpvAccess(lastBreakPointObject) = NULL;
+    CkpvAccess(lastBreakPointMsg) = NULL;
+    CkpvAccess(lastBreakPointObject) = NULL;
 }
 
 //ccs handler to set a breakpoint with entry function name msg
@@ -638,7 +658,7 @@ void CpdSetBreakPoint (char *msg)
   char functionName[128];
   int tableSize, tableIdx = 0;
   int reply = 0;
-  sscanf(msg+CmiMsgHeaderSizeBytes, "%s", functionName);
+  sscanf(msg+CmiReservedHeaderSize, "%s", functionName);
   if (strlen(functionName) > 0)
   {
     tableSize = _entryTable.size();
@@ -650,11 +670,11 @@ void CpdSetBreakPoint (char *msg)
        //{
     tableIdx = atoi(functionName);
     if (tableIdx >= 0 && tableIdx < tableSize) {
-           EntryInfo * breakPointEntryInfo = (EntryInfo *)CpvAccess(breakPointEntryTable)->get(tableIdx);
+           EntryInfo * breakPointEntryInfo = (EntryInfo *)CkpvAccess(breakPointEntryTable)->get(tableIdx);
            delete breakPointEntryInfo;
            breakPointEntryInfo = new EntryInfo(_entryTable[tableIdx]->name, _entryTable[tableIdx]->call, _entryTable[tableIdx]->msgIdx, _entryTable[tableIdx]->chareIdx );
            //CmiPrintf("Breakpoint is set for function %s with an epIdx = %ld\n", _entryTable[tableIdx]->name, tableIdx);
-           CpvAccess(breakPointEntryTable)->put(tableIdx) = breakPointEntryInfo;
+           CkpvAccess(breakPointEntryTable)->put(tableIdx) = breakPointEntryInfo;
            _entryTable[tableIdx]->name = "debug_breakpoint_ep";
            _entryTable[tableIdx]->call = (CkCallFnPtr)_call_freeze_on_break_point;
            //_entryTable[tableIdx]->msgIdx = CpvAccess(_debugMsg);
@@ -685,18 +705,18 @@ void CpdRemoveBreakPoint (char *msg)
 {
   char functionName[128];
   int reply = 0;
-  sscanf(msg+CmiMsgHeaderSizeBytes, "%s", functionName);
+  sscanf(msg+CmiReservedHeaderSize, "%s", functionName);
   if (strlen(functionName) > 0) {
     int idx = atoi(functionName);
     if (idx >= 0 && idx < _entryTable.size()) {
       //CmiPrintf("[ERROR]Entrypoint was not found for function %s\n", functionName);
       //void *objPointer;
       //void *keyPointer;
-      //CkHashtableIterator *it = CpvAccess(breakPointEntryTable)->iterator();
+      //CkHashtableIterator *it = CkpvAccess(breakPointEntryTable)->iterator();
       //while(NULL!=(objPointer = it->next(&keyPointer)))
       //{
       //EntryInfo * breakPointEntryInfo = *(EntryInfo **)objPointer;
-      EntryInfo * breakPointEntryInfo = CpvAccess(breakPointEntryTable)->get(idx);
+      EntryInfo * breakPointEntryInfo = CkpvAccess(breakPointEntryTable)->get(idx);
       if (breakPointEntryInfo != NULL) {
         _entryTable[idx]->name =  breakPointEntryInfo->name;
         _entryTable[idx]->call = (CkCallFnPtr)breakPointEntryInfo->call;
@@ -705,7 +725,7 @@ void CpdRemoveBreakPoint (char *msg)
         reply = ~0 ;
         //_debugEntryTable[idx].isBreakpoint = CmiFalse;
         //CmiPrintf("Breakpoint is removed for function %s with epIdx %ld\n", _entryTable[idx]->name, idx);
-        //CpvAccess(breakPointEntryTable)->remove(idx);
+        //CkpvAccess(breakPointEntryTable)->remove(idx);
       }
     }
   }
@@ -718,7 +738,7 @@ void CpdRemoveAllBreakPoints ()
   void *objPointer;
   void *keyPointer;
   int reply = 1;
-  CkHashtableIterator *it = CpvAccess(breakPointEntryTable)->iterator();
+  CkHashtableIterator *it = CkpvAccess(breakPointEntryTable)->iterator();
   while(NULL!=(objPointer = it->next(&keyPointer)))
   {
     EntryInfo * breakPointEntryInfo = *(EntryInfo **)objPointer;
@@ -738,7 +758,17 @@ extern "C" int CpdIsCharmDebugMessage(void *msg) {
          env->getMsgtype() == FillVidMsg || _entryTable[env->getEpIdx()]->inCharm;
 }
 
-
+#if CMK_BLUEGENE_CHARM
+CpvExtern(int, _bgCcsHandlerIdx);
+extern "C" int CpdIsBgCharmDebugMessage(void *msg) {
+  envelope *env = (envelope*)msg;
+  if (CmiBgMsgFlag(msg) == BG_CLONE) {
+    env=*(envelope**)(((char*)msg)+CmiBlueGeneMsgHeaderSizeBytes);
+  }
+  return (((CmiBlueGeneMsgHeader*)msg)->hID) == CpvAccess(_bgCcsHandlerIdx) || env->getMsgtype() == ForVidMsg ||
+         env->getMsgtype() == FillVidMsg || _entryTable[env->getEpIdx()]->inCharm;
+}
+#endif
 
 CpvExtern(char *, displayArgument);
 
@@ -802,7 +832,7 @@ void CpdCharmInit()
   //CpdListRegister(new CpdListAccessor_c("converse/memory/leak",cpd_memory_length,0,cpd_memory_leak,0));
   CpdListRegister(new CpdListAccessor_c("converse/memory/data",cpd_memory_getLength,0,cpd_memory_get,0,false));
 
-  CpdBreakPointInit();
+  //CpdBreakPointInit();
   CcsRegisterHandler("ccs_set_break_point",(CmiHandler)CpdSetBreakPoint);
   CcsSetMergeFn("ccs_set_break_point",CcsMerge_logical_and);
   CcsRegisterHandler("ccs_remove_break_point",(CmiHandler)CpdRemoveBreakPoint);
@@ -822,6 +852,9 @@ void CpdCharmInit()
   CpdListRegister(new CpdList_message());
   CpdListRegister(new CpdList_msgStack());
   CpdIsDebugMessage = CpdIsCharmDebugMessage;
+#if CMK_BLUEGENE_CHARM
+  CpdIsDebugMessage = CpdIsBgCharmDebugMessage;
+#endif
 }
 
 #else