Fix memory leaks in trace projections and summary
[charm.git] / src / ck-core / debug-message.C
blobff7d1e52e94b8eb74fc1d45ba460109d5a1b1f87
1 #include <ck.h>
2 #include "envelope.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include "queueing.h"
8 #if 0
9 /* Queue message extraction calls: */
10   CqsEnumerateQueue((Queue)CpvAccess(CsdSchedQueue), &schedQueue);
11   FIFOQueue = CdsFifo_Enumerate((CdsFifo)CpvAccess(CmiLocalQueue));
12   DQueue = CdsFifo_Enumerate(CpvAccess(debugQueue));
13 #endif
15 /************ Charm++ Message PUP *****************/
16 /* 
17  pack_mode = 
18                   0:  pup each field separately, allows for debugging;
19                   1:  pup the message as a single array of bytes;
20                   2:  try to handle the cross platform compatibility where
21                       Converse header sizes are different. Works same as 0, 
22                       but ignore the converse header. Cannot handle the case 
23                       in heterogeneous platforms where data type length is 
24                       different.
26 void CkPupMessage(PUP::er &p,void **atMsg,int pack_mode) {
27         UChar type;
28         int size,prioBits,envSize;
30         /* pup this simple flag so that we can handle the NULL msg */
31         int isNull = (*atMsg == NULL);   // be overwritten when unpacking
32         p(isNull);
33         if (isNull) { *atMsg = NULL; return; }
35         envelope *env=UsrToEnv(*atMsg);
36         unsigned char wasPacked=0;
37         p.comment("Begin Charm++ Message {");
38         if (!p.isUnpacking()) {
39                 wasPacked=env->isPacked();
40                 if (0==wasPacked) //If it's not already packed...
41                   CkPackMessage(&env); //Pack it
42                 type=env->getMsgtype();
43                 size=env->getTotalsize();
44                 prioBits=env->getPriobits();
45                 envSize=sizeof(envelope);
46         }
47         p(type);
48         p(wasPacked);
49         p(size);
50         p(prioBits);
51         p(envSize);
52         int userSize=size-envSize-sizeof(int)*CkPriobitsToInts(prioBits);
53         if (p.isUnpacking())
54                 env=_allocEnv(type,userSize,prioBits);
55         if (pack_mode == 1) {
56           /*Pup entire header and message as raw bytes.*/
57           p((char *)env,size);
58         } 
59         else if (pack_mode == 2) {
60             /*Pup header in detail and message separately.*/
61             /* note that it can be that sizeof(envelope) != envSize */
62             env->pup(p);
63             p((char*)env+sizeof(envelope),size-envSize);
64         }
65         else 
66         { /*Pup each field separately, which allows debugging*/
67           p.comment("Message Envelope:");
68           env->pup(p);
69           p.comment("Message User Data:");
70 #if 0 /* Messages *should* be packed according to entry point: */
71           int ep=env->getEpIdx();
72           if (ep>0 && ep<_numEntries)
73             _entryTable[ep]->pupFn(p,*atMsg);
74           else
75 #endif
76             ((CkMessage *)*atMsg)->pup(p);
77           p.comment("} End Charm++ Message");
78         }
79         if (0==wasPacked) //Restore the packed-ness to previous state-- unpacked
80           CkUnpackMessage(&env);
81         *atMsg=EnvToUsr(env);
84 void envelope::pup(PUP::er &p) {
85         //message type, totalsize, and priobits are already pup'd (above)
86         int convHeaderSize;
87         if (!p.isUnpacking()) convHeaderSize = CmiReservedHeaderSize;
88         p(convHeaderSize);
89         //puping converse hdr hopefully not go beyond boundry
90         p((char *)core,convHeaderSize);
91         p(ref);
92         //p((char *)&attribs,sizeof(attribs));
93         p(attribs.msgIdx);
94         p(attribs.mtype);
95         int d;
96         if (!p.isUnpacking()) d = attribs.queueing;
97         //cppcheck-suppress uninitvar
98         p|d;
99         if (p.isUnpacking()) attribs.queueing = d;
100         if (!p.isUnpacking()) d = attribs.isPacked;
101         p|d;
102         if (p.isUnpacking()) attribs.isPacked = d;
103         if (!p.isUnpacking()) d = attribs.isUsed;
104         p|d;
105         if (p.isUnpacking()) attribs.isUsed = d; 
106         p(epIdx);
107         p(pe);
108 #if CMK_REPLAYSYSTEM || CMK_TRACE_ENABLED
109         p(event);
110 #endif
111         p((char*)getPrioPtr(),getPrioBytes());
112         switch(getMsgtype()) {
113         case NewChareMsg: case NewVChareMsg: 
114         case ForChareMsg: case ForVidMsg: case FillVidMsg:
115                 p((char *)&(type.chare.ptr),sizeof(void *));
116                 p(type.chare.forAnyPe);
117                 break;
118         case NodeBocInitMsg: case BocInitMsg: case ForNodeBocMsg: case ForBocMsg:
119                 p|type.group.g;
120                 p|type.group.rednMgr;
121                 p|type.group.dep;
122                 p|type.group.epoch;
123                 p|type.group.arrayEp;
124                 break;
125         case ArrayEltInitMsg: case ForArrayEltMsg:
126                 p|type.array.arr;
127                 p|type.array.id;
128                 p(type.array.hopCount);
129                 p(type.array.ifNotThere);
130                 break;
131         case RODataMsg:
132                 p(type.roData.count);
133                 break;
134         case ROMsgMsg:
135                 p(type.roMsg.roIdx);
136                 break;
137         default: /*No type-dependent fields to pack*/
138                 break;
139         }
142 void CkMessage::pup(PUP::er &p) {
143         //Default message pup: just copy user portion as bytes
144         envelope *env=UsrToEnv((void *)this);
145         int userSize=env->getTotalsize()-sizeof(envelope)-env->getPrioBytes();
146         p((char *)this,userSize);