home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / examine.zip / EXAMINE.DOC next >
Text File  |  1989-04-22  |  20KB  |  542 lines

  1.  
  2.   EXAMINE          Assembly Level Examination Utility          Version 2.0
  3.  
  4.                 Copyright (c) 1989   Richard W. Prescott
  5.                           All Rights Reserved
  6.  
  7.  
  8.  All brand and product names mentioned herein are trademarks or registered 
  9.                 trademarks of their respective holders.
  10.  
  11.   ┌─────────────────────────────────────────────────────────────────────┐
  12.   │  This file contains documentation for the program file EXAMINE.EXE  │
  13.   └─────────────────────────────────────────────────────────────────────┘
  14.  
  15.  
  16. The following topics are described below:
  17.  
  18. 1. Overview
  19. 2. Command line options
  20. 3. Producing a Map file
  21. 4. Behind EXAMINE.EXE
  22. 5. System Requirements
  23. 6. DISCLAIMER
  24. 7. Purchase Information
  25. 8. TP&Asm/TP&Asm-M
  26.  
  27.  
  28.  
  29.  
  30. 1. Overview
  31.  
  32. EXAMINE.EXE is a utility program which can be used to display the 
  33. assembly level implementation for each line of any source files 
  34. compiled with Turbo Pascal version 4.0 or 5.0.  You must compile to 
  35. disk, and you must instruct the compiler to create a map file with 
  36. line number detail, as explained below.  
  37.  
  38. The default presentation is to the screen, however output may be
  39. redirected to the printer (>PRN) or to a file (>filename.ext).
  40.  
  41. The following presents a section of EXAMINE output:
  42.  
  43.  
  44. ----
  45.   m := 0;                                          ─── Source Line
  46.                                                    ┐   
  47. 4FB0:0075 31C0          XOR     AX,AX              ├── Corresponding
  48. 4FB0:0077 8946BA        MOV     [BP-46],AX         ┘    disassembly
  49. ----                                            
  50.   FOR n := 0 TO SearchLimit DO BEGIN               ─── Source Line
  51.                                                    ┐
  52. 4FB0:007A 8B4608        MOV     AX,[BP+08]         │
  53. 4FB0:007D 8946B8        MOV     [BP-48],AX         │
  54. 4FB0:0080 31C0          XOR     AX,AX              │   Corresponding
  55. 4FB0:0082 3B46B8        CMP     AX,[BP-48]         ├──   DEBUG.COM 
  56. 4FB0:0085 7F5B          JG      00E2               │    disassembly
  57. 4FB0:0087 8946BC        MOV     [BP-44],AX         │
  58. 4FB0:008A EB03          JMP     008F               │
  59. 4FB0:008C FF46BC        INC     WORD PTR [BP-44]   ┘
  60. ----
  61.     IF FindArray[n] = FindStr[1] THEN BEGIN        ─── Source Line
  62.                                                    ┐
  63. 4FB0:008F 8B46BC        MOV     AX,[BP-44]         │
  64. 4FB0:0092 C47E0A        LES     DI,[BP+0A]         │   Corresponding
  65. 4FB0:0095 03F8          ADD     DI,AX              ├──   DEBUG.COM 
  66. 4FB0:0097 26            ES:                        │    disassembly
  67. 4FB0:0098 8A05          MOV     AL,[DI]            │
  68. 4FB0:009A 3A46BF        CMP     AL,[BP-41]         │
  69. 4FB0:009D 753B          JNZ     00DA               ┘
  70. ----
  71.  
  72.  
  73.  
  74. EXAMINE.EXE is useful in a number of situations:
  75.  
  76. To simplify the designing of external PROCs.  (For example, by 
  77. writing the PROC shell first in Pascal and using EXAMINE to 
  78. determine the parameter offsets, parameter push sequence for  
  79. procedure calls, etc).  
  80.  
  81. To verify the assembly code produced by the Integrated Compile-time 
  82. Assembler TP&Asm.  (This is the reason why Examine was written).  
  83.  
  84. To simplify converting Pascal code to assembly language for use 
  85. within TP&Asm, or with Inline or External.  
  86.  
  87. To determine which of a set of alternative Pascal statements 
  88. produces the more efficient code.  For example, consider the three
  89. alternative statements below:
  90.  
  91.        IF (Ch IN ['N','n']) THEN DummyProc;
  92.  
  93.        IF (Ch='N') OR (Ch='n') THEN DummyProc;
  94.  
  95.        CASE Ch OF 'N','n': DummyProc; END;
  96.  
  97. As determined using EXAMINE, the first statement uses 51 bytes of 
  98. code (including the 32 byte set constant), the second statement 
  99. uses 17 bytes, and the third, only 14 bytes.  In fact, a CASE 
  100. statement will always be smaller than an IN statement unless there
  101. are more than 12 distinct values or range endpoints to be checked.
  102.  
  103.  
  104.  
  105. 2. Command line options
  106.  
  107. Examine may be invoked with just a single file name, or with up to 
  108. three file names, a procedure name, and starting and ending line 
  109. numbers.  The general format for invoking examine is:
  110.  
  111. Examine SourceName ExeName MapName [ProcName StartLine EndLine]
  112.  
  113. Most of the above parameters may be omitted.  The use of brackets 
  114. '[..]' is required when specifying a Proc/Function or Line Number 
  115. limit.  Omitted parameters will assume default values as specified 
  116. below:
  117.  
  118.    Default Source path = current directory
  119.    Default Source name = 'NONAME'
  120.    Default Source ext  = 'PAS'
  121.  
  122.    Default Executable path = Source path
  123.    Default Executable name = Source name
  124.    Default Executable ext  = 'EXE'
  125.  
  126.    Default Map path = Executable path
  127.    Default Map name = Executable name
  128.    Default Map ext  = 'MAP'
  129.  
  130.    Default Start Line  = 1 
  131.    Default Ending Line = End of Source File
  132.  
  133.    If only one line number is specified, it is taken to be the starting 
  134.    line.  
  135.  
  136.  
  137. EXAMINE can be terminated at any time by pressing:
  138.    <Ctrl>-C              - or -
  139.    <Ctrl>-<Break>
  140.  
  141.  
  142. Examples
  143.  
  144. To Examine all of MYPROG.PAS with MYPROG.PAS, MYPROG.EXE, and
  145. MYPROG.MAP all in the current directory:
  146.  
  147.   Examine myprog
  148.  
  149. If all three files are in the directory C:\PASFILES:
  150.  
  151.   Examine c:\pasfiles\myprog
  152.  
  153. To limit Examine to the procedure FIRSTPROC:
  154.  
  155.   Examine myprog [firstproc]
  156.  
  157. To limit Examine to a specific range of lines
  158.  
  159.   Examine myprog [56 185]
  160.  
  161. To limit Examine to a range of lines within FIRSTPROC:
  162.  
  163.   Examine myprog [firstproc 56 185]
  164.  
  165.  
  166. Examine was designed to handle Units.  Do not attempt to Examine a 
  167. TPU file, however.  Rather, a Unit may be specified as the source 
  168. file when examining an executable file which Uses that Unit:
  169.  
  170. If MyProg uses a unit MyUnit,
  171.  
  172.   Examine myunit myprog
  173.  
  174.  
  175. Units which are overlaid ( eg, {$O OvrUnit} ) in the main program
  176. cannot be processed by EXAMINE.  The executable code for such Units
  177. is stored separately and loaded by the overlay manager during program 
  178. execution, and not loaded by DOS or DEBUG at program startup.  As a
  179. result, the overlay unit code is simply not present during execution 
  180. of EXAMINE.
  181.  
  182. The simplest way to EXAMINE an overlayable Unit is to create a short
  183. program file which uses the unit in a non-overlaid fashion:
  184.  
  185.  Program NotOvr;
  186.  Uses OvrUnit; 
  187.  (** OvrUnit was compiled {O+} but will not be overlaid here **)
  188.  
  189.  VAR DummyPtr: POINTER;
  190.  BEGIN
  191.    DummyPtr := @Function1;  {- Force Link Function1  of OvrUnit -}
  192.    DummyPtr := @Procedure1; {- Force Link Procedure1 of OvrUnit -}
  193.    DummyPtr := @Procedure2; {- Force Link Procedure2 of OvrUnit -}
  194.     : <etc>
  195.  END.
  196.  
  197.  
  198.  Then Compile:   TPC NotOvr /gd          <-- using TPC version 5.0
  199.   And Examine:   EXAMINE OvrUnit NotOvr
  200.  
  201. Since "{$O OvrUnit}" is not specified, the OvrUnit Unit code will be 
  202. contained in the EXE file NOTOVR.EXE and will then be available to 
  203. EXAMINE.
  204.  
  205.  
  206.  
  207. Examine was not intended to handle include files, however the 
  208. only real limitation is the following:  If a source file contains 
  209. executable code both before and after an include directive, then 
  210. the line number table for that source file will be split into two 
  211. pieces, and only the first piece can be examined.  The included file 
  212. (eg INCLUDE.PAS) may be examined by specifying it as the source 
  213. file: 
  214.  
  215.   Examine include myprog
  216.  
  217.  
  218.  
  219. Using Output Redirection:
  220.  
  221. The LAST parameter specified on the command line may be a "greater 
  222. than" symbol > , followed by "PRN" or the name of a file.  This 
  223. instructs the operating system to redirect standard output from the 
  224. screen to the printer (PRN) or the named file.  EXAMINE.EXE fully 
  225. supports output redirection.
  226.  
  227. To Examine MYPROG.PAS with output sent to the printer: 
  228.  
  229.   Examine myprog >PRN
  230.  
  231. To Examine a range of lines within the Unit MyUnit, with output 
  232. saved in the file MYUNIT.XMN:
  233.  
  234.   Examine myunit myprog [56 185] >myunit.xmn
  235.  
  236.  
  237. EXAMINE detects output redirection and provides an on-screen status 
  238. report of progress through the executable file.  
  239.  
  240. The short batch file XM.BAT is provided to simplify the process of
  241. redirecting output to a disk file.  Command line parameters for XM 
  242. are the same as for EXAMINE, with the exception that the SourceName
  243. parameter for XM must omit the extension ".PAS".  The last example 
  244. above can be accomplished more simply using XM:
  245.  
  246.   XM myunit myprog [56 185]
  247.  
  248.  
  249. Please refer to your MS-DOS/PC-DOS Manual for further information on 
  250. the use of Output Redirection.
  251.  
  252.  
  253.  
  254.  
  255. 3. Producing a Map file
  256.  
  257. To produce a map file using the Turbo Version 5.0 Integrated 
  258. Development Environment: 
  259.  
  260. Be sure all units you may wish to examine are compiled in the 
  261. (default) {$D+} state.  Then set 
  262.            Options/Linker/Map file/Detailed 
  263. and compile the program file to disk.
  264.  
  265.  
  266. To produce a map file using TPC Version 5.0:
  267.  
  268. Be sure all units you may wish to examine are compiled in the 
  269. (default) {$D+} state.  Then compile with the command line option 
  270. "/gd":
  271.  
  272.   tpc myprog /gd
  273.  
  274.  
  275. To produce a map file using the Turbo Version 4.0 Integrated 
  276. Development Environment: 
  277.  
  278. Be sure all units you may wish to examine are compiled in the 
  279. (default) {$D+} state.  Then set 
  280.    Options/Compiler/Turbo pascal map file generation ... On
  281. and compile the program file to disk.  This will produce an EXE and 
  282. a TPM file.  Then use TPMAP to produce the final Map file from 
  283. myprog.tpm:
  284.  
  285.   tpmap myprog
  286.  
  287.  
  288. To produce a map file using TPC Version 4.0:
  289.  
  290. Be sure all units you may wish to examine are compiled in the 
  291. (default) {$D+} state.  Compile with the command line option "/$T+", 
  292. and then use TPMAP to produce the final Map file:
  293.  
  294.   tpc myprog /$T+
  295.   tpmap myprog
  296.  
  297.  
  298.  
  299.  
  300. 4. Behind EXAMINE.EXE
  301.  
  302. EXAMINE produces its disassembly by running DEBUG.COM from your DOS 
  303. disk as a "child process" and requesting disassembly of the required 
  304. sections via the DEBUG unassemble command "-u".  The advantage of 
  305. using DEBUG.COM rather than an internally written disassembler is 
  306. that the disassembly generated is then essentially guaranteed to be 
  307. reliable.  Users who feel comfortable with the reliability of 
  308. DEBUG.COM can be equally confident in the disassembly produced by 
  309. EXAMINE.  
  310.  
  311. In addition, this technique illustrates how to create a useful 
  312. utility from an existing program without having to "reinvent the 
  313. wheel" (or rewrite the disassembler).  
  314.  
  315. The following description provides an overview of how EXAMINE 
  316. operates:
  317.  
  318.   1. EXAMINE first verifies that it can find the Source, MAP, 
  319.      and Executable files and checks the dates of these files.
  320.      If the Source date is later than the Executable file date,
  321.      or if the MAP and Executable file dates differ by more than 
  322.      8 seconds, the user is asked to confirm before continuing.
  323.  
  324.   2. The MAP file is then read and processed.  The Line Number
  325.      Table for the specified source file is stored in compressed 
  326.      form, 4 bytes per Line Number entry.
  327.  
  328.   3. The Source file is then read and stored immediately following 
  329.      the compressed Line Number Table.
  330.  
  331.      EXAMINE uses DOS Memory Allocation techniques rather than 
  332.      using the Turbo heap to allocate space for the MAP and Source 
  333.      files.  This permits memory not required by these files to be 
  334.      reclaimed for use by DEBUG.COM and the Executable file.  (In 
  335.      contrast, the full amount "heapmax" as specified in the {$M }
  336.      compiler directive is reserved by the Turbo program and is not
  337.      available for use by a program under "Exec").
  338.  
  339.   4. EXAMINE installs a new interrupt $21 handler which replaces 
  340.      the DOS Buffered Input Function 0Ah.  EXAMINE also monitors 
  341.      Function $30 (Get DOS Version) and the undocumented Function 
  342.      $50 (Set PSP) used by DEBUG.COM.  All other function requests 
  343.      are passed directly to the original interrupt $21 handler.  
  344.  
  345.   5. EXAMINE Executes DEBUG.COM with the Executable file specified
  346.      as a command line parameter.  DEBUG loads into memory, loads 
  347.      the Executable file, and then waits for input via the DOS 
  348.      Buffered Input Function 0Ah.  
  349.  
  350.   6. Each time EXAMINE's Function 0Ah handler receives a request 
  351.      for input, it
  352.       1) Writes a source line or series of source lines (as 
  353.          indicated by the MAP file Line Number Table) to the 
  354.          standard output device.
  355.       2) Returns to DEBUG.COM with an unassemble command which
  356.          instructs DEBUG to display (to the standard output device)
  357.          the disassembly of the source line(s) just displayed.
  358.  
  359.   7. The process in (6.) repeats until EXAMINE instructs DEBUG to
  360.      display the disassembly of the final source line requested.
  361.      On the NEXT Function 0Ah input request, EXAMINE instructs 
  362.      DEBUG.COM to exit with a quit "-q" request, and the EXEC 
  363.      process terminates.
  364.  
  365.   8. On return from the EXEC process, EXAMINE restores the original
  366.      interrupt $21 handler, and exits to DOS.
  367.  
  368.  
  369.  
  370.  
  371. 5. System Requirements
  372.  
  373. Examine Version 2.0 requires: DEBUG.COM running on an IBM PC or 
  374. Compatible, with Version 2.0 or above of MS-DOS or PC-DOS.  
  375. Minimum memory requirements are 128K plus memory required by the 
  376. executable program being examined.
  377.  
  378.  
  379. Limitations and other notes:
  380.  
  381. Source and Map files are limited to 64K bytes.  Executable file size 
  382. is not limited, but must be small enough to load into memory after 
  383. Examine's minimum memory requirement of 128K.
  384.  
  385. If Examine cannot find one of the files you specify, it will report 
  386. the full path specification it was using for the file it failed to 
  387. find.
  388.  
  389. If Examine encounters an error with the Map file, it will tell you.  
  390. Make sure the file you specify is an UNMODIFIED Map file, with full 
  391. line number detail, produced by Turbo/TPC Version 5.0 or by TPMAP 
  392. Version 4.0.
  393.  
  394. Examine attempts to recognize string, set, and range constants and 
  395. display them in a readable DB format, for example:
  396.                        DB 11,'Hello World'
  397. If Examine fails to recognize a group of such constants, the fallback 
  398. presentation uses the standard DEBUG.COM disassembly.
  399.  
  400. Examine will attempt to exit gracefully when it detects the output
  401. disk becoming full (under output redirection).  If it detects fewer
  402. than 5 free "clusters" (approximately 4K free on a floppy), it will
  403. exit with the message "Insufficient space on output disk".  Replace
  404. or otherwise correct the disk problem, and re-execute Examine.
  405.  
  406.  
  407.  
  408.  
  409. 6. DISCLAIMER OF WARRANTY 
  410.  
  411. This software and accompanying documentation are sold "as is" and 
  412. without warranties as to performance or merchantability.  
  413.  
  414. This program is sold without any express or implied warranties 
  415. whatsoever.  Because of the diversity of conditions and hardware 
  416. under which this program may be used, no warranty of fitness for a 
  417. particular purpose is offered.  The user is advised to test the 
  418. program thoroughly before relying on it.  THE USER MUST ASSUME THE 
  419. ENTIRE RISK OF USING THE PROGRAM.  ANY LIABILITY OF THE AUTHOR WILL 
  420. BE LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF THE 
  421. PURCHASE PRICE.  
  422.  
  423.  
  424.  
  425.  
  426. 7. Purchase Information.
  427.  
  428. Note: Registered users of TP&Asm (described below) are automatically 
  429. registered users of EXAMINE.  The EXAMINE.EXE program file and source
  430. code is included on registration and update disks for TP&Asm Version 
  431. 2.0.  
  432.  
  433. The EXAMINE package is distributed as shareware.  After you have 
  434. reviewed the package for a reasonable period of time (say, 30 days), 
  435. please register it or purchase TP&Asm if you plan to continue using 
  436. it.  As a benefit of registration, you can receive full source code 
  437. for the program file EXAMINE.EXE, as indicated below.
  438.  
  439. Even if you choose not to register, I encourage you to retain a copy 
  440. of EXAMINE and distribute it to others via BBS or on diskette.  
  441. Please include all files in the distribution package.  
  442.  
  443. The following price list applies to registration of EXAMINE and 
  444. purchase of TP&Asm.  Users who choose to register EXAMINE with the 
  445. "registration + disk" option will receive the most recent version,
  446. including source code.  Users who register EXAMINE with the 
  447. "registration only" option do not receive source code but may elect 
  448. to do so at a later date by sending the additional $3 P&H.  
  449.  
  450.  
  451. EXAMINE Registration   ... $15 + $3 P&H for registration + disk
  452.                            $15  (total) for registration only
  453.  
  454. TP&Asm Version 2.0     ... $49 + $3 P&H 
  455.  
  456.  
  457. (Wisconsin residents, please add 5% sales tax).
  458.  
  459. All prices listed are for standard 5 1/4 inch floppy disks.  Add
  460. $2 for distribution on 3 1/2 inch disks.
  461.  
  462.  
  463. Please send a check or money order payable to:
  464.  
  465.                       Richard W. Prescott
  466.                       724 Sauk Ridge Trail
  467.                       Madison, WI  53705
  468.  
  469.  
  470. When purchasing TP&Asm, please include the following information:
  471.  
  472.   1. Full Version number of the Turbo Pascal compiler you now use.
  473.  
  474.   2. Your registration number for that compiler.
  475.  
  476.   3. If you obtained TP&Asm-M from a bulletin board:
  477.      3a. Name, area code and phone number of that bulletin board
  478.      3b. Full Version number of the TP&Asm-M version you have
  479.      3c. Directory Date of the README file
  480.  
  481.  
  482.  
  483.  
  484. 8. TP&Asm/TP&Asm-M
  485.  
  486. TP&Asm is a small assembler which runs Turbo 4.0/5.0 (Integrated
  487. Environment or TPC) as a subprocess and permits you to place 
  488. assembly language statements directly into your Pascal source code 
  489. in blocks beginning with the keywords "Assemble" and/or "Internal".  
  490.  
  491. TP&Asm provides the convenience and flexibility of having "live" 
  492. assembly language in your programs which can be modified and 
  493. immediately recompiled with no need to exit and reassemble.  You 
  494. have complete freedom to place assembly language anywhere in your 
  495. program, freely mix Pascal and assembly blocks, freely transfer 
  496. between Pascal and assembly blocks via Call/Jump/Loop/Goto to any 
  497. Pascal or assembly label, make direct Call, Jmp and Offset 
  498. references to Pascal Proc/Functions, and make simplified Pascal 
  499. style references to your Pascal and assembly variables and 
  500. parameters.  Units compiled with TP&Asm can be distributed and 
  501. Used independent of TP&Asm.  
  502.  
  503. The resulting ASSEMBLY Development Environment is identical to your 
  504. PASCAL Development Environment.  It provides fast assembly with no 
  505. additional disk access, and reports assembly syntax errors on the 
  506. standard Turbo error line with cursor placed on the error.  It 
  507. accepts the standard syntax of both MASM and A86, but also provides 
  508. certain enhancements such as the placement of named data in the 
  509. Code Segment.  
  510.  
  511. With Turbo Version 5.0, you can trace your assembly code line by 
  512. line in the IDE.  Using the record variable CPU defined in the unit 
  513. ASMWATCH (included), you can Watch, Evaluate, and Modify the CPU 
  514. registers and flags during the trace.  
  515.  
  516. TP&Asm can be purchased as described in the preceding section.
  517.  
  518. A shareable Memory Mode version called TP&Asm-M is also available.  
  519. The distinction between TP&Asm and TP&Asm-M is that TP&Asm-M is 
  520. intended for developing and debugging assembly language in the IDE, 
  521. but not for final compilation.  You can compile to Memory (with the 
  522. standard Turbo style interactive syntax error detection) and Trace 
  523. your assembly code in the IDE with full capability to Watch, 
  524. Evaluate, and Modify the CPU registers and Flags - then convert to 
  525. INLINE or EXTERNAL after the code is fully developed.  TP&Asm-M's 
  526. INTERNAL statement and its support of the standard syntax of MASM, 
  527. A86, and INLINE.COM simplifies this conversion.  
  528.  
  529. The TP&Asm-M distribution disk can be ordered from me for $5 plus 
  530. $3 P&H, with the $5 being credited toward subsequent registration 
  531. of TP&Asm or TP&Asm-M.  It can also be downloaded from the IBMPRO 
  532. or BPROGA forums on CompUServe.  Look for the archives TP-ASM and 
  533. TPA2-R ( May be ".ARC" or ".ZIP" ).  Registration for TP&Asm-M is 
  534. $19.
  535.  
  536.  
  537.  
  538.  
  539.  
  540. EXAMINE.EXE was compiled and assembled using TP&Asm Version 2.0 
  541. running Turbo Pascal Version 5.0.  
  542.