
                            FindHit 37.4

                                  by
                            Douglas Keller

                   Copyright 1993 by Douglas Keller

                            July 1, 1993


0. Introduction
---------------

FindHit is used to find the line numbers where Enforcer and Mungwall
hits occur in C source code.  The idea for FindHit came from Doug
Walker's Hitme program.

FindHit requires AmigaDOS 2.0, v37 or greater.


1. Contents
-----------

FindHit     - FindHit v37.4.
FindHit.doc - This doc file.

FindHit.c   - Sas/C 6.3 source for FindHit.
headers.h   - System headers included by FindHit.c.
lmkfile     - Sas/C 6.3 smake makefile.

offender     - Example program that cause Enforcer and Mungwall hits.
offender.c   - Sas/C 6.3 source for offender.
offender.map - Mapfile for offender produced by slink.


2. How to use FindHit
---------------------

FindHit takes the following command line arguments:

  MAPFILE/A,OFFSET/A/M,HUNK/N,DEL=DELETEOMDFILE/S

    MAPFILE/A  - Name of the mapfile from Slink, for the program
                 that produced the hit.  The mapfile is the file Slink
                 generates when the MAP <map_file_name>,h option is used.
                 This argument is required.

    OFFSET/A/M - Offset that Enforcer or Mungwall reports that
                 caused the hit.  This value is in hexadecimal
                 with no leading $ or 0x.  Multiple offsets can
                 be specified, but at least on offset is required.

    HUNK/N     - The hunk that Enforcer or Mungwall reports that
                 caused the hit.  The hunk is not required and if
                 it is no specified the default hunk will be zero.

    DEL=DELETEOMDFILE/S - This tells FindHit to delete the Omd file
                 after it is done.  By default the Omd file is NOT
                 deleted.  If FindHit is run and it finds an Omd file
                 that is not out of date it will use the Omd file
                 without running Omd again.  The Omd file is generated
                 in t:.

Here are some examples of running FindHit:

  1> findhit offender.map 270

     Found offset 0x00000270 in "offender.c", on line 11

     Searchs offender.map for offset 270 hex in hunk 0.  The output
     shows the hit was found on line 11 of offender.c.

  1> findhit rush.map 1ac44 hunk 2 delomdfile

     Found offset 0x0001AC44 in "req_palette.c", on line 278

     Searchs rush.map for offset 1ac44 hex in hunk 2, and deletes
     the omd file after it is done.

  1> findhit magic.map 988 4ac8 857c

     Found offset 0x00000988 in "magic.c", on line 173
     Found offset 0x00004AC8 in "addgads.c", on line 470
     Found offset 0x0000857C in "cmds2.c", on line 310

     Searchs magic.map for the three offsets 988, 4ac8, and 857c.

If some of the filenames of your object files are longer then 15
characters make sure you use the FWIDTH option in Slink to increase
the length of the filename field of the mapfile.  FindHit will
automatically find the correct information even if the mapfile width's
change.


3. Using FindHit with Enforcer, Mungwall, and SegTracker
--------------------------------------------------------

For best results you should be using the latest versions of Enforcer
and Mungwall which take advantage of SegTracker.

