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

  1. Example shared library
  2. Copyright (c) 1992-1993 SAS Institute, Cary, NC, USA
  3. All Rights Reserved
  4.  
  5. This example shows you how to debug a shared library and how to
  6. profile a shared library.
  7.  
  8. DEBUGGING SHARED LIBRARIES
  9. --------------------------
  10.  
  11. To debug a shared library, perform the following steps:
  12.  
  13. 1. Build the library.
  14.  
  15.    Just type "SMAKE" in the Shell or double-click on the "Build" icon.
  16.    
  17.    SMAKE will build the library "mylib.library" and install it in your
  18.    LIBS: directory.  It will build the test program "test" in the current
  19.    directory.
  20.  
  21. 2. Run the test program under the debugger.
  22.  
  23.    From the Shell, type
  24.    
  25.       cpr test
  26.  
  27.    or from Workbench, click on the "Debug" icon, hold down the SHIFT key
  28.    and double-click on the "test" icon.
  29.  
  30. 3. Let CPR know you want to debug shared libraries.
  31.  
  32.    Type the following in the dialog window:
  33.    
  34.       opt reslib on
  35.  
  36.    or use the mouse to select the "Step into Reslib?" menu item from the 
  37.    "Options" menu.
  38.  
  39. 4. Set a breakpoint in the library routine and proceed.
  40.  
  41.    Type the following in the CPR dialog window:
  42.    
  43.       b mylib.library:LIBtest1
  44.       go
  45.  
  46.    After typing "go", you should see CPR stop at the routine "test1" in
  47.    your library.  In your libraries, the prefix preceding the name may 
  48.    vary depending on how you specify the LIBPREFIX option.  Since this
  49.    example specifies a LIBPREFIX of _LIB, we use LIB in the debugger.
  50.    Only functions that are listed in your .fd file need the prefix.
  51.  
  52. 5. Use the debugger normally.
  53.  
  54.    Anything you can do in the debugger under normal circumstances is legal
  55.    in the shared library.  Try setting the value of the external variable
  56.    "b":
  57.    
  58.       set b = 10
  59.       go
  60.  
  61.    You should hit your breakpoint again.  Go to the workbench by clicking
  62.    on the front-to-back gadget in the upper right-hand corner.  You'll see
  63.    that the function test1 returned 10.
  64.  
  65. 6. Clear all breakpoints and allow the program to complete.
  66.  
  67.       bc *
  68.       go
  69.  
  70.    Note that under AmigaDOS 1.3, there will be a short delay because
  71.    the test program calls the Delay() function.  Under AmigaDOS 2.0, you
  72.    will have to go to the workbench and click on the close gadget of the
  73.    program before the program will terminate.
  74.  
  75. PROFILING SHARED LIBRARIES
  76. --------------------------
  77.  
  78. Note that the smakefile compiles "mylib.c" with the PROFILE compiler
  79. option.  This causes the compiler to generate special code at the
  80. entry and exit to each function that can be used by the SPROF utility
  81. to determine how much time you are spending in each of your subroutines.
  82.  
  83. To try the profiling, type the following in a Shell:
  84.  
  85.    sprof test
  86.  
  87. Note that "test" is NOT compiled with profiling.  However, "test" does
  88. invoke the shared library which IS compiled with profiling.  When the
  89. shared library is loaded, the libinitr.o startup code runs the profiling
  90. autoinitialization function from the standard link library.  This
  91. autoinit function establishes communications with the SPROF utility.
  92.  
  93. You could also choose to run SPROF seperately.  To do this, open two
  94. Shell windows.  In one window, type
  95.  
  96.    sprof
  97.  
  98. and in the other, type
  99.  
  100.    test
  101.  
  102. When the library gets loaded, from anywhere in the system, SPROF knows
  103. and begins profiling.
  104.  
  105. You can run SPROF on the library from WorkBench in either of two ways:
  106.  
  107.    1. Double-click the SPROF icon in SC:C, then double-click the TEST
  108.       icon.
  109.    
  110.    2. Single-click the SPROF icon in SC:C, then hold down the SHIFT
  111.       key and double-click the TEST icon.
  112.  
  113. If SPROF is not running when the library is initialized, the library 
  114. executes with no profiling.
  115.  
  116. The SPROF utility is supplied in SC:C, and the source code is provided
  117. in SC:EXTRAS/SPROF.  For more information and a more detailed example,
  118. see SC:EXAMPLES/PROFILE.