home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / hp / 13109 < prev    next >
Encoding:
Text File  |  1992-11-19  |  4.0 KB  |  144 lines

  1. Newsgroups: comp.sys.hp
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!watserv2.uwaterloo.ca!madmax.uwaterloo.ca!gordon
  3. From: gordon@madmax.uwaterloo.ca (Gordon R. Strachan)
  4. Subject: Re: xdb accessing 'opaque' data structures
  5. Message-ID: <Bxz22G.5rx@watserv2.uwaterloo.ca>
  6. Sender: news@watserv2.uwaterloo.ca
  7. Organization: University of Waterloo
  8. References: <Bxx17C.7KF@watserv2.uwaterloo.ca> <BxxA12.LBA@fc.sde.hp.com>
  9. Date: Thu, 19 Nov 1992 16:35:03 GMT
  10. Lines: 132
  11.  
  12. In article <BxxA12.LBA@fc.sde.hp.com> bruno@fc.hp.com (Bruno Melli) writes:
  13. >> So the debugger know what _MyWidgetRec structure looks like, it just
  14. >> can't figure out that typedef MyWidget.  It all very strange to me.
  15. >
  16. >This is how it is supposed to work:
  17. >
  18. >You have something like this in one file:
  19. >
  20. >struct foo *p;
  21. >
  22. >The compiler puts out debug info to the effect that p is a pointer
  23. >to a struct foo. We don't know what foo is yet, so the compiler emits
  24. >debug info for a "dummy" structure called foo.
  25. >
  26. >In another file, you define foo:
  27. >
  28. >struct foo { whatever..... };
  29. >
  30. >At link time, /usr/bin/pxdb is supposed to redirect the pointer
  31. >in the debug info for p from the dummy structure foo to the real
  32. >structure foo.
  33. >
  34. >Now the problem: 
  35. >
  36. >There used to be a bug in the debug info generated by the
  37. >C compiler. Instead of calling the dummy structure "foo", the compiler
  38. >would call it <<NULL SYMBOL>> (or something like that).
  39. >With this, pxdb had no way of fixing the debug info for p as the matching
  40. >was done on a string compare basis.
  41. >
  42. >My guess is that your program knows what the _MyWidgetRec in some
  43. >modules, but that in the module where you use p, the type is still 
  44. >opaque...
  45. >A potential workaround if that's the case is to include a definition for
  46. >_MyWidgetRec in the module where p is declared...
  47.  
  48. Well, its a little more bizarre than that.  To illistrate consider the
  49. following example.  Suppose we create the file debugP.h which contains:
  50.  
  51.  
  52. struct _MyStruct
  53. {
  54.  int v1;
  55.  int v2;
  56. } MyStruct;
  57.  
  58. Next a file called debug.h:
  59.  
  60. typedef struct _MyStruct *MyStructPtr;
  61.  
  62. finally, two files which call these.  First debug.c
  63.  
  64. #include <stdio.h>
  65. #include "debug.h"
  66.  
  67. extern MyStructPtr getit();
  68.  
  69. main()
  70.  
  71.  
  72. {
  73.  MyStructPtr valptr;
  74.  
  75.  valptr = getit();
  76.  doit(valptr);
  77. }
  78.  
  79. and the file debug1.c
  80.  
  81. #include <stdio.h>
  82. #include "debugP.h"
  83. #include "debug.h"
  84.  
  85. MyStructPtr getit()
  86.  
  87. {
  88.  MyStructPtr temp = (MyStructPtr) malloc(sizeof(MyStruct));
  89.  return(temp);
  90. }
  91.  
  92. doit(valptr)
  93.  
  94. MyStructPtr valptr;
  95.  
  96.  
  97. {
  98.  valptr->v2=1;
  99. }
  100.  
  101. now, compile with cc -g -o debug debug.c debug1.c.  Go into the debugger and
  102. put a break point in the getit() function.  Start the program and try to
  103. print out the contexts of temp.  On a 700 (HPUX 8.07) it will return a
  104. null symbol.  But, the structure was defined within the module, it should
  105. now.  Now, add the line #include "debugP.h" to debug.c and recompile.  Put
  106. the same breakpoint and now you will be able to print out the context of
  107. temp.  Now, temp is completely defined in debug1.c and should be isolated
  108. from what goes on in the file debug.c.  I am not even trying to debug a
  109. routine in debug.c
  110.  
  111. As a last test (just to add some spice) go back to the original debug.c code
  112. and compile with:
  113.  
  114. cc -g -o debug debug1.c debug.c
  115.  
  116. ie. change the order of the compiling.
  117.  
  118. You will now be able to print out the values of temp.  In fact, we can even
  119. print out the fields of valptr in the mainline despite the fact the structure
  120. is hidden from it.  So, the lesson we have learned is that you don't have
  121. to define the structure in the module you are debugging but that the
  122. structure can't be hidden from the first structure you link.
  123.  
  124. Given this, I would say the easier work around is to write a dummy file
  125. which includes all the private widget header files and defines one instance
  126. of each.  When debugging, you simply link this in first and everything should
  127. work as planned.  I think that is easier than putting
  128.  
  129. #ifdef DEBUG
  130. #include <CoreP.h>
  131. #endif
  132.  
  133. everywhere.
  134.  
  135. I don't know though, I still think its a bug...
  136.  
  137. Gordon
  138. >
  139. >bruno.
  140. >
  141. >
  142.  
  143.  
  144.