home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SOFTIC~1.ZIP / DOC-TXT.ZIP / CHAP7 < prev    next >
Text File  |  1992-05-24  |  14KB  |  353 lines

  1.   CHAPTER 7
  2.  
  3. Symbolic and Source Level Debugging
  4.    7.1 Introduction
  5.    7.2 Preparing for Symbolic or Source Debugging
  6.    7.2.1 Preparing for Symbolic Debugging Only
  7.    7.2.2 Preparing for Symbolic and Source 
  8.                   Level Debugging
  9.    7.3 Reserving Memory for Symbols and Source File
  10.    7.4 Loading Programs and Symbol Files
  11.    7.5 Debugging With Symbols
  12.    7.6 Debugging With Source
  13.  
  14.      177 
  15.  
  16. 7.1 Introduction
  17.  
  18. Soft-ICE can load programs, symbol tables and source files for enhanced
  19. debugging. Symbolic debugging allows you to set break points and reference
  20. variables with symbol names rather than specifying numeric addresses.
  21. Source level debugging allows you to step through your program at the
  22. source code level rather than assembly code level.
  23.  
  24. Symbol and source line number information is extracted from the link map
  25. file. The link map must be compatible with Microsoft's linker version 3.60
  26. or greater.
  27.  
  28. Symbols and source files reside in extended memory. You must have
  29. sufficient extended memory for the symbols and source files. Source files
  30. are not paged from the disk as in many debuggers. This allows Soft-ICE to
  31. provide complete system debugging in source level, You can debug T&SR's
  32. interrupt routines and other systems level code at the source level.
  33.  
  34. Note:
  35. You cannot use symbolic or source level debugging unless Soft-ICE has been
  36. loaded as a device driver in CONFIG.SYS.
  37.  
  38.  7.2 Preparing for Symbolic or Source Debugging
  39.  
  40. Before debugging a program with symbols or source you must create a symbol
  41. file. This is a binary file that contains symbol and line number
  42. information in a format that Soft-ICE can understand. This file is created
  43. with the utility MSYM.EXE. MSYM.EXE reads in your link map to create a
  44. symbol file with the extension (.SYM).
  45.  
  46.      178 
  47.  
  48. 7.2.1 Preparing for Symbolic Debugging Only
  49.  
  50. To prepare a program for symbolic debugging only, you must do the
  51. following steps:
  52.    1. Compile or assemble your program.
  53.    2. Link your program with the proper switches to create
  54.         a .MAP file that contains a list of public symbols.
  55.         If you are using Microsoft's linker, the /MA switch
  56.         is the proper switch to use. This .MAP file must be
  57.         identical to the .MAP file produced by Microsoft's
  58.          linker, version 3.60 or greater.
  59.    3. Create a.SYM file by running MSYM.EXE. The
  60.         syntax for using MSYM.EXE is:
  61.        MSYM program-name [.extension]
  62.    If the extension is not supplied MSYM assumes the
  63.    extension is.MAP. MSYM reads in a map file as in
  64.    and writes out a symbol file as output. The symbol
  65.    has the name program-name.SYM.
  66.  
  67. Note:
  68. Before compiling or assembling your program you may want to make some
  69. additional symbols public. Only public symbols are supported with Soft-ICE
  70. symbolic debugging. The way to make a variable or a label public varies,
  71. depending upon which language you are using.
  72.  
  73. In 8086 assembly language, simply use the PUBLIC directive followed by the
  74. locally defined symbols you wish to make public. For example:
  75.  
  76.    PUBLIC FOO, LOOP1, STATUS
  77.  
  78. In C language, all procedure names and static variables are defined
  79. outside a block are public.
  80.  
  81.      179 
  82.  
  83. For other languages, refer to your language manual for details.
  84.  
  85. 7.2.2 Preparing for Symbolic and Source Level Debugging
  86.  
  87. To prepare a program for both symbolic and source debugging, you must do
  88. the following steps:
  89.    1. Compile or assemble each module that you wish
  90.         debug at the source level with the appropriate
  91.         switch to put line number information into the
  92.         object files. With Microsoft languages you can use
  93.         either the /Zi or the /Zd switches. You may not
  94.         want to do this with all files, because the combined
  95.         file sizes of the symbol file and all the source files
  96.         compiled with these switches must fit into the
  97.         amount of extended memory you have reserved
  98.         with the /SYM loading switch in CONFIG.SYS.
  99.    2. Link your program with the proper switches to create
  100.         a.MAP file that contains source line numbers and
  101.         a list of public symbols. If you are using
  102.         Microsoft's linker, the /LI and /MA switches are
  103.         the proper switches to use. This .MAP file must be
  104.         identical to the.MAP file produced by Microsoft's
  105.         linker, version 3.60 or greater.
  106.    3. Create a.SYM file by running MSYM.EXE. The
  107.         syntax for using MSYM.EXE is:
  108.         MSYM program-name [.extension]
  109.   If the extension is not supplied MSYM assumes the
  110.   extension is.MAP. MSYM reads in a map file as input
  111.   and writes out a symbol file as output. The symbol file
  112.   has the name program-name.SYM.
  113.  
  114.      180 
  115.  
  116. 7.3 Reserving Memory for Symbols and Source Files
  117.  
  118. Before loading programs, symbol files and source files you must reserve
  119. extended memory for them. Extended memory is reserved when you load Soft-
  120. ICE in CONFIG.SYS. Before reserving extended memory you may want to add up
  121. the file sizes of the .SYM file and all of the source files that you want
  122. to load. You must reserve at least this much extended memory.
  123. You must use the /SYM loading switch when loading S-ICE.EXE. A sample line
  124. in CONFIG.SYS for loading Soft-ICE and reserving space for symbols and
  125. source files is:
  126.  
  127.       DEVICE = S-ICE.EXE /SYM 1024
  128.  
  129. This example loads Soft-ICE into extended memory and reserves 1 megabyte
  130. of memory for symbols and source files. See section 6.3 (Loading Soft-ICE
  131. as a Loadable Device Driver) for more details on reserving memory.
  132.  
  133.  7.4 Loading Programs and Symbol Files
  134.  
  135. The Soft-ICE utility LDR.EXE is used for loading programs, symbol files
  136. and source files. For symbolically debugging application programs and T&SR
  137. programs you will typically use LDR.EXE to load the program, symbols and
  138. source files in one step. For debugging loadable device drivers, ROMs and
  139. other system components you will typically use LDR.EXE to load the symbol
  140. file and source files only.
  141. The syntax for LDR.EXE is:
  142.  
  143. LDR program-name | program-name.SYM |
  144.                               program-name.extension
  145.  
  146.      181
  147.  
  148. 7.4.1 Loading Program, Symbols and Source
  149.  
  150. To load your program, symbols and source files in one step, you must use
  151. LDR.EXE in the form:
  152.  
  153.    LDR program-name
  154.  
  155. Notice that program-name does not have a file extension. If no file
  156. extension is supplied, then LDR.EXE will do the following:
  157.    1. Load program-name.SYM into extended memory
  158.    2. Load source files into extended memory. This step
  159.         is done only if source records exist in the .SYM file.
  160.    3. Load program-name.EXE into memory at the
  161.         location it would have loaded if it had been loaded
  162.         directly from the DOS prompt.
  163.    4. Bring up Soft-ICE with the instruction pointer at
  164.         first instruction of your program. If it is a C
  165.         program and source is loaded for the file
  166.         containing , _MAIN, then the source for that file
  167.         will be visible in the code window.
  168.  
  169.  7.4.2 Loading Only Symbols and Source Files
  170.  
  171. If you wish to load only symbols and source files (for debugging a
  172. loadable device driver for example) you must use LDR.EXE in the form:
  173.  
  174.    LDR program-name.SYM
  175.  
  176. Notice that the.SYM extension is specified. This will load the .SYM file
  177. and source files into extended memory. When symbols are loaded by this
  178. method your program or device driver symbols are assumed to be referenced
  179. from 0:0. Since this is rarely the case you will need to use the Soft-ICE
  180. command SYMLOC to locate the symbols. See
  181.  
  182.      182 
  183.  
  184. the description of the SYMLOC command in section 5.10 for a complete
  185. description. An example of loading a symbol file called DRIVER.SYM is:
  186.  
  187.   LDR DRIVER.SYM
  188.  
  189. 7.4.3 Loading a Program With No Symbols or Source
  190.  
  191. To load a program file without loading the associated symbol file you must
  192. use LDR.EXE in the form:
  193.  
  194.    LDR program-name.extension
  195.  
  196. Notice that the file extension is present. Typically the file extension
  197. will be.EXE or.COM. When a file extension specified LDR.EXE will load the
  198. program and bring up Soft-ICE with the instruction pointer at the first
  199. instruction of the program. An example of loading a program with symbols
  200. and source is:
  201.  
  202.   LDR TEST.EXE
  203.  
  204. Notes:
  205. LDR.EXE saves a copy of the interrupt vector table automatically when it
  206. loads your program. This is equivalent to doing a VECS S command. If you
  207. are going to exit your program before it runs to completion, you can do an
  208. EXIT R to exit the program and restore the interrupt vector table.
  209.  
  210. Using LDR.EXE to load only the program-name.EXE is often useful for
  211. restarting your program while in the middle of a source level debugging
  212. session. To restart, the EXIT R command to abort the current session. Then
  213. use LDR.EXE to reload your.EXE file. The symbols: source do not have to be
  214. loaded since they remain in extended memory.
  215.  
  216.      183 
  217.  
  218. If LDR.EXE gives you the message "Out of space loading symbol
  219. information", this means that you did not reserve enough extended memory
  220. with the /SYM loading switch in CONFIG.SYS.
  221.  
  222. If LDR.EXE does not find your source files on the same directory as the
  223. program you are loading, LDR.EXE will prompt you for the path names where
  224. it can find the source files. If you have source files on several
  225. directories or are loading a program frequently this becomes cumbersome.
  226. You can eliminate the need for prompting by using the DOS environment
  227. variable SRC. LDR.EXE uses this environment variable to find source files
  228. before prompting the user. The syntax for setting the environment variable
  229. from the DOS prompt is:
  230.  
  231.    SET SRC = directory;directory;...;directory
  232.  
  233. Each of the specified directories will be searched before the user is
  234. prompted.
  235.  
  236. Limitations:
  237. Soft-ICE supports symbols for only one program at a time. If you load a
  238. new .SYM file, the existing one is overwritten.
  239. Soft-ICE does not follow overlays or Microsoft Windows segment movement.
  240. Soft-ICE recognizes public symbols and line numbers only. It does not
  241. support local variables.
  242.  
  243. 7.5 Debugging With Symbols
  244.  
  245. After you have loaded your program and.SYM file you can begin debugging
  246. your program symbolically. In general a symbol can be used in any command
  247. in place of an address.
  248.  
  249.      184 
  250.  
  251. Symbols are also used by several Soft-ICE commands when addresses are
  252. displayed. For example, the U command displays symbol names of labels and
  253. procedures as it encounters them.
  254. There are two commands that are helpful when you are symbolically
  255. debugging:
  256.    * SYM -- Use the SYM command to get a listing of
  257.        symbol names and values, or to change the value
  258.        a symbol.
  259.    * SYMLOC -- Use the SYMLOC command to
  260.        relocate the base of all of your symbols. You
  261.        would need to use the SYMLOC command when:
  262.        1. Loading symbols for a loadable device driver
  263.        2. Loading symbols for a T&SR that has already
  264.             been loaded
  265.        3. Your program moves itself to a location other
  266.             than its original location.
  267. See section 5. 10 for a complete description of these commands.
  268.  
  269. 7.6 Debugging With Source
  270.  
  271. When source files are loaded, Soft-ICE allows you to view and step through
  272. your source code as you are debugging. Soft-ICE offers two different modes
  273. of source level debugging: mixed mode and source mode. Use the SRC command
  274. to switch between modes.
  275. Mixed mode shows source lines and the assembly language produced by those
  276. source lines intermixed on the display. Mixed mode is useful when you must
  277. debug at the assembly level, but use the source lines for reference. Mixed
  278. mode is allowed whether the code window visible or not.
  279.  
  280.      185 
  281.  
  282. Source mode strictly shows source lines on the display. Source level
  283. debugging requires the code window to be visible.
  284.  
  285. 7.6.1 Using Line Numbers
  286.  
  287. Line numbers can be used in place of addresses in several commands. To
  288. differentiate a line number from an actual address, place a . (period) in
  289. front of the number. For example, to set an execution break point at
  290. source line 45 type:
  291.  
  292.    BPX .450
  293.  
  294.  7.6.2 Using Source Mode in the Code Window
  295.  
  296. The code window must be visible to enter source mode. If not visible, use
  297. the WC command to make it visible. Once you are in source mode you can use
  298. Soft-ICE commands switch to a different source file, view source at any
  299. location in the file, scroll through the file, search for strings in the
  300. file, and set break points in the file. For a complete description of the
  301. following commands see their command descriptions in chapters 4 and 5. The
  302. following list is a brief overview of commands that are useful when
  303. debugging source code:
  304.     * Make the code window visible (if it is not already)
  305.         with the WC command. 
  306.     * Toggle between source, mixed, and code modes
  307.         with the SRC command. To toggle modes enter:
  308.            SRC
  309.      186
  310.  
  311.     * Place a source file in the code window (if it is n@
  312.         already) with the FILE command. For example
  313.         change from the current file to file MAIN.C enter:
  314.  
  315.              FILE MAIN.C
  316.  
  317.     * Display source at a specific location within the
  318.         source file with the U command. To change the
  319.         view to a specific line number or memory address
  320.         use the U command. You can specify actual
  321.         addresses or line numbers as a parameter to the
  322.         command. For example, to view source in the
  323.         code window starting at source line 450 enter:
  324.  
  325.              U .450
  326.  
  327.  
  328.     * Locate the current instruction in the code wind@
  329.         with the . (period) command.
  330.     * Search for a specific character string with the S@
  331.         command. For example, to search for the string
  332.         "Hello World" starting at line 100 in the current
  333.         source file enter:
  334.  
  335.             SS 100 "Hello World"
  336.  
  337.     * Move the cursor to the code window (if it is not
  338.         already) with the EC command.
  339.     * Scroll the source with the keys up, down,
  340.         PaqeUp, PageDn.
  341.     * Set point-and-shoot break points with the BPX
  342.         command. Simply place the cursor on the source
  343.         line that you wish to break on, then enter:
  344.  
  345.            BPX
  346.  
  347.         187
  348.  
  349. Page 188 is blank
  350.  
  351.         188
  352.  
  353.