Removed almost all warnings on origin2000.
[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
85   for(i = 0; i < CpvAccess(numBreakPoints); i++)
86     CsvAccess(BreakPoints)[i] = (newBreakPoints[i] - '0');
87 }
88
89 char *getBreakPoints(void)
90 {
91   char *temp;
92   int i;
93
94   if(CsvAccess(BreakPoints) == 0){
95     CsvAccess(BreakPoints) = (int *)malloc(CpvAccess(numBreakPoints) 
96                                            *sizeof(int));
97     for(i = 0; i < CpvAccess(numBreakPoints); i++)
98       CsvAccess(BreakPoints)[i] = 0;
99   }
100
101   temp = (char *)malloc(CpvAccess(numBreakPoints)*2*sizeof(char)+6);
102   strcpy(temp, "");
103   sprintf(temp, "%d#", CpvAccess(numBreakPoints));
104   for(i = 0; i < CpvAccess(numBreakPoints); i++){
105     char t[3];
106     sprintf(t, "%d#", CsvAccess(BreakPoints)[i]);
107     strcat(temp, t);
108   }
109   return(temp);
110 }
111
112 int isBreakPoint(char *msg)
113 {
114   int hndlrID;
115   int i;
116
117   if(CsvAccess(BreakPoints) == 0){
118     CsvAccess(BreakPoints) = (int *)malloc(CpvAccess(numBreakPoints)
119                                            *sizeof(int));
120     for(i = 0; i < CpvAccess(numBreakPoints); i++)
121       CsvAccess(BreakPoints)[i] = 0;
122   }
123   hndlrID = CmiGetHandler(msg);
124   if(CpvAccess(handlerArray)[hndlrID][0] != 0){
125     int offset;
126     indirectionFunction f;
127
128     f = CpvAccess(indirectionFnArray)[hndlrID];
129     offset = CpvAccess(offsetArray)[hndlrID] + (*f)(msg);
130
131     return(CsvAccess(BreakPoints)[offset]);
132   } else {
133     return 0;
134   }
135 }
136
137 int isEntryPoint(char *msg)
138 {
139   int hndlrID;
140
141   hndlrID = CmiGetHandler(msg);
142   if(CpvAccess(handlerArray)[hndlrID][0] != 0){
143     return 1;
144   } else {
145     return 0;
146   }
147
148
149 #endif