When the included offender program is run it produces the following
hits.
 
  BYTE-WRITE to  00000000        data=61         PC: 07A11A4A
  USP:  07A0ABFC SR: 0000 SW: 0711  (U0)(-)(-)  TCB: 07B82A88
  Data: 07A0ABFC 00000002 000003ED 00000FA8 00000001 0000002B 0000003B 07B82AE4
  Addr: 079FEC2A 079E9020 079F64F9 079F64FC 079FE9E8 00000000 0780DF24 --------
  ----> 079FEC2A - "offender"  Hunk 0001 Offset 00000242
  ----> 079FE9E8 - "offender"  Hunk 0001 Offset 00000000
  Stck: 079FEC2E 0780DF24 07A1236A 00000001 079FEC2A 07A12042 0000FFFF 07B83B24
  Stck: 07B82A88 00F95106 07800810 00000000 07A0AC3C 00008011 01EE10FB 00000000
  ----> 07A11A4A - "offender"  Hunk 0000 Offset 0000028A
  ----> 079FEC2E - "offender"  Hunk 0001 Offset 00000246
  ----> 07A1236A - "offender"  Hunk 0000 Offset 00000BAA
  ----> 079FEC2A - "offender"  Hunk 0001 Offset 00000242
  ----> 07A12042 - "offender"  Hunk 0000 Offset 00000882
  Name: "New_WShell"  CLI: "offender"  Hunk 0000 Offset 0000028A
   
  BYTE-WRITE to  00000000        data=62         PC: 07A11A30
  USP:  07A0ABF4 SR: 0000 SW: 0711  (U0)(-)(-)  TCB: 07B82A88
  Data: 07A0ABFC 00000002 000003ED 00000FA8 00000001 0000002B 0000003B 07B82AE4
  Addr: 079FEC2A 079E9020 079F64F9 079F64FC 079FE9E8 00000000 0780DF24 --------
  ----> 079FEC2A - "offender"  Hunk 0001 Offset 00000242
  ----> 079FE9E8 - "offender"  Hunk 0001 Offset 00000000
  Stck: 00000000 07A11A4C 079FEC2E 0780DF24 07A1236A 00000001 079FEC2A 07A12042
  Stck: 0000FFFF 07B83B24 07B82A88 00F95106 07800810 00000000 07A0AC3C 00008011
  ----> 07A11A30 - "offender"  Hunk 0000 Offset 00000270
  ----> 07A11A4C - "offender"  Hunk 0000 Offset 0000028C
  ----> 079FEC2E - "offender"  Hunk 0001 Offset 00000246
  ----> 07A1236A - "offender"  Hunk 0000 Offset 00000BAA
  ----> 079FEC2A - "offender"  Hunk 0001 Offset 00000242
  ----> 07A12042 - "offender"  Hunk 0000 Offset 00000882
  Name: "New_WShell"  CLI: "offender"  Hunk 0000 Offset 00000270

  Mismatched FreeMem size 99!
  Original allocation: 100 bytes from A:0x7A11A58 C:0x780DF24 Task 0x7B82A88
  Testing with original size.
   
    FreeMem(0x79FE018,99) attempted by "offender" (TCB:07B82A88)
    from A:0x7A11A62 C:0x780DF24 SP:0x7A0ABF8
  APC:0x07A11A62 in seglist of "offender"   Hunk 0000 Offset 000002A2


The first hit is in hunk 0 at offset 28A, if the follow is typed:

    1> findhit offender.map 28a

       Found offset 0x0000028A in "offender.c", on line 20

This shows the hit is in offender.c on line 20.

The second hit is a little more interesting, it is in a
subroutine.  The second ----> line, which is from SegTracker, that
Enforcer reports is:

    ----> 07D20D9C - "offender"  Hunk 0000 Offset 0000028C

This is the offset in offender where the function that caused the hit
is called from.  This SegTracker information can be helpful if
Enforcer does not find the Name of the program that caused the hit.

The last hit is from Mungwall, it shows the FreeMem() that has the
problem is in hunk 0 offset 2a2.

If some of the filenames of your object files are longer then 15
characters make sure you use the FWIDTH option in Slink to increase
the length of the filename field of the mapfile.  FindHit will
automatically find the correct information even if the mapfile width's
change.


4. How FindHit Works
--------------------

FindHit search through the mapfile that Slink generates to find the
object file that has the problem.  FindHit then executes Omd on the C
source and the object file to disassemble it.  The base of the object
file, from the mapfile, plus the offset into the Omd file should equal
the offset that Enforcer or Mungwall reports.

Since Omd is used to disassemble the code, code must be compiled with
a debug level of at least DEBUG=LINE.

If the DELETEOMDFILE option is not given the Omd file is generated in
T: and is not deleted ater FindHit is done with it.  The next time
FindHit is run it checks the date of the Omd file and the object file
to see of the Omd file needs to be regenerated.  If the Omd file is
newer then the object file, FindHit uses the Omd file that it finds in
T:, else it generates the Omd file again.

If you prefer the default to delete the Omd file, the following alias
can be made:  alias FindHit "FindHit deleteomdfile".


5. About the Source
-------------------

Sas/C 6.3 source is included.  The source does not use any startup
code and there is not writable global data, so it is reentrant.


6. Legal junk
-------------

Permission is granted to distribute this program and its documentation
for non-commercial purposes as long as the copyright notices are not
removed.  This program may not be distributed for a profit without
permission from Doug Keller.  Fred Fish has permission to distribute
this program as part of the Fred Fish library.


7. Bugs and Info
----------------

If you would like to get in touch with me I can be reached on the
following:

            Bix : dkeller
        Internet: dkeller@vnet.ibm.com
