source: trunk/nom/src/nomdebug.c

Last change on this file was 384, checked in by cinc, 17 years ago

Changed some types in method definitions.

File size: 15.6 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#ifdef __OS2__
36# define INCL_DOS
37# define INCL_DOSFILEMGR
38# define INCL_DOSERRORS
39# define INCL_WIN
40# define INCL_WINWORKPLACE
41# define INCL_OS2MM
42# define INCL_MMIOOS2
43# define INCL_MCIOS2
44# define INCL_GPI
45# define INCL_PM
46# include <os2.h>
47#endif /* __OS2__ */
48
49#include <stdarg.h>
50#include <stdio.h>
51
52#include "nom.h"
53#include "nomtk.h"
54#include "nomobj.h"
55#include "nomclassmanager.h"
56
57//#include "cwsomcls.h"
58extern NOMClassMgr* NOMClassMgrObject;
59extern gboolean fInitialized;
60
61NOMEXTERN void NOMLINK nomPrintObjectPointerErrorMsg(NOMObject* nomObject, NOMClass* nomClass, gchar* chrMethodName)
62{
63 if(!nomObject)
64 g_error("The object used to call the method %s is not valid. A NULL pointer was given.", chrMethodName);
65 else{
66 if(!nomIsObj(nomObject))
67 g_error("The object used to call the method %s is not a valid NOM object. ", chrMethodName);
68 else
69 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_nomQueryCreatedClassName(nomClass, NULL),
70 NOMObject_nomQueryClassName(nomObject, NULL));
71 }
72}
73
74/*
75 This function prints some more info about the object error. It's used for generic checks which
76 always return NULL which isn't always correct.
77 */
78static void nomPrintAdditionalErrorMsg(void)
79{
80 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.");
81}
82
83/* Function to check if NOMObject is valid before calling a method on it. Note that we don't have to check
84 the instance class here using nomIsA*(). */
85NOMEXTERN gboolean NOMLINK nomCheckNOMObjectPtr(NOMObject *nomSelf, NOMClass* nomClass, gchar* chrMethodName, CORBA_Environment *ev)
86{
87 /* Not initialized yet, so object check won't work. This means the three core NOM classes are not
88 yet created.*/
89 if(!fInitialized)
90 return TRUE;
91
92 if(ev && (ev->fFlags & NOMENV_FLG_DONT_CHECK_OBJECT))
93 return TRUE;
94
95 // g_message("In %s with %s %px nomClass: %px (%s)", __FUNCTION__, chrMethodName, nomSelf, nomClass, nomClass->mtab->nomClassName);
96 if(!nomIsObj(nomSelf))
97 {
98 nomPrintObjectPointerErrorMsg(nomSelf, nomClass, chrMethodName);
99 nomPrintAdditionalErrorMsg();
100 return FALSE;
101 }
102 return TRUE;
103}
104
105#include <string.h>
106/* Function to check if an object is valid before calling a method on it */
107NOMEXTERN gboolean NOMLINK nomCheckObjectPtr(NOMObject *nomSelf, NOMClass* nomClass, gchar* chrMethodName, CORBA_Environment *ev)
108{
109 /* Not initialized yet, so object check won't work. This means the three core NOM classes are not
110 yet created.*/
111 if(!fInitialized)
112 return TRUE;
113
114 if(ev && (ev->fFlags & NOMENV_FLG_DONT_CHECK_OBJECT))
115 return TRUE;
116
117 // g_message("In %s with %s %px nomClass: %px (%s)", __FUNCTION__, chrMethodName, nomSelf, nomClass, nomClass->mtab->nomClassName);
118 if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf, nomClass, NULL))
119 {
120 nomPrintObjectPointerErrorMsg(nomSelf, nomClass, chrMethodName);
121 nomPrintAdditionalErrorMsg();
122 return FALSE;
123 }
124 return TRUE;
125}
126
127NOMEXTERN CORBA_Environment* NOMLINK nomCreateEnvNoObjectCheck(void)
128{
129 CORBA_Environment * tempEnv=(CORBA_Environment*)NOMMalloc(sizeof(CORBA_Environment));
130 if(tempEnv)
131 tempEnv->fFlags|=NOMENV_FLG_DONT_CHECK_OBJECT;
132 return tempEnv;
133}
134
135static void dumpClassFunc(GQuark gquark, gpointer data, gpointer user_data)
136{
137 nomMethodTab* mtab;
138 NOMClassPriv* priv;
139
140 mtab=(nomMethodTab*)data;
141 priv=(NOMClassPriv*)mtab->nomClsInfo;
142
143 if(!priv)
144 nomPrintf("%s: gquark: %ld, %lx-> %s mtab: %lx, nomClsInfo->mtab: %lx\n",
145 __FUNCTION__, gquark, data, mtab->nomClassName, mtab, priv/*->mtab*/);
146 else
147 nomPrintf("%s: gquark: %ld, %lx-> %s mtab: %lx, nomClsInfo->mtab: %lx\n",
148 __FUNCTION__, gquark, data, mtab->nomClassName, mtab, priv->mtab);
149
150}
151
152NOMEXTERN void NOMLINK dumpClasses(void)
153{
154 GData *pgdata;
155
156 nomPrintf("----- %s ----- NOMClassMgrObject: %lx\n", __FUNCTION__, NOMClassMgrObject);
157
158 pgdata=(GData*)_nomGetClassList(NOMClassMgrObject, NULL);
159 if(pgdata){
160 nomPrintf("%s: classlist: %lx\n", __FUNCTION__, pgdata);
161 g_datalist_foreach(&pgdata, dumpClassFunc, pgdata);
162 }
163 nomPrintf("----- End of %s -----\n", __FUNCTION__);
164}
165
166void _dumpSci(nomStaticClassInfo* sci)
167{
168 nomPrintf("%d: --- sci dump ---:\n", __LINE__);
169 nomPrintf("&sci: 0x%x\n", sci);
170 nomPrintf("Num static methods: %d\n", sci->ulNumStaticMethods);
171 nomPrintf("Num static overrides: %d\n", sci->ulNumStaticOverrides);
172 nomPrintf("Major: %d, minor %d\n", sci->ulMajorVersion, sci->ulMinorVersion);
173 nomPrintf("Instance data size: %d\n", sci->ulInstanceDataSize);
174 //somPrintf("Max methods: %d\n", sci->maxMethods);
175 nomPrintf("numParents: %d\n", sci->ulNumParents);
176 nomPrintf("classId: %s\n", *sci->nomClassId);
177 if(sci->nomExplicitMetaId)
178 nomPrintf("explicitMetaId (meta class): %s\n", *sci->nomExplicitMetaId);
179 else
180 nomPrintf("explicitMetaId (meta class): NULL\n");
181 // somPrintf("*parents: 0x%x\n", sci->parents);
182 nomPrintf("somClassDataStructure cds: 0x%x\n",sci->nomCds);
183 if(sci->nomCds)
184 nomPrintf("classObject: 0x%x\n", sci->nomCds->nomClassObject);
185 //somPrintf("somCClassDataStructure ccds: 0x%x\n", sci->ccds);
186 nomPrintf("Static method table (nomStaticMethodDesc): 0x%x\n", sci->nomSMethods);
187 //somPrintf("Override method table (somOverrideMethod_t): 0x%x\n", sci->omt);
188
189 nomPrintf("------------------\n");
190
191}
192
193
194void _dumpClassDataStruct(nomClassDataStructure* cds, gulong ulNumMethods)
195{
196 int a;
197
198 nomPrintf("%d: --- classdataStruct dump num methods: %d ---:\n", __LINE__, ulNumMethods);
199 nomPrintf("classObject: %x\n", cds->nomClassObject);
200 for(a=0;a<ulNumMethods; a++)
201 nomPrintf("%d: %x at address %x\n", a+1, cds->nomTokens[a], &cds->nomTokens[a]);
202
203 nomPrintf("-----------------------------\n");
204}
205
206void _dumpMtab(nomMethodTab* mtab)
207{
208 int a;
209 nomMethodProc* entries;
210
211 nomPrintf("\n--- mtab dump for %x, %s (%s) ---\n", mtab, mtab->nomClassName, __FUNCTION__);
212 nomPrintf(" mtab: 0x%x\n", mtab);
213 nomPrintf(" classObject: 0x%x\n", mtab->nomClassObject);
214 nomPrintf(" classInfo: 0x%x\n", mtab->nomClsInfo);
215 // somPrintf("*classInfo: 0x%x\n", *sObj->mtab->classInfo);
216 nomPrintf(" className: %s\n", mtab->nomClassName);
217 nomPrintf(" instanceSize (this and all parents): %d 0x%x\n", mtab->ulInstanceSize, mtab->ulInstanceSize);
218 nomPrintf(" mtabSize: %d 0x%x\n", mtab->mtabSize, mtab->mtabSize);
219 nomPrintf(" somMethodProcs: (%ld)\n", (mtab->mtabSize-(glong)sizeof(nomMethodTab))/4);
220 // entries=sObj->mtab->entries[0];
221 for(a=0; a<=(mtab->mtabSize-sizeof(nomMethodTab))/4; a++)
222 nomPrintf(" %d: somMethodProc: 0x%x at 0x%x\n", a, mtab->entries[a], &mtab->entries[a]);
223 nomPrintf("--- end of mtab dump ---\n");
224}
225
226
227void _dumpObjShort(NOMObject* sObj)
228{
229
230 nomPrintf("--- Object dump (mtab) for %s ---\n", sObj->mtab->nomClassName);
231 nomPrintf("Obj: 0x%x\n", sObj);
232 nomPrintf("SOM_Any->mtab: 0x%x\n", sObj->mtab);
233 nomPrintf("classObject: 0x%x\n", sObj->mtab->nomClassObject);
234 nomPrintf("classInfo: 0x%x\n", sObj->mtab->nomClsInfo);
235#if 0
236 nomPrintf("*classInfo: 0x%x\n", *sObj->mtab->nomClsInfo);
237
238 so=(gulong*)sObj->mtab->classInfo;
239#endif
240 nomPrintf("className: %s\n", sObj->mtab->nomClassName);
241 nomPrintf("instanceSize (this and all parents): %d 0x%x\n", sObj->mtab->ulInstanceSize, sObj->mtab->ulInstanceSize);
242 nomPrintf("mtabSize: %d 0x%x\n", sObj->mtab->mtabSize, sObj->mtab->mtabSize);
243 nomPrintf("nomMethodProcs: (%d)\n", (sObj->mtab->mtabSize-sizeof(nomMethodTab))/4);
244 nomPrintf("classObject in entries[]: 0x%x\n", sObj->mtab->entries[0]);
245 // entries=sObj->mtab->entries[0];
246 // for(a=0; a<=(sObj->mtab->mtabSize-sizeof(somMethodTab))/4; a++)
247 // somPrintf("%d: somMethodProc: 0x%x\n", a, sObj->mtab->entries[a]);
248 nomPrintf("---------\n");
249}
250
251
252#if 0
253void _dumpStaticMTab(somStaticMethod_t* smt, gulong ulMethod)
254{
255 somStaticMethod_t* tmpSmt=&smt[ulMethod];
256
257 somPrintf("--- static method dump for 0x%x, method index: %d ---:\n", smt, ulMethod);
258 somPrintf("classData: %x\n", tmpSmt->classData);
259 somPrintf("methodId: %s\n", **tmpSmt->methodId);
260 somPrintf("methodDescriptor: %s\n", **tmpSmt->methodDescriptor);
261 somPrintf("method: 0x%x\n", tmpSmt->method);
262
263 somPrintf("-----------------------------\n");
264}
265
266void _dumpOverrideMTab(somOverrideMethod_t* omt, gulong ulMethod)
267{
268 somOverrideMethod_t* tmpOmt=&omt[ulMethod];
269
270 somPrintf("--- override method dump for 0x%x, method index: %d ---:\n", omt, ulMethod);
271 somPrintf("classId: %s\n", **tmpOmt->methodId);
272 // somPrintf("methodDescriptor: %s\n", **tmpOmt->methodDescriptor);
273 somPrintf("method: 0x%x\n", tmpOmt->method);
274
275 somPrintf("-----------------------------\n");
276}
277
278void SOMLINK _dumpParentMTab(somParentMtabStructPtr pMtabPtr)
279{
280
281 somPrintf("--- ParentMtabStruct dump for 0x%x (%s) ---:\n", pMtabPtr, pMtabPtr->mtab->className);
282 somPrintf("this mtab:\t\t\t%x\n", pMtabPtr->mtab);
283 somPrintf("somMethodTabs next:\t\t%x\n", pMtabPtr->next);
284 if(pMtabPtr->next) {
285 somPrintf("parent mtab (next->mtab):\t%x\n", pMtabPtr->next->mtab);
286 somPrintf(" next->next:\t\t\t%x\n", pMtabPtr->next->next);
287 }
288 else
289 somPrintf(" NO parent mtab\n");
290 somPrintf("classObject:\t\t\t0x%x\n", pMtabPtr->classObject);
291 somPrintf("instanceSize:\t\t\t%d 0x%x\n", pMtabPtr->instanceSize, pMtabPtr->instanceSize);
292 somPrintf("-----------------------------\n");
293}
294
295void _dumpParentMTabList(somParentMtabStructPtr pMtabPtr)
296{
297 somParentMtabStructPtr tempPtr=pMtabPtr;
298
299 while(tempPtr){
300 _dumpParentMTab(tempPtr);
301 if(tempPtr->next)
302 tempPtr=(void*)tempPtr->next->mtab;
303 else
304 tempPtr=NULL;
305 }
306
307}
308
309void _dumpMethodTabList(somMethodTabList *mtabList)
310{
311 somMethodTab *mtab;
312 int a=0;
313
314 somPrintf("--- somMethodTabList dump for 0x%x ---:\n", mtabList);
315 while(mtabList && a<3)
316 {
317 mtab=mtabList->mtab;
318
319 if(mtab)
320 somPrintf(" %d: mtab: %x , class: %s SOM class object: %x, priv object: %x, next: %x\n",
321 a, mtab, mtab->className, mtab->classObject, mtab->classInfo, mtabList->next);
322 else
323 somPrintf("mtab is 0!!\n");
324
325 mtabList=mtabList->next;
326 a++;
327 }
328 somPrintf("-----------------------------\n");
329}
330
331void SOMLINK _dumpMTabListPrivClass(SOMClassPriv *sClass)
332{
333 somMethodTabList *mtabList;
334 somMethodTab *mtab;
335 int a=0;
336
337 if(!sClass) {
338 somPrintf("--- somMethodTabList dump: no SOMClassPriv* ");
339 return;
340 }
341 mtabList=&sClass->mtabList;
342
343 somPrintf("\n--- somMethodTabList dump for 0x%x %s (%s) ---:\n", sClass, sClass->mtab->className, __FUNCTION__);
344 while(mtabList)
345 {
346 mtab=mtabList->mtab;
347 somPrintf(" %d: mtab: %x , class: %s SOM class object: %x, priv object: %x, next %x\n",
348 a, mtab, mtab->className, mtab->classObject, mtab->classInfo, mtabList->next);
349 mtabList=mtabList->next;
350 a++;
351 }
352 somPrintf("--- somMethodTabList end ---\n");
353}
354
355 /* Dump object data. This means more or less dumping of the methodTabStruct of this
356 object. A pointer to this struct is the first word of any object (SOMAny.mtab).
357
358 -- Object Instance Structure:
359
360 struct somMethodTabStruct;
361 typedef struct SOMAny_struct {
362 struct somMethodTabStruct *mtab;
363 integer4 body[1];
364 } SOMAny;
365
366typedef struct somMethodTabStruct {
367 SOMClass *classObject;
368 somClassInfo *classInfo;
369 char *className;
370 long instanceSize;
371 long dataAlignment;
372 long mtabSize;
373 long protectedDataOffset; // from class's introduced data
374 somDToken protectedDataToken;
375 somEmbeddedObjStruct *embeddedObjs;
376 // remaining structure is opaque
377 somMethodProc* entries[1]; <-- I found that this isn't correct (or I misseed something in the includes). When dumping a mtab
378 the following has this structure:
379
380 SOMClass *classObject; //The first class object (SOMObject)
381 This is basically a copy -> somMethodProc* firstMethod_1;
382 of the ClassDataStruct somMethodProc* secondMEthod_1;
383 ...
384 SOMClass *classObject; //The second class object
385 ClassDataStruct of 2. -> somMethodProc* firstMethod_2;
386 class somMethodProc* secondMEthod_2;
387
388} somMethodTab, *somMethodTabPtr;
389 */
390void SOMLINK _dumpObj(SOMObject* sObj)
391{
392 int a;
393 somMethodProc* entries;
394
395 somPrintf("\n--- Object dump (mtab) for %s (%s) ---\n", sObj->mtab->className, __FUNCTION__);
396 somPrintf(" Obj: 0x%x\n", sObj);
397 somPrintf(" SOM_Any->mtab: 0x%x\n", sObj->mtab);
398 somPrintf(" classObject: 0x%x\n", sObj->mtab->classObject);
399 somPrintf(" classInfo: 0x%x\n", sObj->mtab->classInfo);
400 // somPrintf("*classInfo: 0x%x\n", *sObj->mtab->classInfo);
401 somPrintf(" className: %s\n", sObj->mtab->className);
402 somPrintf(" instanceSize (this and all parents): %d 0x%x\n", sObj->mtab->instanceSize, sObj->mtab->instanceSize);
403 somPrintf(" mtabSize: %d 0x%x\n", sObj->mtab->mtabSize, sObj->mtab->mtabSize);
404 somPrintf(" somMethodProcs: (%ld)\n", (sObj->mtab->mtabSize-(glong)sizeof(somMethodTab))/4);
405 // entries=sObj->mtab->entries[0];
406 for(a=0; a<=(sObj->mtab->mtabSize-sizeof(somMethodTab))/4; a++)
407 somPrintf(" %d: somMethodProc: 0x%x at 0x%x\n", a, sObj->mtab->entries[a], &sObj->mtab->entries[a]);
408 somPrintf("--- end of object dump ---\n");
409}
410
411
412
413#endif
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
442
443
Note: See TracBrowser for help on using the repository browser.