home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / linux / 23142 < prev    next >
Encoding:
Text File  |  1993-01-07  |  3.7 KB  |  81 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!uunet.ca!xenitec!mongrel!shrdlu!gdm
  3. From: gdm@shrdlu.kwnet.on.ca (Giles D Malet)
  4. Subject: Re: [BUG?] Why does gdb affect the behaviour of many errors?
  5. References: <JRS.93Jan4201620@lepton.world.std.com> <1993Jan5.051110.6558@monu6.cc.monash.edu.au> <1993Jan5.083646.16917@serval.net.wsu.edu>
  6. Organization: 3.141592653589793238462643383279502884197169399
  7. Date: Thu, 7 Jan 1993 17:26:22 GMT
  8. Message-ID: <C0Hv3y.u19@shrdlu.kwnet.on.ca>
  9. Lines: 70
  10.  
  11. >ashtray@yoyo.cc.monash.edu.au (John Newnham) writes:
  12. >>But surely an error should (generally, races excluded)
  13. >>occur wether the process is running under a debugger or normally?
  14.  
  15. hlu@luke.eecs.wsu.edu (H.J. Lu) writes:
  16. >If you got the answer, please let me know. I had an X11 program of
  17. >several thousand lines in C++, which was running fine on decstation.
  18. >But on AT&T UNIX SVR3.2.2/386, it core-dumped. If I compiled it
  19. >with -g, it ran ok. It drove me crazy.
  20.  
  21. The key is the -g option. As you well know, the program is thus complied
  22. to include all kinds of info, such as variable names, line numbers,
  23. etc etc, so that gdb can make it's displays luverly.
  24.  
  25. Say your problem is a daft pointer. Without the `-g' option, referencing
  26. this pointer for a write could be destroying something important, such
  27. as another pointer. When that second pointer is used, it now points to
  28. code space or whatever, and causes a dump.
  29.  
  30. So, you do a -g. Now your daft pointer could well point to something
  31. completely different, as the data area has been all shuffled around.
  32. Perhaps it points into the space of a variable you have already used (in
  33. initialisation ?) and will not use again, so clobbering it has no effect.
  34. The program may now work perfectly because your pointer may be used in
  35. something like `if ( *p != NULL )', and as it happens *p does not equal
  36. NULL at that moment...
  37.  
  38. Of course the reverse can happen - you hit a problem at point X in your
  39. program, then compile with -g, run gdb and suddenly hit a problem at
  40. point A, long before getting anywhere near X :-)
  41.  
  42. So - when you finish your testing, do a final compile without -g,
  43. and with -s, *and do another test run*, unless you want to embarrass
  44. yourself later.
  45.  
  46. Hope that helps.
  47.  
  48. BTW, this sort of problem can occur in many ways - changing the length
  49. of a (writable) string could cause a program to crash in a seemingly
  50. completely unrelated place. (Thinks...) Say this string is finished
  51. with, and your stray pointer is harmlessly destroying the end of it.
  52. No problem. You then shorten the string, and just following it is the
  53. storage space for another pointer....
  54.  
  55. Now don't you wish you had become a lumberjack ?
  56.  
  57. PREACH WARNING : This is why I am so against everyone so gaily compiling
  58. with the -fwritable_strings option when it is in fact so rarely needed.
  59. You are often just hiding bugs that will jump up and bite you in the
  60. arse later when you least expect it.
  61. The above error will be caught immediately without -fwrite...,
  62. but be hidden by it. This is of course the whole purpose of non-writable
  63. segments...
  64.  
  65. I have compiled almost every program on my system, including smail,
  66. uucp, elm, c-news, some GNU stuff, inet stuff etc. Pretty well everything
  67. except most of the `standard' stuff in /bin & /usr/bin that is found on
  68. a root diskette. The *only* program that needed -fwritable-strings was
  69. `fmt', a formatting program from the net that is more powerfull than
  70. the usual one (it handles >lines) - it had a `char *p="something"' or
  71. whatever it was in it, which I changed to something more respectable.
  72. So now not one program on this machine needs -f666.
  73.  
  74. I don't run X.
  75.  
  76. Bye ! :-)
  77.  
  78. -- 
  79. Giles D Malet                                             gdm@shrdlu.kwnet.on.ca
  80. Waterloo, Ont, Canada       +1 519 725 5726       gdmalet@descartes.uwaterloo.ca
  81.