home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / PCASM1.ZIP / DEBUGGER.DOC < prev    next >
Text File  |  1990-08-02  |  15KB  |  296 lines

  1.  
  2.  
  3.  
  4.                                                                              1
  5.  
  6.                                       DEBUGGERS
  7.  
  8.  
  9.              Debuggers are designed to take you through your program step by
  10.              step. This allows you to see which instruction is being executed
  11.              at each moment, and this in turn allows you to pinpoint the spot
  12.              where the program starts doing something you don't want it to do.
  13.              In the beginning, debuggers like DEBUG would look at each
  14.              instruction and give you the text mnemonic for that instruction.
  15.              Each individual instruction has exactly one text mnemonic.
  16.  
  17.              This was better than nothing, but it suffered from several
  18.              problems. First, it substituted the address of a variable or
  19.              subroutine for the variable or subroutine name. A name like
  20.              'result' became 0A84h, a hex number. Secondly, in a high level
  21.              language, you know what the source code looks like, but you don't
  22.              have the slightest idea what the machine code looks like, and you
  23.              don't care. It is nearly impossible to tell where you are in a
  24.              PASCAL program by looking at the machine code. You are interested
  25.              in what is happening, not in how the compiler generated
  26.              instructions for your code. 
  27.  
  28.              The general solution to these problems is a SYMBOLIC debugger.
  29.              While the compiler or assembler is generating the object file, it
  30.              keeps track of what LINE you are on in the text file. Each
  31.              instruction is indexed by the text line where it is generated.
  32.              This information is passed along to the linker, which processes
  33.              it if it is asked to do so . Here is a program which was
  34.              assembled once with the symbolic information and once without the
  35.              information:
  36.  
  37.                  MIT      OBJ     1978   7-23-90   4:31p
  38.                  OHNE     OBJ      952   7-23-90   4:31p
  39.  
  40.              MIT.OBJ has the symbolic information, OHNE.OBJ doesn't. As you
  41.              can see, this debugging information can take up as much space as
  42.              the rest of the file. 
  43.  
  44.  
  45.              When you start up the program under the debugger, the debugger
  46.              reads both the executable file and the TEXT file into memory and
  47.              displays the appropriate text line for each machine instruction.
  48.  
  49.              In order to use a symbolic debugger, you need to:
  50.  
  51.                  1) tell the compiler to generate the debugger information
  52.                  2) tell the linker to process the information
  53.                  3) leave your text files UNALTERED.
  54.  
  55.              For MASM, the instructions are:
  56.  
  57.                  1) masm  /zi  filename1 ;
  58.                  2) link  /co  filename1+... ;
  59.  
  60.  
  61.              ______________________
  62.  
  63.              The PC Assembler Tutor - Copyright (C) 1990 Chuck Nelson
  64.  
  65.  
  66.  
  67.  
  68.              Debuggers                                                       2
  69.              _________
  70.  
  71.              For TASM, the instructions are:
  72.  
  73.                  1) tasm /zi  filename1 ;
  74.                  2) tlink /v  filename1+... ;
  75.  
  76.              where the dots indicate that you may be linking more than one
  77.              file.
  78.  
  79.              It is not necessary for all the object files to have the
  80.              debugging information. The debuggers will read the text files for
  81.              those parts which have the debugging information and will
  82.              generate code like DEBUG for those parts which don't have any
  83.              information. 
  84.  
  85.              If you have a large program you probably want to concentrate on
  86.              the section that is causing the problems. You set a breakpoint
  87.              (which is a command to stop execution at a certain spot) for the
  88.              start of this section, run the program, and then single step
  89.              through the section. That one section is the only place that
  90.              needs the symbolic information. 
  91.  
  92.              Both Codeview and Turbo Debugger do much the same thing. Here is
  93.              the Turbo screen:
  94.  
  95.    *************************** TURBO SCREEN {1} ***************************
  96.      File   View   Run   Breakpoints   Data   Window   Options        READY
  97.    .Module: debugtst  File: debugtst.asm 74.................................1.
  98.    .                                                                         .
  99.    .  start: push  ds               ; set up for return   .Registers......3. .
  100.    .         sub   ax,ax                                  .  ax 5C94   .c=0. .
  101.    .         push  ax                                     .  bx 0000   .z=1. .
  102.    .                                                      .  cx 0000   .s=0. .
  103.    .         mov   ax, DATASTUFF    ; load ds             .  dx 0000   .o=0. .
  104.    .         mov   ds,ax                                  .  si 0000   .p=1. .
  105.    .                                                      .  di 0000   .a=0. .
  106.    .  outer_loop:                                         .  bp 0000   .i=1. .
  107.    .          lea     ax, multiplicand        ; load multi.  sp 09FA   .d=0. .
  108.    .          call    get_unsigned_8byte                  .  ds 4AD6   .   . .
  109.    .          call    print_unsigned_8byte                .  es 4A26   .   . .
  110.    .          call    get_unsigned            ; unsigned w.  ss 4A36   .   . .
  111.    .          mov     multiplier, ax                      .  cs 4B27   .   . .
  112.    .                                                      .  ip 0019   .   . .
  113.    .                                                      .................. .
  114.    .          lea     si, multiplicand        ; load pointers                .
  115.    ...........................................................................
  116.    .Watches.................................................................2.
  117.    .multiplier,d                  23700                                      .
  118.    .multiplicand                  qword 00000042E843515D                     .
  119.    ...........................................................................
  120.    F1-Help F2-Bkpt F3-Close F4-Here F5-Zoom F6-Next F7-Trace F8-Step F9-Run
  121.    ******************************* END TURBO *******************************
  122.  
  123.    Here's the Codeview screen:
  124.              ____________________
  125.  
  126.                 1. Turbo Debugger   Version 1.5
  127.                   Copyright (C) 1988, 1989 Borland International
  128.  
  129.  
  130.  
  131.  
  132.              Debuggers                                                       3
  133.              _________
  134.  
  135.  
  136.    ************************* CODEVIEW SCREEN {2} ***************************
  137.    .File  View  Search  Run  Watch  Options  Language  Calls  Help . 
  138.    F8=Trace F5=Go
  139.    .......................... debugtst.ASM ..................................
  140.    73:     main   proc far                                        . AX = 0000
  141.    74:                                                            . BX = 0000
  142.    75:     start: push  ds               ; set up for return      . CX = 0000
  143.    76:            sub   ax,ax                                     . DX = 0000
  144.    77:            push  ax                                        . SP = 0A00
  145.    78:                                                            . BP = 0000
  146.    79:            mov   ax, DATASTUFF    ; load ds                . SI = 0000
  147.    80:            mov   ds,ax                                     . DI = 0000
  148.    81:                                                            . DS = 44FD
  149.    82:     outer_loop:                                            . ES = 44FD
  150.    83:             lea     ax, multiplicand        ; load multipli. SS = 450D
  151.    84:             call    get_unsigned_8byte                     . CS = 4601
  152.    85:             call    print_unsigned_8byte                   . IP = 0000
  153.    86:             call    get_unsigned            ; unsigned word.
  154.    87:             mov     multiplier, ax                         .   NV UP
  155.    88:                                                            .   EI PL
  156.    89:                                                            .   NZ NA
  157.    90:             lea     si, multiplicand        ; load pointers.   PO NC
  158.    .........................................................................
  159.    Microsoft (R) CodeView (R)  Version 2.2                           
  160.    (C) Copyright Microsoft Corp. 1986-1988.  All rights reserved.    
  161.    >                                                                
  162.    ***************************** END CODEVIEW *****************************
  163.  
  164.              As you can see, they look almost the same and they operate
  165.              similarly. The Borland people (Turbo Debugger) have gone an extra
  166.              step and have made it possible to use Turbo Debugger with both
  167.              Borland and Microsoft high-level languages.
  168.  
  169.  
  170.              I/O AND ASMHELP
  171.  
  172.              All programs do output. These two debuggers deal with this by
  173.              reserving a section of video memory for the program's output. You
  174.              put output in one place in memory and the debugger puts output in
  175.              a different place. As long as things are being done in an orderly
  176.              manner, when your screen is doing output your screen is visible
  177.              and when the debugger has charge its screen is showing.
  178.  
  179.              The problem here is that your program may take only 1/100 of a
  180.              second to write to the screen. This will appear as a flash on the
  181.              screen. You won't see anything. Both debuggers allow you to
  182.              toggle back and forth between the debugger screen and your
  183.              screen. This is tedious, but it works.
  184.  
  185.              In order to alleviate the problem, ASMHELP has a timer. You
  186.              ____________________
  187.  
  188.                 2. Microsoft (R) CodeView (R)  Version 2.2       
  189.                    (C) Copyright Microsoft Corp. 1986-1988.  
  190.                    All rights reserved.    
  191.  
  192.  
  193.  
  194.  
  195.  
  196.              Debuggers                                                       4
  197.              _________
  198.  
  199.              activate the timer with:
  200.  
  201.                  mov  al, #          ; # is a number from 1 to 5
  202.                  call set_timer
  203.  
  204.              where you put a number from 1 to 5 in AL. You deactivate it with:
  205.  
  206.                  call kill_timer
  207.  
  208.              You put a number from 1 to 5 in AL before the call to
  209.              'set_timer'. This will create a 1 to 5 second delay. From that
  210.              point on, every time a print function in ASMHELP is called, it
  211.              will show the screen for the specified number of seconds. If you
  212.              put a number larger than 5 in AL:
  213.  
  214.                  mov  al, 120
  215.                  call set_timer
  216.  
  217.              ASMHELP will require you to press the ENTER key before
  218.              continuing. This allows you to view the user screen as much time
  219.              or as little time as you want.
  220.  
  221.              The idea here is for you to set the timer at the beginning of
  222.              your program. Then the rest of the program will have the extended
  223.              viewing time for the print functions.
  224.  
  225.  
  226.  
  227.              D86
  228.  
  229.              D86 is what I'd call a semi-symbolic debugger. It does not use
  230.              line information - it uses a symbol table. This is a list of
  231.              symbols in the program along with where they appear in the code.
  232.              This is much better than DEBUG but is not as valuable as using
  233.              the text files. It also means that it can't work that well with
  234.              high-level languages. Here is the D86 output from the same piece
  235.              of code:
  236.  
  237.  
  238.    *************************** D86 SCREEN {3} ***************************
  239.    START:                                B  Set permanent breakpoints
  240.    # 0000 PUSH DS                        F  Find MARKed memory bytes
  241.      0001 SUB AX,AX                      G  Go, until address(es) reached
  242.      0003 PUSH AX                        J  Jump within this code segment
  243.      0004 MOV AX,0253F                   L  List disassembly to LST file
  244.      0007 MOV DS,AX                      O  set operating system-call traps
  245.    OUTER_LOOP:                           Q  Quit debugging session
  246.      0009 MOV AX,8                       W  Write program and SYM to disk
  247.      000C CALL 0151A
  248.      000F CALL 01253                     Alt-F9    restore trashed screen
  249.      0012 CALL 069B                      Shift-F7  set MARK at CS:IP
  250.      0015 MOV MULTIPLIER,AX              Home      Jump last-trap/prog-start
  251.      0018 MOV SI,8
  252.      001B MOV BX,012
  253.              ____________________
  254.  
  255.                 3. D86  Version 3.22    (C) Copyright 1990   Eric Isaacson
  256.  
  257.  
  258.  
  259.  
  260.              Debuggers                                                       5
  261.              _________
  262.  
  263.     
  264.    AX 0929             1:
  265.    BX 001A  IP 0000    2:
  266.    CX 0000  CS 2593    3:
  267.    DX 0000  SS 249F    4:
  268.    SI 0010  DS 253F    5:
  269.    DI 0000  ES 248F    6:
  270.    BP 42D9  SP 09F2    6: 001A 06B1 F202 0015 0000 248F
  271.  
  272.    g 0015
  273.    ****************************** END D86 *******************************
  274.  
  275.              As you can see, D86 has lost some of the information, but you can
  276.              follow this as long as you have a printout of the text file at
  277.              your side. 
  278.  
  279.              D86 has some weaknesses. It makes no allowance for user output,
  280.              so all user output is either erased immediately or is mixed with
  281.              the information on the debugger screen. It has no key to let you
  282.              jump over subroutines (you either need to go through the whole
  283.              subroutine or set a breakpoint after every subroutine call).
  284.              Finally, it alters the counter which keeps track of where you are
  285.              in the program.
  286.  
  287.              When using a debugger you want to scroll through the program to
  288.              find places where you want to stop, and then set breakpoints. If
  289.              you scroll with D86, it will change the program location. If you
  290.              don't know the EXACT location where you were before you started
  291.              scrolling, you can't get back to continue debugging the program.
  292.              You need to reload the file and start over again. Think of what
  293.              this would mean if you had been working on a program for 15
  294.              minutes. Why D86 does this is completely beyond me. 
  295.  
  296.