759bf5295762e626ed884e0521516795646556df
[charm.git] / src / ck-core / info.C
1 #include <converse.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #if CMK_DEBUG_MODE
7
8 CsvDeclare(int*,  BreakPoints);
9 CsvDeclare(char*, SymbolTableInfo);
10 CpvDeclare(symbolTableType, SymbolTableFnArray);
11 typedef int offsetType[MAX_NUM_HANDLERS];
12 CpvDeclare(offsetType, offsetArray);
13 CpvDeclare(int, numBreakPoints);
14 CpvDeclare(indirectionType, indirectionFnArray);
15
16 CpvExtern(handlerType, handlerArray);
17
18 char *makeSymbolTableInfo(void)
19 {
20   symbolTableFunction f;
21   char *returnInfo, *newReturnInfo;
22   int i;
23
24   returnInfo = (char *)malloc(1);
25   returnInfo[0] = '\0';
26   for(i = 0; i < MAX_NUM_HANDLERS; i++){
27     if((f = CpvAccess(SymbolTableFnArray)[i]) != 0){
28       char *p;
29
30       p = (*f)();
31       newReturnInfo = (char *)malloc(strlen(p) + strlen(returnInfo) + 1);
32       strcpy(newReturnInfo, returnInfo);
33       strcat(newReturnInfo, p);
34       free(returnInfo);
35       free(p);
36       returnInfo = newReturnInfo;
37     }
38   }
39   
40   return(returnInfo);
41 }
42
43 extern "C"
44 void CpdInitializeBreakPoints(void)
45 {
46   int i;
47
48   CsvInitialize(int *, BreakPoints);
49   CsvInitialize(char *, SymbolTableInfo);
50   CpvInitialize(symbolTableType, SymbolTableFnArray);
51   CpvInitialize(offsetType, offsetArray);
52   CpvInitialize(int, numBreakPoints);
53   CpvInitialize(indirectionType, indirectionFnArray);
54
55   CsvAccess(BreakPoints) = 0;
56   CsvAccess(SymbolTableInfo) = 0;
57   for(i = 0; i < MAX_NUM_HANDLERS; i++){
58     CpvAccess(SymbolTableFnArray)[i] = 0;
59     CpvAccess(offsetArray)[i] = 0;
60     CpvAccess(indirectionFnArray)[i] = 0;
61   }
62   CpvAccess(numBreakPoints) = 0;
63 }
64
65 void symbolTableFnArrayRegister(int hndlrID, int noOfBreakPoints,
66                                 symbolTableFunction f, indirectionFunction g)
67 {
68   CpvAccess(SymbolTableFnArray)[hndlrID] = f;
69   CpvAccess(indirectionFnArray)[hndlrID] = g;
70   CpvAccess(offsetArray)[hndlrID] = CpvAccess(numBreakPoints);
71   CpvAccess(numBreakPoints) += noOfBreakPoints;
72 }
73
74 char *getSymbolTableInfo(void)
75 {
76   if(CsvAccess(SymbolTableInfo) == 0) 
77     CsvAccess(SymbolTableInfo) = makeSymbolTableInfo();
78   return(CsvAccess(SymbolTableInfo));
79 }
80
81 void setBreakPoints(char *newBreakPoints)
82 {
83   int i;
84   char *temp;
85
86   for(i = 0; i < CpvAccess(numBreakPoints); i++)
87     CsvAccess(BreakPoints)[i] = (newBreakPoints[i] - '0');
88 }
89
90 char *getBreakPoints(void)
91 {
92   char *temp;
93   int i;
94
95   if(CsvAccess(BreakPoints) == 0){
96     CsvAccess(BreakPoints) = (int *)malloc(CpvAccess(numBreakPoints) 
97                                            *sizeof(int));
98     for(i = 0; i < CpvAccess(numBreakPoints); i++)
99       CsvAccess(BreakPoints)[i] = 0;
100   }
101
102   temp = (char *)malloc(CpvAccess(numBreakPoints)*2*sizeof(char)+6);
103   strcpy(temp, "");
104   sprintf(temp, "%d#", CpvAccess(numBreakPoints));
105   for(i = 0; i < CpvAccess(numBreakPoints); i++){
106     char t[3];
107     sprintf(t, "%d#", CsvAccess(BreakPoints)[i]);
108     strcat(temp, t);
109   }
110   return(temp);
111 }
112
113 int isBreakPoint(char *msg)
114 {
115   int hndlrID;
116   int i;
117
118   if(CsvAccess(BreakPoints) == 0){
119     CsvAccess(BreakPoints) = (int *)malloc(CpvAccess(numBreakPoints)
120                                            *sizeof(int));
121     for(i = 0; i < CpvAccess(numBreakPoints); i++)
122       CsvAccess(BreakPoints)[i] = 0;
123   }
124   hndlrID = CmiGetHandler(msg);
125   if(CpvAccess(handlerArray)[hndlrID][0] != 0){
126     int offset;
127     indirectionFunction f;
128
129     f = CpvAccess(indirectionFnArray)[hndlrID];
130     offset = CpvAccess(offsetArray)[hndlrID] + (*f)(msg);
131
132     return(CsvAccess(BreakPoints)[offset]);
133   } else {
134     return 0;
135   }
136 }
137
138 int isEntryPoint(char *msg)
139 {
140   int hndlrID;
141
142   hndlrID = CmiGetHandler(msg);
143   if(CpvAccess(handlerArray)[hndlrID][0] != 0){
144     return 1;
145   } else {
146     return 0;
147   }
148
149
150 #endif