home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / examples / example_device / READ.ME < prev    next >
Encoding:
Text File  |  1996-12-24  |  4.0 KB  |  128 lines

  1. Copyright (c) 1993 SAS Institute, Inc, Cary, NC, USA
  2. All Rights Reserved
  3.  
  4. This file describes some techniques for debugging
  5. devices.
  6.  
  7. This explaination is broken up into two sections,
  8.  
  9. 1) Debugging Devices that do not create a new task or
  10.    debugging the code areas that run in the Users process,
  11.    
  12.    and
  13.   
  14. 2) Debugging the task created by the device.
  15.  
  16. =========================================================
  17. Debugging Devices in code area that run under the User's
  18. task.
  19. =========================================================
  20.  
  21. This type of debugging is exactly like debugging a shared
  22. library. You can set a breakpoint on a function in the device
  23. by saying 
  24.  
  25.    break example.device:DevBeginIO
  26.  
  27. NOTE: CPR does not have any debugging information for the 
  28.       device until the OpenDevice() call has returned. Therefore
  29.       this technique will not work for setting a breakpoint
  30.       on the Init(), or Open(), or UserDevInit() routine in 
  31.       the device.
  32.  
  33. Here's a trick for debugging the UserDevInit() if you have Enforcer
  34. and SegTracker running.
  35.  
  36. At the start of the UserDevInit() insert a harmless enforcer hit, ie
  37.   {
  38.         volatile char *a = 0;
  39.         *a = 0;
  40.   }
  41.   
  42. Run CPR on the program that opens your device.
  43. Run the program by typing
  44.  
  45.   go
  46.  
  47. CPR will stop at the enforcer hit and display assembly source. Remember
  48. that OpenDevice() has not yet returned, to CPR has no debugging
  49. information.  To load  the debugging information, type
  50.  
  51.   symload
  52.   
  53. This form of the command will ask SegTracker for the name and seglist of
  54. the current PC, and load debug information. If the device load module
  55. is not in the current directory, you may need to tell symload the absolute
  56. path to the load module. To do this type
  57.  
  58.   symload PC pc "<filename>"
  59.  
  60. Make sure "filename" is enclosed in quotes.  For example, if the correct
  61. filename is "sc:examples/example_device/example.device", you would type
  62.  
  63.   symload PC pc "sc:examples/example_device/example.device"
  64.  
  65. =========================================================
  66. Debugging the task created by the device.
  67. =========================================================
  68.  
  69. There are two important items to remember when setting breakpoints
  70. in code from a device that executes as a second task.
  71.  
  72.   1) Be sure to set the breakpoint at a location so that once the
  73.      PC gets there, CPR will have debugging information for that process.
  74.      When debugging a device, CPR does not have debugging information
  75.      about the device until the OpenDevice() call returns. For this
  76.      example, you can set a breakpoint at cmd_handler() line 70. This
  77.      location is safe because line 69 waits for the first message to
  78.      be sent to it from the BeginIO() routine.
  79.      
  80.   2) Make sure that CPR has control of the task that hits a breakpoint.
  81.      CPR implements breakpoint by inserting ILLEGAL instructions. If a
  82.      task that is not under CPR's control hits the breakpoint, the program
  83.      will get a Software Error 4.
  84.     
  85. Here are the steps for debugging the second task of this example
  86. device.
  87.  
  88. 1) Start CPR on the driver program. The driver program will do the
  89.    OpenDevice().
  90.    
  91.       cpr driver
  92.       
  93. 2) Turn on catch new tasks, and catch devices.
  94.     
  95.       opt catch on
  96.       opt device on
  97.       
  98. 3) Set a breakpoint in the code for the new task.
  99.  
  100.       break example.device:cmd_handler 70
  101.       
  102. 4) Run the program.
  103.  
  104.       go
  105.       
  106. 5) CPR should stop at line 70 of cmd_handler() and display the source
  107.    for serial.c. You can now lists the tasks under CPR's control.
  108.    
  109.       tasks
  110.       
  111. 6) Notice that four tasks are currently under CPR's control. The two
  112.    extra tasks were created by the Open() of con: on lines 58 and 60.
  113.    We don't want to debug them, so let them run by detaching them.
  114.    
  115.       detach "CON"
  116.       detach "CON"
  117.       
  118. 7) Now list the tasks again. You should see only two.
  119.      
  120.       tasks
  121.       
  122.  
  123. At this point you can continue debugging as normal.
  124.  
  125. If you want to debug a location before line 70 of this example,
  126. or before place where the OpenDevice() is known to have completed,
  127. use the Enforcer/SegTracker trick explained above.
  128.