home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gdb / bug / 899 < prev    next >
Encoding:
Text File  |  1992-07-25  |  4.6 KB  |  199 lines

  1. Newsgroups: gnu.gdb.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!foxtrot.ccmrc.ucsb.edu!doug
  3. From: doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott)
  4. Subject: gdb 4.6 bug report
  5. Message-ID: <9207242135.AA20290@foxtrot.ccmrc.ucsb.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Fri, 24 Jul 1992 21:35:21 GMT
  10. Approved: bug-gdb@prep.ai.mit.edu
  11. Lines: 186
  12.  
  13. System:  Sun 4/440 running OS 4.1
  14. Compiler:  g++ 2.2.2
  15. Gdb version: 4.6, compiled with g++ bug fix flag
  16. Description of problem:
  17. When tracing program execution of assignment operators
  18. in the Complex class, I discovered that gdb incorrectly
  19. determines the value of 'this' when descending into
  20. assignment operator = (Complex &) in cases where the
  21. class instance is globally or locally static. 
  22.  
  23.  
  24. Comments start with "[NOTE: ".
  25.  
  26. tango> gdb a.out
  27. GDB is free software and you are welcome to distribute copies of it
  28.  under certain conditions; type "show copying" to see the conditions.
  29. There is absolutely no warranty for GDB; type "show warranty" for details.
  30. GDB 4.6, Copyright 1992 Free Software Foundation, Inc...
  31. (gdb) break main
  32. Breakpoint 1 at 0x22f0: file ggg.c, line 9.
  33. (gdb) run
  34. Starting program: /home/doug/C++/a.out 
  35.  
  36.  
  37. Breakpoint 1, main () at ggg.c:9
  38. 9               static Complex sc0;     // should be automatically zeroed
  39. Warning: the current language does not match this frame.
  40. (gdb) n
  41. 10              Complex c0 = 0;
  42. (gdb) 
  43.  
  44. 11              Complex c1 = 1;
  45. (gdb) 
  46.  
  47. 12              Complex c2;             // this will not be initialized
  48. (gdb) 
  49.  
  50. 14              c2 = c0;                // test assignment to local object
  51.  
  52. [NOTE: printing values before descending into operator]
  53.  
  54. (gdb) print c0
  55. $1 = {
  56.   re = 0, 
  57.  
  58.   im = 0
  59. }
  60. (gdb) print c2
  61. $2 = {
  62.   re = -1.0560207522679516e+270, 
  63.  
  64.   im = 0
  65. }
  66. (gdb) s
  67. Complex::operator= (this=0xf7fffb38, y=@0xf7fffb58) at ./Complex.h:131
  68. 131       re = y.real(); im = y.imag(); return *this; 
  69.  
  70.  
  71. (gdb) fin
  72. Run till exit from #0  Complex::operator= (this=0xf7fffb38, y=@0xf7fffb58)
  73.     at ./Complex.h:131
  74. main () at ggg.c:16
  75. 16   cout << "zero " << zero << " one " << one << " s_zero " << s_zero << "\n";
  76. Value returned is $3 = (Complex &) @0xf7fffb38: {re = 0, im = 0}
  77.  
  78. [NOTE that here (local variable), &c2 == this from above operator, as it should]
  79.  
  80. (gdb) print &c2
  81. $4 = (Complex *) 0xf7fffb38    
  82.  
  83. (gdb) n
  84. zero (0, 0) one (1, 0) s_zero (0, 0)
  85. 17 cout << "sc0 " << sc0 << " c0 " <<  c0 << " c1 " << c1 << " c2 " << c2 << "\n";
  86.  
  87. (gdb) n
  88. sc0 (0, 0) c0 (0, 0) c1 (1, 0) c2 (0, 0)
  89. 19              sc0 = c1;             // test assignment to local static object
  90.  
  91. (gdb) print sc0
  92. $5 = {
  93.   re = 0, 
  94.  
  95.   im = 0
  96. }
  97.  
  98. (gdb) print c1
  99. $6 = {
  100.   re = 1, 
  101.  
  102.   im = 0
  103. }
  104.  
  105. (gdb) print &sc0
  106. $7 = (Complex *) 0x241e0
  107.  
  108. [NOTE that in this next operator call, this != &sc0]
  109.  
  110. (gdb) s            
  111. Complex::operator= (this=0x26418, y=@0xf7fffb48) at ./Complex.h:131
  112. 131       re = y.real(); im = y.imag(); return *this; 
  113.  
  114.  
  115. (gdb) n
  116. 132     } 
  117.  
  118.  
  119. (gdb) n
  120. main () at ggg.c:21
  121. 21              cout << "now sc0 = " << sc0 << "\n";
  122.  
  123. [NOTE: that gdb still thinks sc0 is (0, 0)]
  124.  
  125. (gdb) print sc0
  126. $8 = {
  127.   re = 0, 
  128.  
  129.   im = 0
  130. }
  131.  
  132. [NOTE: but when printed, it is correctly set to (1, 0)]
  133.  
  134. (gdb) n
  135. now sc0 = (1, 0)
  136. 23              s_zero = c1;         // test assignment to global static object
  137.  
  138. [NOTE: for global static, same thing:  &s_zero != this]
  139.  
  140. (gdb) print &s_zero
  141. $9 = (Complex *) 0x241f8
  142.  
  143. (gdb) s
  144. Complex::operator= (this=0x26430, y=@0xf7fffb48) at ./Complex.h:131
  145. 131       re = y.real(); im = y.imag(); return *this; 
  146.  
  147.  
  148. (gdb) fin
  149. Run till exit from #0  Complex::operator= (this=0x26430, y=@0xf7fffb48)
  150.     at ./Complex.h:131
  151. 0x255c in main () at ggg.c:23
  152. 23              s_zero = c1;            // test assignment to global static object
  153. Value returned is $10 = (Complex &) @0x26430: {re = 1, im = 0}
  154.  
  155. [NOTE:  again, gdb thinks it is still set to (0, 0)]
  156.  
  157. (gdb) print s_zero
  158. $11 = {
  159.   re = 0, 
  160.  
  161.   im = 0
  162. }
  163. (gdb) n
  164. 24      }
  165. (gdb) cont
  166. Continuing.
  167.  
  168. Program exited normally.
  169.  
  170. Here is the program.
  171. ----------------------------------------------------------------
  172. #include <Complex.h>
  173. #include <stream.h>
  174.  
  175. static Complex zero = 0;
  176. static Complex one = 1;
  177. static Complex s_zero;        // should be automatically zeroed
  178.  
  179. main() {
  180.     static Complex sc0;    // should be automatically zeroed
  181.     Complex c0 = 0;
  182.     Complex c1 = 1;
  183.     Complex c2;        // this will not be initialized
  184.  
  185.     c2 = c0;        // test assignment to local object
  186.  
  187.     cout << "zero " << zero << " one " << one << " s_zero " << s_zero << "\n";
  188.     cout << "sc0 " << sc0 << " c0 " <<  c0 << " c1 " << c1 << " c2 " << c2 << "\n";
  189.  
  190.     sc0 = c1;        // test assignment to local static object
  191.  
  192.     cout << "now sc0 = " << sc0 << "\n";
  193.  
  194.     s_zero = c1;        // test assignment to global static object
  195.  
  196. }
  197.  
  198.  
  199.