source: trunk/nom/src/nomdebug.c@ 284

Last change on this file since 284 was 281, checked in by cinc, 18 years ago

Some minor changes for the new IDL compiler

File size: 15.5 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2* Version: CDDL 1.0/LGPL 2.1
3*
4* The contents of this file are subject to the COMMON DEVELOPMENT AND
5* DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
6* this file except in compliance with the License. You may obtain a copy of
7* the License at http://www.sun.com/cddl/
8*
9* Software distributed under the License is distributed on an "AS IS" basis,
10* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11* for the specific language governing rights and limitations under the
12* License.
13*
14* The Original Code is "NOM" Netlabs Object Model
15*
16* The Initial Developer of the Original Code is
17* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
18* Portions created by the Initial Developer are Copyright (C) 2005-2007
19* the Initial Developer. All Rights Reserved.
20*
21* Contributor(s):
22*
23* Alternatively, the contents of this file may be used under the terms of
24* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
25* case the provisions of the LGPL are applicable instead of those above. If
26* you wish to allow use of your version of this file only under the terms of
27* the LGPL, and not to allow others to use your version of this file under
28* the terms of the CDDL, indicate your decision by deleting the provisions
29* above and replace them with the notice and other provisions required by the
30* LGPL. If you do not delete the provisions above, a recipient may use your
31* version of this file under the terms of any one of the CDDL or the LGPL.
32*
33* ***** END LICENSE BLOCK ***** */
34
35#define INCL_DOS
36#define INCL_DOSFILEMGR
37#define INCL_DOSERRORS
38#define INCL_WIN
39#define INCL_WINWORKPLACE
40#define INCL_OS2MM
41#define INCL_MMIOOS2
42#define INCL_MCIOS2
43#define INCL_GPI
44#define INCL_PM
45
46#include <os2.h>
47#include <stdarg.h>
48#include <stdio.h>
49
50#include "nom.h"
51#include "nomtk.h"
52#include "nomobj.h"
53#include "nomclassmanager.h"
54
55//#include "cwsomcls.h"
56extern NOMClassMgr* NOMClassMgrObject;
57extern gboolean fInitialized;
58
59NOMEXTERN void NOMLINK nomPrintObjectPointerErrorMsg(NOMObject* nomObject, NOMClass* nomClass, gchar* chrMethodName)
60{
61 if(!nomObject)
62 g_error("The object used to call the method %s is not valid. A NULL pointer was given.", chrMethodName);
63 else{
64 if(!nomIsObj(nomObject))
65 g_error("The object used to call the method %s is not a valid NOM object. ", chrMethodName);
66 else
67 g_error("The object for which the method %s should be called is not valid for this method.\nThe object must be some instance of class %s (or of a subclass) but is a %s.", chrMethodName, NOMClass_nomGetCreatedClassName(nomClass, NULLHANDLE),
68 NOMObject_nomGetClassName(nomObject, NULLHANDLE));
69 }
70}
71
72/*
73 This function prints some more info about the object error. It's used for generic checks which
74 always return NULL which isn't always correct.
75 */
76static void nomPrintAdditionalErrorMsg(void)
77{
78 g_message("Note that NULL is returned for the call (if the method returns a value). This may not be correct. Use the NOMPARMCHECK() macro to specify default return values for methods.");
79}
80
81/* Function to check if NOMObject is valid before calling a method on it. Note that we don't have to check
82 the instance class here using nomIsA*(). */
83NOMEXTERN gboolean NOMLINK nomCheckNOMObjectPtr(NOMObject *nomSelf, NOMClass* nomClass, gchar* chrMethodName, CORBA_Environment *ev)
84{
85 /* Not initialized yet, so object check won't work. This means the three core NOM classes are not
86 yet created.*/
87 if(!fInitialized)
88 return TRUE;
89
90 if(ev && (ev->fFlags & NOMENV_FLG_DONT_CHECK_OBJECT))
91 return TRUE;
92
93 // g_message("In %s with %s %px nomClass: %px (%s)", __FUNCTION__, chrMethodName, nomSelf, nomClass, nomClass->mtab->nomClassName);
94 if(!nomIsObj(nomSelf))
95 {
96 nomPrintObjectPointerErrorMsg(nomSelf, nomClass, chrMethodName);
97 nomPrintAdditionalErrorMsg();
98 return FALSE;
99 }
100 return TRUE;
101}
102
103#include <string.h>
104/* Function to check if an object is valid before calling a method on it */
105NOMEXTERN gboolean NOMLINK nomCheckObjectPtr(NOMObject *nomSelf, NOMClass* nomClass, gchar* chrMethodName, CORBA_Environment *ev)
106{
107 /* Not initialized yet, so object check won't work. This means the three core NOM classes are not
108 yet created.*/
109 if(!fInitialized)
110 return TRUE;
111
112 if(ev && (ev->fFlags & NOMENV_FLG_DONT_CHECK_OBJECT))
113 return TRUE;
114
115 // g_message("In %s with %s %px nomClass: %px (%s)", __FUNCTION__, chrMethodName, nomSelf, nomClass, nomClass->mtab->nomClassName);
116 if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf, nomClass, NULLHANDLE))
117 {
118 nomPrintObjectPointerErrorMsg(nomSelf, nomClass, chrMethodName);
119 nomPrintAdditionalErrorMsg();
120 return FALSE;
121 }
122 return TRUE;
123}
124
125NOMEXTERN CORBA_Environment* NOMLINK nomCreateEnvNoObjectCheck(void)
126{
127 CORBA_Environment * tempEnv=(CORBA_Environment*)NOMMalloc(sizeof(CORBA_Environment));
128 if(tempEnv)
129 tempEnv->fFlags|=NOMENV_FLG_DONT_CHECK_OBJECT;
130 return tempEnv;
131}
132
133static void dumpClassFunc(GQuark gquark, gpointer data, gpointer user_data)
134{
135 nomMethodTab* mtab;
136 NOMClassPriv* priv;
137
138 mtab=(nomMethodTab*)data;
139 priv=(NOMClassPriv*)mtab->nomClsInfo;
140
141 if(!priv)
142 nomPrintf("%s: gquark: %ld, %lx-> %s mtab: %lx, nomClsInfo->mtab: %lx\n",
143 __FUNCTION__, gquark, data, mtab->nomClassName, mtab, priv/*->mtab*/);
144 else
145 nomPrintf("%s: gquark: %ld, %lx-> %s mtab: %lx, nomClsInfo->mtab: %lx\n",
146 __FUNCTION__, gquark, data, mtab->nomClassName, mtab, priv->mtab);
147
148}
149
150NOMEXTERN void NOMLINK dumpClasses(void)
151{
152 GData *pgdata;
153
154 nomPrintf("----- %s ----- NOMClassMgrObject: %lx\n", __FUNCTION__, NOMClassMgrObject);
155
156 pgdata=_nomGetClassList(NOMClassMgrObject, NULLHANDLE);
157 if(pgdata){
158 nomPrintf("%s: classlist: %lx\n", __FUNCTION__, pgdata);
159 g_datalist_foreach(&pgdata, dumpClassFunc, pgdata);
160 }
161 nomPrintf("----- End of %s -----\n", __FUNCTION__);
162}
163
164void _dumpSci(nomStaticClassInfo* sci)
165{
166 nomPrintf("%d: --- sci dump ---:\n", __LINE__);
167 nomPrintf("&sci: 0x%x\n", sci);
168 nomPrintf("Num static methods: %d\n", sci->ulNumStaticMethods);
169 nomPrintf("Num static overrides: %d\n", sci->ulNumStaticOverrides);
170 nomPrintf("Major: %d, minor %d\n", sci->ulMajorVersion, sci->ulMinorVersion);
171 nomPrintf("Instance data size: %d\n", sci->ulInstanceDataSize);
172 //somPrintf("Max methods: %d\n", sci->maxMethods);
173 nomPrintf("numParents: %d\n", sci->ulNumParents);
174 nomPrintf("classId: %s\n", *sci->nomClassId);
175 if(sci->nomExplicitMetaId)
176 nomPrintf("explicitMetaId (meta class): %s\n", *sci->nomExplicitMetaId);
177 else
178 nomPrintf("explicitMetaId (meta class): NULLHANDLE\n");
179 // somPrintf("*parents: 0x%x\n", sci->parents);
180 nomPrintf("somClassDataStructure cds: 0x%x\n",sci->nomCds);
181 if(sci->nomCds)
182 nomPrintf("classObject: 0x%x\n", sci->nomCds->nomClassObject);
183 //somPrintf("somCClassDataStructure ccds: 0x%x\n", sci->ccds);
184 nomPrintf("Static method table (nomStaticMethodDesc): 0x%x\n", sci->nomSMethods);
185 //somPrintf("Override method table (somOverrideMethod_t): 0x%x\n", sci->omt);
186
187 nomPrintf("------------------\n");
188
189}
190
191
192void _dumpClassDataStruct(nomClassDataStructure* cds, ULONG ulNumMethods)
193{
194 int a;
195
196 nomPrintf("%d: --- classdataStruct dump num methods: %d ---:\n", __LINE__, ulNumMethods);
197 nomPrintf("classObject: %x\n", cds->nomClassObject);
198 for(a=0;a<ulNumMethods; a++)
199 nomPrintf("%d: %x at address %x\n", a+1, cds->nomTokens[a], &cds->nomTokens[a]);
200
201 nomPrintf("-----------------------------\n");
202}
203
204void _dumpMtab(nomMethodTab* mtab)
205{
206 int a;
207 nomMethodProc* entries;
208
209 nomPrintf("\n--- mtab dump for %x, %s (%s) ---\n", mtab, mtab->nomClassName, __FUNCTION__);
210 nomPrintf(" mtab: 0x%x\n", mtab);
211 nomPrintf(" classObject: 0x%x\n", mtab->nomClassObject);
212 nomPrintf(" classInfo: 0x%x\n", mtab->nomClsInfo);
213 // somPrintf("*classInfo: 0x%x\n", *sObj->mtab->classInfo);
214 nomPrintf(" className: %s\n", mtab->nomClassName);
215 nomPrintf(" instanceSize (this and all parents): %d 0x%x\n", mtab->ulInstanceSize, mtab->ulInstanceSize);
216 nomPrintf(" mtabSize: %d 0x%x\n", mtab->mtabSize, mtab->mtabSize);
217 nomPrintf(" somMethodProcs: (%ld)\n", (mtab->mtabSize-(LONG)sizeof(nomMethodTab))/4);
218 // entries=sObj->mtab->entries[0];
219 for(a=0; a<=(mtab->mtabSize-sizeof(nomMethodTab))/4; a++)
220 nomPrintf(" %d: somMethodProc: 0x%x at 0x%x\n", a, mtab->entries[a], &mtab->entries[a]);
221 nomPrintf("--- end of mtab dump ---\n");
222}
223
224
225void _dumpObjShort(NOMObject* sObj)
226{
227
228 nomPrintf("--- Object dump (mtab) for %s ---\n", sObj->mtab->nomClassName);
229 nomPrintf("Obj: 0x%x\n", sObj);
230 nomPrintf("SOM_Any->mtab: 0x%x\n", sObj->mtab);
231 nomPrintf("classObject: 0x%x\n", sObj->mtab->nomClassObject);
232 nomPrintf("classInfo: 0x%x\n", sObj->mtab->nomClsInfo);
233#if 0
234 nomPrintf("*classInfo: 0x%x\n", *sObj->mtab->nomClsInfo);
235
236 so=(ULONG*)sObj->mtab->classInfo;
237#endif
238 nomPrintf("className: %s\n", sObj->mtab->nomClassName);
239 nomPrintf("instanceSize (this and all parents): %d 0x%x\n", sObj->mtab->ulInstanceSize, sObj->mtab->ulInstanceSize);
240 nomPrintf("mtabSize: %d 0x%x\n", sObj->mtab->mtabSize, sObj->mtab->mtabSize);
241 nomPrintf("nomMethodProcs: (%d)\n", (sObj->mtab->mtabSize-sizeof(nomMethodTab))/4);
242 nomPrintf("classObject in entries[]: 0x%x\n", sObj->mtab->entries[0]);
243 // entries=sObj->mtab->entries[0];
244 // for(a=0; a<=(sObj->mtab->mtabSize-sizeof(somMethodTab))/4; a++)
245 // somPrintf("%d: somMethodProc: 0x%x\n", a, sObj->mtab->entries[a]);
246 nomPrintf("---------\n");
247}
248
249
250#if 0
251void _dumpStaticMTab(somStaticMethod_t* smt, ULONG ulMethod)
252{
253 somStaticMethod_t* tmpSmt=&smt[ulMethod];
254
255 somPrintf("--- static method dump for 0x%x, method index: %d ---:\n", smt, ulMethod);
256 somPrintf("classData: %x\n", tmpSmt->classData);
257 somPrintf("methodId: %s\n", **tmpSmt->methodId);
258 somPrintf("methodDescriptor: %s\n", **tmpSmt->methodDescriptor);
259 somPrintf("method: 0x%x\n", tmpSmt->method);
260
261 somPrintf("-----------------------------\n");
262}
263
264void _dumpOverrideMTab(somOverrideMethod_t* omt, ULONG ulMethod)
265{
266 somOverrideMethod_t* tmpOmt=&omt[ulMethod];
267
268 somPrintf("--- override method dump for 0x%x, method index: %d ---:\n", omt, ulMethod);
269 somPrintf("classId: %s\n", **tmpOmt->methodId);
270 // somPrintf("methodDescriptor: %s\n", **tmpOmt->methodDescriptor);
271 somPrintf("method: 0x%x\n", tmpOmt->method);
272
273 somPrintf("-----------------------------\n");
274}
275
276void SOMLINK _dumpParentMTab(somParentMtabStructPtr pMtabPtr)
277{
278
279 somPrintf("--- ParentMtabStruct dump for 0x%x (%s) ---:\n", pMtabPtr, pMtabPtr->mtab->className);
280 somPrintf("this mtab:\t\t\t%x\n", pMtabPtr->mtab);
281 somPrintf("somMethodTabs next:\t\t%x\n", pMtabPtr->next);
282 if(pMtabPtr->next) {
283 somPrintf("parent mtab (next->mtab):\t%x\n", pMtabPtr->next->mtab);
284 somPrintf(" next->next:\t\t\t%x\n", pMtabPtr->next->next);
285 }
286 else
287 somPrintf(" NO parent mtab\n");
288 somPrintf("classObject:\t\t\t0x%x\n", pMtabPtr->classObject);
289 somPrintf("instanceSize:\t\t\t%d 0x%x\n", pMtabPtr->instanceSize, pMtabPtr->instanceSize);
290 somPrintf("-----------------------------\n");
291}
292
293void _dumpParentMTabList(somParentMtabStructPtr pMtabPtr)
294{
295 somParentMtabStructPtr tempPtr=pMtabPtr;
296
297 while(tempPtr){
298 _dumpParentMTab(tempPtr);
299 if(tempPtr->next)
300 tempPtr=(void*)tempPtr->next->mtab;
301 else
302 tempPtr=NULLHANDLE;
303 }
304
305}
306
307void _dumpMethodTabList(somMethodTabList *mtabList)
308{
309 somMethodTab *mtab;
310 int a=0;
311
312 somPrintf("--- somMethodTabList dump for 0x%x ---:\n", mtabList);
313 while(mtabList && a<3)
314 {
315 mtab=mtabList->mtab;
316
317 if(mtab)
318 somPrintf(" %d: mtab: %x , class: %s SOM class object: %x, priv object: %x, next: %x\n",
319 a, mtab, mtab->className, mtab->classObject, mtab->classInfo, mtabList->next);
320 else
321 somPrintf("mtab is 0!!\n");
322
323 mtabList=mtabList->next;
324 a++;
325 }
326 somPrintf("-----------------------------\n");
327}
328
329void SOMLINK _dumpMTabListPrivClass(SOMClassPriv *sClass)
330{
331 somMethodTabList *mtabList;
332 somMethodTab *mtab;
333 int a=0;
334
335 if(!sClass) {
336 somPrintf("--- somMethodTabList dump: no SOMClassPriv* ");
337 return;
338 }
339 mtabList=&sClass->mtabList;
340
341 somPrintf("\n--- somMethodTabList dump for 0x%x %s (%s) ---:\n", sClass, sClass->mtab->className, __FUNCTION__);
342 while(mtabList)
343 {
344 mtab=mtabList->mtab;
345 somPrintf(" %d: mtab: %x , class: %s SOM class object: %x, priv object: %x, next %x\n",
346 a, mtab, mtab->className, mtab->classObject, mtab->classInfo, mtabList->next);
347 mtabList=mtabList->next;
348 a++;
349 }
350 somPrintf("--- somMethodTabList end ---\n");
351}
352
353 /* Dump object data. This means more or less dumping of the methodTabStruct of this
354 object. A pointer to this struct is the first word of any object (SOMAny.mtab).
355
356 -- Object Instance Structure:
357
358 struct somMethodTabStruct;
359 typedef struct SOMAny_struct {
360 struct somMethodTabStruct *mtab;
361 integer4 body[1];
362 } SOMAny;
363
364typedef struct somMethodTabStruct {
365 SOMClass *classObject;
366 somClassInfo *classInfo;
367 char *className;
368 long instanceSize;
369 long dataAlignment;
370 long mtabSize;
371 long protectedDataOffset; // from class's introduced data
372 somDToken protectedDataToken;
373 somEmbeddedObjStruct *embeddedObjs;
374 // remaining structure is opaque
375 somMethodProc* entries[1]; <-- I found that this isn't correct (or I misseed something in the includes). When dumping a mtab
376 the following has this structure:
377
378 SOMClass *classObject; //The first class object (SOMObject)
379 This is basically a copy -> somMethodProc* firstMethod_1;
380 of the ClassDataStruct somMethodProc* secondMEthod_1;
381 ...
382 SOMClass *classObject; //The second class object
383 ClassDataStruct of 2. -> somMethodProc* firstMethod_2;
384 class somMethodProc* secondMEthod_2;
385
386} somMethodTab, *somMethodTabPtr;
387 */
388void SOMLINK _dumpObj(SOMObject* sObj)
389{
390 int a;
391 somMethodProc* entries;
392
393 somPrintf("\n--- Object dump (mtab) for %s (%s) ---\n", sObj->mtab->className, __FUNCTION__);
394 somPrintf(" Obj: 0x%x\n", sObj);
395 somPrintf(" SOM_Any->mtab: 0x%x\n", sObj->mtab);
396 somPrintf(" classObject: 0x%x\n", sObj->mtab->classObject);
397 somPrintf(" classInfo: 0x%x\n", sObj->mtab->classInfo);
398 // somPrintf("*classInfo: 0x%x\n", *sObj->mtab->classInfo);
399 somPrintf(" className: %s\n", sObj->mtab->className);
400 somPrintf(" instanceSize (this and all parents): %d 0x%x\n", sObj->mtab->instanceSize, sObj->mtab->instanceSize);
401 somPrintf(" mtabSize: %d 0x%x\n", sObj->mtab->mtabSize, sObj->mtab->mtabSize);
402 somPrintf(" somMethodProcs: (%ld)\n", (sObj->mtab->mtabSize-(LONG)sizeof(somMethodTab))/4);
403 // entries=sObj->mtab->entries[0];
404 for(a=0; a<=(sObj->mtab->mtabSize-sizeof(somMethodTab))/4; a++)
405 somPrintf(" %d: somMethodProc: 0x%x at 0x%x\n", a, sObj->mtab->entries[a], &sObj->mtab->entries[a]);
406 somPrintf("--- end of object dump ---\n");
407}
408
409
410
411#endif
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
Note: See TracBrowser for help on using the repository browser.