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

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

Better error message.

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#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_warning("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_warning("The object used to call the method %s is not a valid NOM object. ", chrMethodName);
66 else
67 g_warning("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(strstr( chrMethodName, "nomIsObj"))
113 //return TRUE;
114
115 if(ev && (ev->fFlags & NOMENV_FLG_DONT_CHECK_OBJECT))
116 return TRUE;
117
118 // g_message("In %s with %s %px nomClass: %px (%s)", __FUNCTION__, chrMethodName, nomSelf, nomClass, nomClass->mtab->nomClassName);
119 if(!nomIsObj(nomSelf) || !_nomIsANoClsCheck(nomSelf, nomClass, NULLHANDLE))
120 {
121 nomPrintObjectPointerErrorMsg(nomSelf, nomClass, chrMethodName);
122 nomPrintAdditionalErrorMsg();
123 return FALSE;
124 }
125 return TRUE;
126}
127
128NOMEXTERN CORBA_Environment* NOMLINK nomCreateEnvNoObjectCheck(void)
129{
130 CORBA_Environment * tempEnv=(CORBA_Environment*)NOMMalloc(sizeof(CORBA_Environment));
131 if(tempEnv)
132 tempEnv->fFlags|=NOMENV_FLG_DONT_CHECK_OBJECT;
133 return tempEnv;
134}
135
136static void dumpClassFunc(GQuark gquark, gpointer data, gpointer user_data)
137{
138 nomMethodTab* mtab;
139 NOMClassPriv* priv;
140
141 mtab=(nomMethodTab*)data;
142 priv=(NOMClassPriv*)mtab->nomClsInfo;
143
144 if(!priv)
145 nomPrintf("%s: gquark: %ld, %lx-> %s mtab: %lx, nomClsInfo->mtab: %lx\n",
146 __FUNCTION__, gquark, data, mtab->nomClassName, mtab, priv/*->mtab*/);
147 else
148 nomPrintf("%s: gquark: %ld, %lx-> %s mtab: %lx, nomClsInfo->mtab: %lx\n",
149 __FUNCTION__, gquark, data, mtab->nomClassName, mtab, priv->mtab);
150
151}
152
153NOMEXTERN void NOMLINK dumpClasses(void)
154{
155 GData *pgdata;
156
157 nomPrintf("----- %s ----- NOMClassMgrObject: %lx\n", __FUNCTION__, NOMClassMgrObject);
158
159 pgdata=_nomGetClassList(NOMClassMgrObject, NULLHANDLE);
160 if(pgdata){
161 nomPrintf("%s: classlist: %lx\n", __FUNCTION__, pgdata);
162 g_datalist_foreach(&pgdata, dumpClassFunc, pgdata);
163 }
164 nomPrintf("----- End of %s -----\n", __FUNCTION__);
165}
166
167void _dumpSci(nomStaticClassInfo* sci)
168{
169 nomPrintf("%d: --- sci dump ---:\n", __LINE__);
170 nomPrintf("&sci: 0x%x\n", sci);
171 nomPrintf("Num static methods: %d\n", sci->ulNumStaticMethods);
172 nomPrintf("Num static overrides: %d\n", sci->ulNumStaticOverrides);
173 nomPrintf("Major: %d, minor %d\n", sci->ulMajorVersion, sci->ulMinorVersion);
174 nomPrintf("Instance data size: %d\n", sci->ulInstanceDataSize);
175 //somPrintf("Max methods: %d\n", sci->maxMethods);
176 nomPrintf("numParents: %d\n", sci->ulNumParents);
177 nomPrintf("classId: %s\n", *sci->nomClassId);
178 if(sci->nomExplicitMetaId)
179 nomPrintf("explicitMetaId (meta class): %s\n", *sci->nomExplicitMetaId);
180 else
181 nomPrintf("explicitMetaId (meta class): NULLHANDLE\n");
182 // somPrintf("*parents: 0x%x\n", sci->parents);
183 nomPrintf("somClassDataStructure cds: 0x%x\n",sci->nomCds);
184 if(sci->nomCds)
185 nomPrintf("classObject: 0x%x\n", sci->nomCds->nomClassObject);
186 //somPrintf("somCClassDataStructure ccds: 0x%x\n", sci->ccds);
187 nomPrintf("Static method table (nomStaticMethodDesc): 0x%x\n", sci->nomSMethods);
188 //somPrintf("Override method table (somOverrideMethod_t): 0x%x\n", sci->omt);
189
190 nomPrintf("------------------\n");
191
192}
193
194
195void _dumpClassDataStruct(nomClassDataStructure* cds, ULONG ulNumMethods)
196{
197 int a;
198
199 nomPrintf("%d: --- classdataStruct dump num methods: %d ---:\n", __LINE__, ulNumMethods);
200 nomPrintf("classObject: %x\n", cds->nomClassObject);
201 for(a=0;a<ulNumMethods; a++)
202 nomPrintf("%d: %x at address %x\n", a+1, cds->nomTokens[a], &cds->nomTokens[a]);
203
204 nomPrintf("-----------------------------\n");
205}
206
207void _dumpMtab(nomMethodTab* mtab)
208{
209 int a;
210 nomMethodProc* entries;
211
212 nomPrintf("\n--- mtab dump for %x, %s (%s) ---\n", mtab, mtab->nomClassName, __FUNCTION__);
213 nomPrintf(" mtab: 0x%x\n", mtab);
214 nomPrintf(" classObject: 0x%x\n", mtab->nomClassObject);
215 nomPrintf(" classInfo: 0x%x\n", mtab->nomClsInfo);
216 // somPrintf("*classInfo: 0x%x\n", *sObj->mtab->classInfo);
217 nomPrintf(" className: %s\n", mtab->nomClassName);
218 nomPrintf(" instanceSize (this and all parents): %d 0x%x\n", mtab->ulInstanceSize, mtab->ulInstanceSize);
219 nomPrintf(" mtabSize: %d 0x%x\n", mtab->mtabSize, mtab->mtabSize);
220 nomPrintf(" somMethodProcs: (%ld)\n", (mtab->mtabSize-(LONG)sizeof(nomMethodTab))/4);
221 // entries=sObj->mtab->entries[0];
222 for(a=0; a<=(mtab->mtabSize-sizeof(nomMethodTab))/4; a++)
223 nomPrintf(" %d: somMethodProc: 0x%x at 0x%x\n", a, mtab->entries[a], &mtab->entries[a]);
224 nomPrintf("--- end of mtab dump ---\n");
225}
226
227
228void _dumpObjShort(NOMObject* sObj)
229{
230
231 nomPrintf("--- Object dump (mtab) for %s ---\n", sObj->mtab->nomClassName);
232 nomPrintf("Obj: 0x%x\n", sObj);
233 nomPrintf("SOM_Any->mtab: 0x%x\n", sObj->mtab);
234 nomPrintf("classObject: 0x%x\n", sObj->mtab->nomClassObject);
235 nomPrintf("classInfo: 0x%x\n", sObj->mtab->nomClsInfo);
236#if 0
237 nomPrintf("*classInfo: 0x%x\n", *sObj->mtab->nomClsInfo);
238
239 so=(ULONG*)sObj->mtab->classInfo;
240#endif
241 nomPrintf("className: %s\n", sObj->mtab->nomClassName);
242 nomPrintf("instanceSize (this and all parents): %d 0x%x\n", sObj->mtab->ulInstanceSize, sObj->mtab->ulInstanceSize);
243 nomPrintf("mtabSize: %d 0x%x\n", sObj->mtab->mtabSize, sObj->mtab->mtabSize);
244 nomPrintf("nomMethodProcs: (%d)\n", (sObj->mtab->mtabSize-sizeof(nomMethodTab))/4);
245 nomPrintf("classObject in entries[]: 0x%x\n", sObj->mtab->entries[0]);
246 // entries=sObj->mtab->entries[0];
247 // for(a=0; a<=(sObj->mtab->mtabSize-sizeof(somMethodTab))/4; a++)
248 // somPrintf("%d: somMethodProc: 0x%x\n", a, sObj->mtab->entries[a]);
249 nomPrintf("---------\n");
250}
251
252
253#if 0
254void _dumpStaticMTab(somStaticMethod_t* smt, ULONG ulMethod)
255{
256 somStaticMethod_t* tmpSmt=&smt[ulMethod];
257
258 somPrintf("--- static method dump for 0x%x, method index: %d ---:\n", smt, ulMethod);
259 somPrintf("classData: %x\n", tmpSmt->classData);
260 somPrintf("methodId: %s\n", **tmpSmt->methodId);
261 somPrintf("methodDescriptor: %s\n", **tmpSmt->methodDescriptor);
262 somPrintf("method: 0x%x\n", tmpSmt->method);
263
264 somPrintf("-----------------------------\n");
265}
266
267void _dumpOverrideMTab(somOverrideMethod_t* omt, ULONG ulMethod)
268{
269 somOverrideMethod_t* tmpOmt=&omt[ulMethod];
270
271 somPrintf("--- override method dump for 0x%x, method index: %d ---:\n", omt, ulMethod);
272 somPrintf("classId: %s\n", **tmpOmt->methodId);
273 // somPrintf("methodDescriptor: %s\n", **tmpOmt->methodDescriptor);
274 somPrintf("method: 0x%x\n", tmpOmt->method);
275
276 somPrintf("-----------------------------\n");
277}
278
279void SOMLINK _dumpParentMTab(somParentMtabStructPtr pMtabPtr)
280{
281
282 somPrintf("--- ParentMtabStruct dump for 0x%x (%s) ---:\n", pMtabPtr, pMtabPtr->mtab->className);
283 somPrintf("this mtab:\t\t\t%x\n", pMtabPtr->mtab);
284 somPrintf("somMethodTabs next:\t\t%x\n", pMtabPtr->next);
285 if(pMtabPtr->next) {
286 somPrintf("parent mtab (next->mtab):\t%x\n", pMtabPtr->next->mtab);
287 somPrintf(" next->next:\t\t\t%x\n", pMtabPtr->next->next);
288 }
289 else
290 somPrintf(" NO parent mtab\n");
291 somPrintf("classObject:\t\t\t0x%x\n", pMtabPtr->classObject);
292 somPrintf("instanceSize:\t\t\t%d 0x%x\n", pMtabPtr->instanceSize, pMtabPtr->instanceSize);
293 somPrintf("-----------------------------\n");
294}
295
296void _dumpParentMTabList(somParentMtabStructPtr pMtabPtr)
297{
298 somParentMtabStructPtr tempPtr=pMtabPtr;
299
300 while(tempPtr){
301 _dumpParentMTab(tempPtr);
302 if(tempPtr->next)
303 tempPtr=(void*)tempPtr->next->mtab;
304 else
305 tempPtr=NULLHANDLE;
306 }
307
308}
309
310void _dumpMethodTabList(somMethodTabList *mtabList)
311{
312 somMethodTab *mtab;
313 int a=0;
314
315 somPrintf("--- somMethodTabList dump for 0x%x ---:\n", mtabList);
316 while(mtabList && a<3)
317 {
318 mtab=mtabList->mtab;
319
320 if(mtab)
321 somPrintf(" %d: mtab: %x , class: %s SOM class object: %x, priv object: %x, next: %x\n",
322 a, mtab, mtab->className, mtab->classObject, mtab->classInfo, mtabList->next);
323 else
324 somPrintf("mtab is 0!!\n");
325
326 mtabList=mtabList->next;
327 a++;
328 }
329 somPrintf("-----------------------------\n");
330}
331
332void SOMLINK _dumpMTabListPrivClass(SOMClassPriv *sClass)
333{
334 somMethodTabList *mtabList;
335 somMethodTab *mtab;
336 int a=0;
337
338 if(!sClass) {
339 somPrintf("--- somMethodTabList dump: no SOMClassPriv* ");
340 return;
341 }
342 mtabList=&sClass->mtabList;
343
344 somPrintf("\n--- somMethodTabList dump for 0x%x %s (%s) ---:\n", sClass, sClass->mtab->className, __FUNCTION__);
345 while(mtabList)
346 {
347 mtab=mtabList->mtab;
348 somPrintf(" %d: mtab: %x , class: %s SOM class object: %x, priv object: %x, next %x\n",
349 a, mtab, mtab->className, mtab->classObject, mtab->classInfo, mtabList->next);
350 mtabList=mtabList->next;
351 a++;
352 }
353 somPrintf("--- somMethodTabList end ---\n");
354}
355
356 /* Dump object data. This means more or less dumping of the methodTabStruct of this
357 object. A pointer to this struct is the first word of any object (SOMAny.mtab).
358
359 -- Object Instance Structure:
360
361 struct somMethodTabStruct;
362 typedef struct SOMAny_struct {
363 struct somMethodTabStruct *mtab;
364 integer4 body[1];
365 } SOMAny;
366
367typedef struct somMethodTabStruct {
368 SOMClass *classObject;
369 somClassInfo *classInfo;
370 char *className;
371 long instanceSize;
372 long dataAlignment;
373 long mtabSize;
374 long protectedDataOffset; // from class's introduced data
375 somDToken protectedDataToken;
376 somEmbeddedObjStruct *embeddedObjs;
377 // remaining structure is opaque
378 somMethodProc* entries[1]; <-- I found that this isn't correct (or I misseed something in the includes). When dumping a mtab
379 the following has this structure:
380
381 SOMClass *classObject; //The first class object (SOMObject)
382 This is basically a copy -> somMethodProc* firstMethod_1;
383 of the ClassDataStruct somMethodProc* secondMEthod_1;
384 ...
385 SOMClass *classObject; //The second class object
386 ClassDataStruct of 2. -> somMethodProc* firstMethod_2;
387 class somMethodProc* secondMEthod_2;
388
389} somMethodTab, *somMethodTabPtr;
390 */
391void SOMLINK _dumpObj(SOMObject* sObj)
392{
393 int a;
394 somMethodProc* entries;
395
396 somPrintf("\n--- Object dump (mtab) for %s (%s) ---\n", sObj->mtab->className, __FUNCTION__);
397 somPrintf(" Obj: 0x%x\n", sObj);
398 somPrintf(" SOM_Any->mtab: 0x%x\n", sObj->mtab);
399 somPrintf(" classObject: 0x%x\n", sObj->mtab->classObject);
400 somPrintf(" classInfo: 0x%x\n", sObj->mtab->classInfo);
401 // somPrintf("*classInfo: 0x%x\n", *sObj->mtab->classInfo);
402 somPrintf(" className: %s\n", sObj->mtab->className);
403 somPrintf(" instanceSize (this and all parents): %d 0x%x\n", sObj->mtab->instanceSize, sObj->mtab->instanceSize);
404 somPrintf(" mtabSize: %d 0x%x\n", sObj->mtab->mtabSize, sObj->mtab->mtabSize);
405 somPrintf(" somMethodProcs: (%ld)\n", (sObj->mtab->mtabSize-(LONG)sizeof(somMethodTab))/4);
406 // entries=sObj->mtab->entries[0];
407 for(a=0; a<=(sObj->mtab->mtabSize-sizeof(somMethodTab))/4; a++)
408 somPrintf(" %d: somMethodProc: 0x%x at 0x%x\n", a, sObj->mtab->entries[a], &sObj->mtab->entries[a]);
409 somPrintf("--- end of object dump ---\n");
410}
411
412
413
414#endif
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
444
Note: See TracBrowser for help on using the repository browser.