home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / err87_13.zip / ERROR87.DOC < prev    next >
Text File  |  1993-01-24  |  7KB  |  155 lines

  1. ERROR87 1.3 - Turbo Pascal units to improve coprocessor error reports.
  2.  
  3. Copyright (c) 1990,1993, D.J. Murdoch.  All rights reserved.
  4.  
  5. Portions of DECODE87.PAS copyright 1985,86, L. David Baldwin.
  6.  
  7. INTRODUCTION
  8.  
  9. Turbo Pascal doesn't handle floating point errors well.  The number of
  10. errors that are reported as run-time "Error 207" is large, and in some
  11. versions the error address is miscalculated, so you don't have a clue
  12. where to look for them. ERROR87 is a unit that attempts to address both
  13. of these problems - it gives more informative error messages, and it
  14. tries to improve on the calculation of the error address.
  15.  
  16. METHOD
  17.  
  18. The ERROR87 unit doesn't interface anything.  When you use it, it
  19. patches the loaded copy of the system library, and installs an exit
  20. procedure that looks for run-time coprocessor errors.  (It does the
  21. patch in memory; it won't affect the copy of the library that's on
  22. disk, or the executable file on disk.)
  23.  
  24. When an error occurs, transfer is passed to the ERROR87 exit
  25. procedure.  If the error was an "Invalid Floating Point Operation",
  26. i.e. run-time error 207, ERROR87 springs into action.  First, it saves
  27. the state of the coprocessor in memory.  (The patch to the system
  28. library was to prevent it from clearing the coprocessor's registers
  29. before ERROR87 could get a look at them.)  Then, it dissects the
  30. state record to try to work out the cause of the error.
  31.  
  32. The first part of the post-mortem is to decode the instruction, using
  33. code based on L. David Baldwin's excellent UNINLINE disassembler.
  34. It then looks at the coprocessor's record of which instruction caused
  35. the error, to see if TP has given the wrong error address.  (Note:
  36. TP/BP 7.0 get the error address right, so no fix is necessary there.
  37. See the note below, though.)  Finally, it proceeds through tests of what
  38. I think are the most likely causes of invalid operations:
  39.  
  40.   - taking the square root of a negative
  41.   - dividing 0/0
  42.   - overflowing the stack by recursive calls, or very complicated
  43.     expressions
  44.   - operating on NaNs ("Not a Number"s), probably because variables
  45.     weren't properly initialized, or a library routine like ln() has
  46.     been passed a negative number
  47.   - underflowing the stack, by a bug in assembler or inline code
  48.  
  49. It prints a message describing the error, and passes control on to the
  50. next exit procedure.
  51.  
  52.  
  53. LIMITATIONS
  54.  
  55. ERROR87 adds several kilobytes to the size of the program, and writes
  56. messages to the standard output device, so you would probably only
  57. want to use it while debugging.
  58.  
  59. TP calculates the trunc() function in a funny way.  ERROR87 will often
  60. be unable to recognize the error if the truncation overflows.
  61.  
  62. The coprocessor doesn't know the code segment of an instruction, only
  63. the linear address.  (The emulator knows less; see below.)  ERROR87
  64. creates a segmented address from this in versions 5.5 and 6.0; TP/BP 7
  65. automatically returns a correct normalized address, so ERROR87 doesn't
  66. touch it. However, none of the IDE versions know how to deal with the
  67. error address when the segment is wrong.  If you have the TP/BP 7
  68. command line compiler, you can use the "/F xxxx:yyyy" option to find the
  69. error.  In earlier versions, you'll have to generate a .MAP file, figure
  70. out which segment the address is in, and manually adjust the value for
  71. TP.  For example, if the program dies with the messages
  72.  
  73.  Operand is not a number!
  74.  Runtime error 207 at 0000:46E3.
  75.  
  76. and TP can't find location 0000:46E3, take a look at the link map:
  77.  
  78.  Start  Stop   Length Name               Class
  79.  
  80.  00000H 0008CH 0008DH TEST               CODE
  81.  00090H 00ABEH 00A2FH ERROR87            CODE
  82.  00AC0H 0135FH 008A0H DECODE87           CODE
  83.  01360H 04927H 035C8H SYSTEM             CODE   <--- it's in here!
  84.  04930H 073B9H 02A8AH DATA               DATA
  85.  073C0H 0B3BFH 04000H STACK              STACK
  86.  0B3C0H 0B3C0H 00000H HEAP               HEAP
  87.  
  88. From this map it's clear that one of the system routines had the
  89. error, and there's not much you can do to find it.  (This example
  90. tried to calculate ln(-1).)  If it had turned out to be in one of your
  91. units, you could ask the compiler to find it by looking for the
  92. address 0136:3383, i.e. (start div $10):(reported address - start).
  93.  
  94. The coprocessor emulator keeps no record of the bad instruction at all.
  95. When run under an emulator, Error87 tries to find the instruction based
  96. on the error address passed to it, but is not always successful.
  97.  
  98. I've attempted to add protected mode (DPMI) support for BP 7, but it
  99. doesn't seem at all reliable.  I don't know if this is caused by bugs
  100. in BP or in Error87.  Under Desqview it's even worse.
  101.  
  102. CONTENTS OF PACKAGE
  103.  
  104. In this package, you should find the following files:
  105.  
  106.  ERROR87.DOC  - this file
  107.  ERROR87.PAS  - source code to the error handling unit
  108.  DECODE87.PAS - source code used to decode the instructions
  109.  DV87.ZIP     - a little TSR to fix a bug in Desqview 2.26 that
  110.                 crashes windows on coprocessor errors
  111.  NMI.ZIP      - a little program to turn on NMI handling on XT clones,
  112.                 so that they don't crash on coprocessor errors
  113.  
  114.  
  115. REGISTRATION
  116.  
  117. ERROR87 is shareware.  That means you can try it out for free, but if
  118. you find that it helps you and you want to keep it, you must register.
  119. Registration is only $10; send a cheque or money order for that amount
  120. in Canadian or U.S. funds to
  121.  
  122.  D.J. Murdoch
  123.  337 Willingdon Ave.
  124.  Kingston, Ontario, Canada,
  125.  K7L 4J7.
  126.  
  127. I'll answer technical questions from registered users, if they're
  128. mailed to me at the above address, or by email to me at
  129.  
  130.  dmurdoch@mast.queensu.ca on Internet
  131.  DJ Murdoch at node 1:249/99.5 on Fidonet
  132.  71631,122 on Compuserve
  133.  
  134. I'd like bug reports from you even if you don't register.
  135.  
  136. The unit DECODE87 is closely based on L. David Baldwin's UNINLINE
  137. program.  I release my contributions to it to the public domain, but
  138. the actual decoding remains under his copyright.  He has released it
  139. for free non-commercial use.
  140.  
  141. RELEASE HISTORY
  142.  
  143. 1.3 - January 1993 - Updated to work with TP/BP 7, including protected mode.
  144.                     Improved the emulator handling marginally.
  145.  
  146. 1.2 - February 1991 - Added check for emulator and warning message.  The
  147.                     emulator in TP 6.0 (and possibly 5.5) doesn't
  148.                     properly emulate all of the coprocessor registers,
  149.                     so Error87 messages will probably be wrong.
  150.  
  151. 1.1 - August 1990 - added detection of trunc() and round() overflows
  152.                     that I forgot in 1.0
  153.  
  154. 1.0 - August 1990 - Initial release
  155.