home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / BSC32.ZIP / BSCTUT.TXT < prev    next >
Text File  |  1994-01-24  |  18KB  |  513 lines

  1. ______________________________________________________________________
  2.  
  3. Browser Library Tutorial - BSCTUT.TXT
  4. Microsoft Visual C++ Browser Toolkit for Windows NT
  5. (C) Copyright Microsoft Corporation, 1993
  6.                               
  7.  
  8.      This tutorial illustrates the use of the browser
  9.      library (BSC.LIB) included in the Microsoft Visual C++
  10.      Browser Toolkit for Windows NT. Specifically, the
  11.      tutorial describes the Toolkit's sample application,
  12.      BSCDUMP, which calls many of the browser library's
  13.      functions. You may want to print a copy of BSCDUMP.C
  14.      for easy reference.
  15.  
  16.  
  17. Contents
  18.  
  19.  
  20.      1    Overview of BSCDUMP
  21.      2    BSCDUMP Arguments
  22.      
  23.           2.1  General List Commands
  24.           2.2  Symbol-specific List Commands
  25.  
  26. ______________________________________________________________________
  27.  
  28. 1  Overview of BSCDUMP
  29.  
  30.      The sample application BSCDUMP included with the
  31.      Browser Toolkit demonstrates how you can use the
  32.      Toolkit's browser library to access the contents of
  33.      browser database files, which have the extension .BSC.
  34.      The database contains all symbols defined in the
  35.      program's source and include files, the location of
  36.      these symbols, references to each, and linkage
  37.      information. These symbols represent the names of all
  38.      functions, types (such as the names of all classes,
  39.      structures, enumerations, and their members), macros,
  40.      and variables in the files. Visual C++ stores a
  41.      program's function names as decorated names, which
  42.      indicate the class to which the function belongs,
  43.      parameter types, calling convention, and return type.
  44.      The database also contains such information as the
  45.      calltree of a function, the symbol table, the
  46.      definition table, and the reference table. You can
  47.      query each of these tables using the browser APIs to
  48.      obtain information about program symbols.
  49.      
  50.      BSCDUMP is a program that displays the contents of .BSC
  51.      files.  The program accomplishes most of its tasks by
  52.      calling browser library functions, which perform all
  53.      the information retrieval work. The include files,
  54.      BSCSUP.H and BSC.H, provide the necessary interface to
  55.      all the browser library's functions. The declarations
  56.      in each of these header files follow the specifications
  57.      explained in the BSCREF.TXT file. You should note the
  58.      special use of  the browser library "callback"
  59.      functions since they can enhance environment
  60.      integration.
  61.      
  62.      A callback function is one that performs a particular
  63.      system service required by the browser library (such as
  64.      memory allocation, file I/O, or error-handling).
  65.      Programs that use BSC.LIB can still use functions from
  66.      the C run-time library, however callback functions can
  67.      be used to provide an interface to any environment that
  68.      might not allow access to the C run-time library. See
  69.      BSCREF.TXT for a more detailed discussion of the
  70.      browser library's callback functions and their
  71.      specifications.
  72.      
  73.      The Browser Toolkit includes the batch file MAKE.BAT
  74.      that instructs the Microsoft Visual C++ for Windows NT
  75.      compiler to create the BSCDUMP executable.
  76.      
  77.      Some of the general operations BSCDUMP performs include
  78.      listing file references, redundant definitions, and
  79.      symbol definitions and references. The program also
  80.      displays symbol calltrees and classtrees, BSC file
  81.      summary and statistics, and raw symbols. The following
  82.      sections provide more specific information about these
  83.      operations and how they are accomplished.
  84.  
  85. ______________________________________________________________________
  86.  
  87. 2  BSCDUMP Arguments
  88.  
  89.      BSCDUMP has the following usage syntax:
  90.      
  91.           BSCDUMP [options] <file.bsc>
  92.      
  93.      Table 1 lists the available options and their
  94.      respective actions. Note that if no option is selected,
  95.      BSCDUMP produces an ASCII dump of the .BSC file.  The
  96.      table also indicates the function that is called to
  97.      produce the desired action. Function names preceded by
  98.      an asterisk refer to functions defined in the BSCDUMP.C
  99.      file itself. All other functions are defined in the
  100.      browser library.  This tutorial describes each of these
  101.      options in the order listed in Table 1.
  102.      
  103.      Table 1:  BSCDUMP Options
  104.                                                    Called
  105.      ------------------------------------------------------------
  106.       Argument               Action             Function
  107.      ------------------------------------------------------------
  108.  
  109.      -l[FCVMT]        List references           ListRefs
  110.  
  111.      -u[FCVMT]        List unused definitions   *ListUnused
  112.  
  113.      -O <file>        Outline functions with    *DumpFunctio
  114.                       source comments           n-Comments
  115.  
  116.      -s               List BSC file             StatsBSC
  117.                       summary/statistics
  118.  
  119.      -S               List raw symbols          *ListRawSyms
  120.  
  121.      -o[FCVMT]        List outline for given    FOutlineModu
  122.      <symbol>         symbol (module)           leLsz
  123.  
  124.      -i[FCVMT]        List information about    GenerateOver
  125.      <symbol>         given symbol              loads
  126.  
  127.      -r <symbol>      List references to        *DumpDefRefL
  128.                       symbol (case sensitive)   sz
  129.  
  130.      -d <symbol>      List definitions of       *DumpDefRefL
  131.                       symbol (case sensitive)   sz
  132.  
  133.      -R <symbol>      List references to        *DumpDefRefL
  134.                       symbol (case              sz
  135.                       insensitive)
  136.  
  137.      -D <symbol>      List definitions of       *DumpDefRefL
  138.                       symbol (case              sz
  139.                       insensitive)
  140.  
  141.      -t <symbol>      Provide                   GenerateOver
  142.                       calltree/classtree        loads
  143.  
  144.      -b <symbol>      Provide backward          GenerateOver
  145.                       calltree/classtree        loads
  146.  
  147.      no argument      Dump entire BSC file      DumpBSC
  148.                       contents
  149.      
  150.      The additional options [FCVMT] available for some
  151.      arguments narrow the inquiry to the following specific
  152.      symbols:
  153.      
  154.      Argument       Symbol Information
  155.      
  156.      F              Functions
  157.      C              Classes
  158.      V              Variables
  159.      M              Macros
  160.      T              Types
  161.      
  162.      If none of these suboptions is selected explicitly,
  163.      then they are all selected by default. The following
  164.      sections describe each of the BSCDUMP options in more
  165.      detail.
  166.  
  167. ______________________________________________________________________
  168.  
  169. 2.1  General List Commands
  170.  
  171.      For each of the options selected that also take
  172.      suboptions, BSCDUMP creates a filter mask (called an
  173.      MBF for historical reasons) representing these
  174.      suboptions. If no suboptions are selected, this mask is
  175.      set to all options.
  176.      
  177.      Refer to BSCREF.TXT for a more detailed discussion of
  178.      browser library functions referred to in BSCDUMP.C.
  179.      
  180.      
  181.      -l[FCVMT] (List References)
  182.      
  183.      The program simply passes the suboption filter mask to
  184.      the browser library function ListRefs, which
  185.      accomplishes the task of listing all symbol references.
  186.      
  187.      
  188.      -u[FCVMT]  (List Unused Definitions)
  189.      
  190.      BSCDUMP depends on the function ListUnused to list
  191.      unused definitions. This is not a browser library
  192.      function and therefore is a good example of one way to
  193.      extend the library's functionality. Here is the
  194.      function listing:
  195.      
  196.      void ListUnused(MBF mbf)
  197.      {
  198.          ISYM isym, isymMac;
  199.          IINST iinst, iinstMac;
  200.          IUBY iubyFirst, iubyLast;
  201.      
  202.          isymMac = IsymMac();
  203.          for (isym = 0 ; isym < isymMac ; isym++) {
  204.           InstRangeOfSym(isym, &iinst, &iinstMac);
  205.           for ( ; iinst < iinstMac ; iinst++) {
  206.               if (!FInstFilter(iinst, mbf))
  207.                continue;
  208.               UbyRangeOfInst(iinst, &iubyFirst, &iubyLast);
  209.               if (iubyFirst == iubyLast) {
  210.                DumpInst(iinst);
  211.                BSCPrintf("\n");
  212.               }
  213.           }
  214.          }
  215.      }
  216.      
  217.      
  218.      Initially, ListUnused calls a browser library function,
  219.      IsymMac, that returns the biggest symbol index in the
  220.      browser database. This number provides the upper bound
  221.      in a search for redundant symbol definitions. The
  222.      following for loop allows the remaining part of the
  223.      function to query each symbol individually with the
  224.      range of isym = 0 to isym = isymMac - 1. The function
  225.      then queries another library function, InstRangeofSym,
  226.      to determine the range of instances associated with
  227.      each symbol in the symbol table. This function stores
  228.      the lower and upper bounds in iinst and iinstMac,
  229.      respectively. A call to FInstFilter determines if the
  230.      current symbol matches the one requested. If it does
  231.      not, then the function proceeds with the next iteration
  232.      of the for loop.
  233.      
  234.      Using the two bounds for the symbols, ListUnused calls
  235.      on the library function UbyRangeOfInst, which returns
  236.      the associated range called by the table. The function
  237.      then determines if the upper and lower bounds of this
  238.      range are identical. If the current symbol is
  239.      redundant, ListUnused calls the function DumpInst,
  240.      which sends the following information to the standard
  241.      output regardless of  symbol instance type:
  242.      
  243.           <ASCII instance name> <ASCII type name> <ASCII
  244.      attribute name>
  245.      
  246.      Finally, another library function, BSCPrintf, produces
  247.      the new line on the standard output via the BSCOutput
  248.      callback function.
  249.      
  250.      
  251.      -O <file>  (Outline functions with source comments)
  252.      
  253.      The BSCDUMP function DumpFunctionComments displays a
  254.      list of all functions and associated comments in the
  255.      given source file(s).  Wildcards can be used in the
  256.      filename given to this option.
  257.      
  258.      To display the source file comments,
  259.      DumpFunctionComments calls another BSCDUMP.C function,
  260.      DumpComments.  This function uses a heuristic rule to
  261.      search for comment blocks before functions in the
  262.      source.  If no comments can be found, only the function
  263.      name is displayed.
  264.      
  265.      The following is the output of  bscdump -O bscdump.c
  266.      bscdump.bsc:
  267.      
  268.      Browser Data Base: bscdump.bsc
  269.      
  270.      [[[[[[[[[[[[[ c:\browser\bscdump.c ]]]]]]]]]]]]
  271.      
  272.      ## DumpBobInfo  (function:public)
  273.      {
  274.      // dump the instance info from a BOB, the BOB must be
  275.      of clsInst
  276.      //
  277.      }
  278.      
  279.      ## DumpComments (function:public)
  280.      {
  281.      // having opened a particular file, we are now looking
  282.      for comments at
  283.      // or before the given line number
  284.      //
  285.      }
  286.      
  287.      ## DumpDefRef   (function:public)
  288.      {
  289.      // dump definitions or references for a single BOB,
  290.      suitable for use
  291.      // in GenerateOverloads
  292.      //
  293.      }
  294.      
  295.      ## DumpDefRefLsz   (function:public)
  296.      {
  297.      // dump definition or reference starting from possibly
  298.      overloaded symbol name
  299.      //
  300.      }
  301.      
  302.      ## DumpFunctionComments (function:public)
  303.      {
  304.      // show any comment headers that are associated with
  305.      functions
  306.      // in the given module.  The module may include
  307.      wildcards.
  308.      //
  309.      }
  310.      
  311.      ## DumpFwdTree  (function:public)
  312.      {
  313.      // dump a forward tree, either class tree or call tree
  314.      depending on
  315.      // the type of BOB that we get.  The BOB must be an
  316.      instance BOB.
  317.      //
  318.      }
  319.      
  320.      ## DumpRevTree  (function:public)
  321.      {
  322.      // dump a reverse tree, either class tree or call tree
  323.      depending on
  324.      // the type of BOB that we get.  The BOB must be an
  325.      instance BOB.
  326.      //
  327.      }
  328.      
  329.      ## GenericError  (function:public)
  330.      {
  331.      // non-specific error message about a given symbol
  332.      //
  333.      }
  334.      
  335.      ## ListRawSyms   (function:public)
  336.      {
  337.      // list the raw text of all the symbols in the
  338.      database, useful
  339.      // for grepping.  Note sorting order is subject to
  340.      change so
  341.      // use a comparison API to compare...
  342.      //
  343.      }
  344.      
  345.      ## ListUnused    (function:public)
  346.      {
  347.      // list unused definitions, these are items which are
  348.      not used by some other
  349.      // symbol known to the browser.  Note, entry points
  350.      like "main" should appear
  351.      // in the list.  This output is helpful in locating
  352.      dead code.
  353.      //
  354.      }
  355.      
  356.      ## main         (function:public)
  357.      {
  358.      // main entry point, parse args and dispatch workers...
  359.      //
  360.      }
  361.      
  362.      ## MbfFromLsz   (function:public)
  363.      {
  364.      // get a mask of object types (nobody knows how this
  365.      ended up getting
  366.      // called an MBF) from a string...
  367.      //
  368.      }
  369.      
  370.      ## ParseArgs    (function:public)
  371.      {
  372.      // parse arguments into global variables and open a
  373.      database
  374.      //
  375.      }
  376.      
  377.      ## Usage        (function:public)
  378.      {
  379.      // emit usage information
  380.      //
  381.      }
  382.      
  383.      
  384.      -s (List Browser File Summary/Statistics)
  385.      
  386.      The browser library function StatsBSC performs all the
  387.      necessary work required to list statistics and a
  388.      summary of a browser database. The statistics include
  389.      the table sizes for the following tables and lists:
  390.      
  391.           -  Module Table
  392.           -  Symbols listed by module name
  393.           -  Symbol list
  394.           -  Properties list
  395.           -  Definition table
  396.           -  Reference table
  397.           -  Call table
  398.           -  Called by table
  399.      
  400.      In addition, the StatsBSC function outputs each symbol
  401.      and the associated instance information counts.
  402.      
  403.      
  404.      -S (List Raw Symbols)
  405.      
  406.      To list raw symbols in a browser database, BSCDUMP
  407.      calls its function ListRawSyms, shown below. This
  408.      function calls the library function IsymMac, which
  409.      returns the biggest symbol index in the database.
  410.      BSCDUMP then prints all symbols with index smaller than
  411.      this largest index.
  412.      
  413.      void ListRawSyms()
  414.      {
  415.          ISYM isym, isymMac;
  416.          isymMac = IsymMac();
  417.      
  418.          for (isym = 0 ; isym < isymMac ; isym++)
  419.           BSCPrintf("%s\n", LszNameFrSym(isym));
  420.      }
  421.  
  422. ______________________________________________________________________
  423.  
  424. 2.2  Symbol-Specific List Commands
  425.  
  426.      -o[FCVMT] <symbol> (List Outlines)
  427.      
  428.      The -o option produces a list of all symbols in the
  429.      module with attribute types indicated by the suboptions
  430.      (F, V, M, C, or T). With the exception of argument
  431.      parsing, all of the work required to produce this list
  432.      is done by the library function FOutlineModuleLsz.
  433.      Here is the actual call to this function:
  434.      
  435.                FOutlineModuleLsz(psymbol, mbf)
  436.      
  437.      
  438.      -i [FCVMT] <symbol> (List Symbol Information)
  439.      
  440.      This option causes BSCDUMP to call the
  441.      GenerateOverloads library function, which takes three
  442.      arguments:  a symbol, a symbol mask, and a pointer to a
  443.      function.  GenerateOverloads returns all possible
  444.      browser objects (BOBs) that match a given overloaded
  445.      name. GenerateOverloads then applies whatever function
  446.      it was given to each of the BOBs found, making
  447.      GenerateOverloads a very powerful library function.  In
  448.      this case, the function passed to GenerateOverloads is
  449.      DumpBobInfo, which dumps a single instance of a browser
  450.      object.
  451.      
  452.      void BSC_API DumpBobInfo(BOB bob)
  453.      {
  454.          if (ClsOfBob(bob) != clsInst)
  455.           return;
  456.          DumpInst(IinstFrBob(bob));
  457.          BSCPrintf("\n");
  458.      }
  459.      
  460.      
  461.      -r <symbol>  and -d <symbol> (List References and
  462.      Definitions to Symbol; Case Sensitive)
  463.      
  464.      The -r and -d options allow the user to list each
  465.      reference to and definition of, respectively, a given
  466.      symbol. Its implementation again demonstrates the power
  467.      of GenerateOverloads. BSCDUMP uses its DumpDefRef
  468.      function and GenerateOverloads, as shown below, to
  469.      generate references and definitions.
  470.      
  471.      void DumpDefRefLsz(LSZ lszSym)
  472.      {
  473.           if (!GenerateOverloads(lszSym, mbfAll,
  474.      DumpDefRef))
  475.               GenericError(lszSym);
  476.      }
  477.      
  478.      
  479.      -R <symbol> and -D <symbol> (List References and
  480.      Definitions to Symbol; Case Insensitive)
  481.      
  482.      These two options are identical to their respective -r
  483.      and -d counterparts, with the exception that the
  484.      database queries are case insensitive. In fact, they
  485.      both result in the same function, DumpDefRefLsz, being
  486.      called. BSCDUMP achieves this dual-case functionality
  487.      by calling the SetCaseBSC library function, which
  488.      overrides the browser database case sensitivity. The
  489.      argument to SetCaseBSC is a Boolean which determines if
  490.      sensitivity is on (TRUE) or off (FALSE).
  491.      
  492.      
  493.      -t <symbol> (Provide Calltree/Classtree)
  494.      
  495.      This option provides the calltree or classtree from a
  496.      symbol name, which may be the name of either a function
  497.      or a module. BSCDUMP calls the GenerateOverloads
  498.      library function with a pointer to BSCDUMP's
  499.      DumpFwdTree function. Depending on the symbol mask
  500.      filter, the latter determines the type of tree
  501.      requested (call or class) and calls one of the two
  502.      library functions CallTreeInst or ClassTreeInst.
  503.      
  504.      -b <symbol> (Provide Backward Calltree/Classtree)
  505.      
  506.      For a backward calltree or classtree, BSCDUMP also
  507.      calls GenerateOverloads, but with a pointer to
  508.      BSCDUMP's DumpRevTree function instead. After
  509.      determining which type of tree is requested, BSCDUMP
  510.      calls one of two library functions, RevTreeInst or
  511.      RevClassTreeInst.
  512.      
  513.