BEYOND ASIS PROGRAM DATA BASES AND TOOL ORIENTED by bxl27997

VIEWS: 4 PAGES: 32

									BEYOND ASIS: PROGRAM DATA BASES
   AND TOOL-ORIENTED QUERIES

               Janusz Laski
               SofTools, Inc.
               3024 Longview
       Rochester Hills, Michigan 48307
               (248) 853 7602
            laski@oakland.edu

              William Stanley
            Oakland University
         Rochester, Michigan 48309
              (248) 370 2133
          wfstanle@oakland.edu

             Pawel Podgorski
           WorldClass Technology
       30200 Telegraph Road, Suite 401
          Bingham Farms, Mi 48025
             (248) 646 0034/230
         Pawel_Podgorski@wct.com




                  Page 1 of 32
             CONTENTS


 SWAT ORIGIN


 EXPERIENCE WITH ASIS


 SWAT DATA BASES


 TOOL ORIENTED QUERIES




                Page 2 of 32
  SWAT: SoftWare Analysis and Testing

Inspiration


STAD - System for Testing And Debugging
1992 - 2001 (J.Laski, P.Luczycki, W.Stanley)




http://www.cse.secs.oakland.edu/edslabs/
               about/stad.asp




                        Page 3 of 32
                    SWAT: Objectives
   Arbitrary Ada 95 Programs


   Integrated Approach: Unified Framework to Support

    - Static (Source-Based) Analysis

    - Dynamic (Execution-Based) Analysis as a refinement
        of Static Analysis

    - All Stages of Software Life Cycle

   Extensibility

    - Easy inclusion of new SAT methods



SAT - Software Analysis and Testing


ASIS used to develop FrontEnD (FRED)



                         Page 4 of 32
          SWAT: Initial Functionality

   Static Analysis

    - Control and Data Dependencies

    - Program Slicing (Partial Programs)

    - Data and Control Anomalies



   Dynamic Analysis

    - Test Coverage Criteria: Statement, Branch, Data Flow
         Chains

    - Dynamic Slicing



   Allow Future Extensions




                         Page 5 of 32
              ASIS: AN EXAMPLE
Flow Graph of an IF statement:

IF A OR ELSE B THEN
   Integer_Value := 1 + 2;
END IF;




                        Page 6 of 32
       ASIS: Code for                   Example.
Procedure Break_Into_Node
  (Routine_Declaration: Asis.Element) is
-- Break declaration into a list of its individual
-- statements and a list of declarations
Routine_Statment_List: Asis.Statement_List :=

Asis.Declarations.Body_Statements(Routine_Declaration)
;
begin
FOR index in Routine_Statement_List'Range LOOP
  IF Asis.Elements.Statement_Kind(Routine_Statement_List
    (index)) = An_If_Statement THEN
-- Break the if statement into its different paths with
-- the ASIS query:
   Asis.Statements.Statement_Paths
     (Routine_Statement_List(index),False);

-- Determine the path kind, and if appropriate get the
-- conditionalexpression of the path using the query:


Asis.Statements.Condition_Expression(If_Paths(Index));
-- The conditional expression is then passed to another
-- handler which determines whether it is a short-circuit
-- expression, and builds nodes for the expressions
-- accordingly. Then the paths are broken into their
-- respective statements using the query:

   Asis.Statements.Sequence_Of_Statements
      (If_paths(Index));

-- Each statement is then evaluated and processed.
 END IF;
END LOOP;
END Break_Into_Nodes;



                         Page 7 of 32
               ASIS: FINDINGS

ADVANTAGES


 Great help in the development of a FRont EnD
  (FRED)



HOWEVER,

  There are PROBLEMS

 Quite steep learning curve: ASIS queries are
  expressed in terms of syntax of a very complex
  language


 Not related directly to tool builder problems



 Most SAT methods are language independent
  rather than Ada specific.


                        Page 8 of 32
    ASIS-DERIVED PROGRAM DATA
               BASES
                     (PDBs)



 Collect information abut program to be used by
  tool builder


 No need to learn ASIS on part of tool developer



 If well specified, allow tool implementation in
  parallel with the development of Front End



 Retrieval    functions             can be viewed as
  second-layer queries



 Core of second-layer                queries   can   be
  language-independent

                      Page 9 of 32
             SWAT: ARCHITECTUR




BDB - Basic Data Bases                FRED - Front EnD

DDB - Derived Data Bases              SAS - Static Analysis System

EDB - Execution Data Bases            DAS - Dynamic Analysis
                                      System



              TAXONOMY OF PDBs


                             Page 10 of 32
 SYSTEM Data Bases - contain information that
  spans the entire program



 PROCEDURAL Data Bases - contain information
  about individual subprograms


-------------

 BASIC DATA BASES - derived from the source,
  without further analysis


 DERIVED DATA BASES - derived by processing
  the Basic Data Bases

------------

FORMAT: Machine and Human Readable




                    Page 11 of 32
            SYSTEM DATA BASES
PUA – Program Under Analysis
(http://www.softools.org)


    Elaboration Order (PUA.EOR)


    With Relation (PUA.WTH)


    Routine Call Graph      (PUA.RCG)


    Routine Symbol Table (PUA.RST)


    Type Symbol Table (PUA.TST)


    Variable Symbol Table (PUA.VST)


    Scope and Visibility (PUA.SAV)




                         Page 12 of 32
     SYSTEM DATA BASES: Examples
Routine Call Graph (PUA.RCG)
    For each subprogram R, it identifies:



   All subprograms that may be called by R




   Places of the calls (in Control Flow Graph Data Base)




   References to Routine Symbol Table




                        Page 13 of 32
Routine Call Graph Home_Budget.RCG
6/23/2001_15:35:1
3 NUMBER OF ROUTINES
**********************************************
******

1 IDENTIFIER NUMBER OF CALLING ROUTINE
Home_Budget CALLS
2 NUMBER OF ROUTINES CALLED

2 IDENTIFIER NUMBER OF CALLED ROUTINE
Display NAME OF ROUTINE CALLED
4 6 0 NODES WHERE CALLED

4 IDENTIFIER NUMBER OF CALLED ROUTINE
Get_Expense NAME OF ROUTINE CALLED
5 0 NODES WHERE CALLED
-----
END FILE Home_Budget.RCG



Part of Routine Call Graph for HomeBudget.



                     Page 14 of 32
 SYSTEM DATA BASES: Examples (cntd)
Routine Symbol Table (PUA.RST), provides an external view of
each subprogram R:


   Types and modes (IN, IN OUT, OUT) of formal
    parameters



   Global variables manipulated by R



   Tree of nesting routines declared in R



   Package specifications and bodies are treated as separate
    routines


   FOR loops, DECLARE blocks are treated as local
    routines



   Cross-references to other PDBs



                          Page 15 of 32
Routine Symbol Table Home_Budget.RST 6/23/2001_15:35:1
Routine_ID Kind_Code Parent_Code Routine_Name
       Qualifier_String
       Parameter_String
       Return_Type_Code Return_Type
       Number_of_Parameters       Parameter_Codes
Parameter_Types
       Number_of_Global_Variables Variable_ID's
Use/definition_Codes
6 = Number of routines or blocks.

variable ID's 0 = use/define codes
*****************************************
4 2 1 Procedure Get_Expense NOT_EXPORTED
  Home_Budget.(Budget : out BudgetArray)
  0 NULL
  1 = Number of parameters 3 = Parameter Codes 4 = Parameter
Types.
  0 = Number of global vars 0 = variable ID's 0 = use/define codes
*****************************************
5 4 4 FOR_LOOP $For2 NOT_EXPORTED
  Home_Budget.Get_Expense.
  NULL
  0 NULL
  0 = Number of parameters 0 = Parameter Codes 0 = Parameter
Types.
  0 = Number of global vars 0 = variable ID's 0 = use/define codes

END Routine Symbol Table       File = Home_Budget.RST



         PROCEDURAL DATA BASES
                            Page 16 of 32
Data about individual subprograms,


        Functions, procedures


        Package Specification


        Package Initialization




Flow Graph (*.CFG)

Definition-Use (*.DFU)

Node Data Base (*.NDB)

Position Data Base (*.POS)


Asterisk *: Either package name or ORPHANS, for subprograms
not in a package




                         Page 17 of 32
PROCEDURAL DATA BASES: Examples



procedure Display (Budget:
BudgetArray) is    -- 1
 begin    -- 2
   For C in Categories loop - 3,4,5
    Category_IO.put (c); -- 6
    Put ( ": " ); -- 7
    Put (item =>Budget(C), aft => 2,
         Exp=> 0 ); -- 8
    New_Line; -- 9
   end loop; -- 10, 11
   New_Line; -- 12
 end Display; -- 13


Numbers correspond to nodes in flow graph.




                         Page 18 of 32
Routine Flow Graphs   Orphans.CFG        6/23/2001_15:35:0
-- Control Flow Graph for
-- procedure Display.

3   NUMBER OF ROUTINES
-------
2 = Routine ID

Routine Name = Display(Budget: BudgetArray)

13   NUMBER OF NODES

1 BRANCH NODES .. (BRANCH NODE, NUMBER OF SUCCESSORS,
NUMBER OF PREDICATES)
5 2 -99

1 JOIN NODES ... (JOIN NODE, NUMBER OF PREDECESSORS)
5 2

13 ARCS
1 2 NULL
2 3 NULL
3 4 NULL
4 5 NULL
5 6 TRUE
5 11 FALSE
6 7 NULL
7 8 NULL
8 9 NULL
9 10 NULL
10 5 NULL
11 12 NULL
12 13 NULL
13 0 NO LABEL
END FILE   Orphans.cfg


                         Page 19 of 32
Nodes DataBase    Orphans.NDB
3   NUMBER OF ROUTINES
****************************************

-----

PROCEDURE Display(Budget: BudgetArray)

13 = NUMBER OF NODES

NODE NUMBER   NODE TYPE
NODE TEXT -- SOURCE

1    EN -- ENtry, Paremeter Evaluation
Display(Budget: BudgetArray) IS

2     ST -- Start execution
BEGIN

3    FI -- FOR loop initialization
[ $For1.C := Categories'FIRST ]

4    FI
[ $For1.$Bound := Categories'LAST ]

5    FT -- FOR loop termination test
[ $For1.C <= $For1.$Bound ]

6    PC -- Procedure Call
Category_IO.put (c);



Node Data Base for procedure Display


                           Page 20 of 32
7    PC
Put ( ": " );

8    PC
Put ( item => Budget(C), aft => 2, Exp=> 0 );

9    PC
New_Line;

10    FINC -- FOR loop INCrement
[ $For1.C := $For1.C'SUCC ]

11    EL -- End of FOR Loop
END LOOP [ $For1 ]

12    PC
New_Line;

13    EX -- EXit
END Display

-----

END FILE     Orphans.ndb


Node Data Base for procedure Display (cntd)




                           Page 21 of 32
        TOOL BUILDING USING PDBs:
          PROGRAM BROWSERS

Some EXAMPLES


To find the type and declaration place of variable Budget:


    Search VST (Variable Symbol Table) for entry for
     Budget (fully qualified name)



    Use cross-reference links to RST (Routine Symbol
     Table) and TST (Type Symbol Table) to get the routine
     and type of Budget


    Use links to POS (Position DB) to get the source code
     position




                             Page 22 of 32
        PROGRAM BROWSERS (cntd)

To find the places where Budget is defined and used:



   Consult VIS(ibility) DB to get scope and visibility of
    Budget



   Using that information, consult DFU (Definition-Use)
    DB to get the definitions and uses of Budget in all
    subprograms in scope of Budget




                           Page 23 of 32
    GENERALIZATION OF PDB’S
RETRIEVAL FUNCTIONS: HIDING ASIS

Type Procedure_Type is record
  Name:            String;
  Procedure_Decl: Asis.Element;
  Procedure_Body: Asis.Element;
  Global_Vars:     Asis.Element_List;
  Global_Vars_VST: Integer_List;
  -- etc.
End record;

Type Var_Identifier_Type is record
  Name:               String;
  Variable_Decl:      Asis.Element;
  Variable_Type_Decl: Asis.Element
  VST_Index:          Natural;
  Variable_Type_Index: Natural;
    -- etc.
End record;

Type Graph_Nodes is record
  Asis_Node:         Asis.Element;
  Asis_Predecessors: Asis.Element_List;
  Asis_Successors:   Asis.Element_List;
  Successors:        Integer_List;
  -- etc.
End Record;



                   Page 24 of 32
             A SYSTEM LEVEL QUERY


function Variable_Declaration
   (Var_identifier: Var_identifier_type)
       return Procedure_type.name;


returns the name of the subprogram in which Var_Identifier is
declared.




        A PROCEDURAL LEVEL QUERY
Function Node_Successor
(Node: Graph_Nodes; Routine:
Procedure_identifier)
   return Graph_Nodes;



returns an array of successors of Node in the flow graph for
Routine.




                            Page 25 of 32
      TOWARDS TOOL-ORIENTED
        QUERIES: OBJECTIVES

 Queries should be expressed in tool-oriented
  terms, rather than syntactic ones


 No need to learn ASIS - ASIS either not used
  or used as an intermediate level


 Allow development of any STA tool, including
  dynamic (execution-based) tools



 No need for PDBs - they are either not used or
  used as an intermediate level



   Potentially can be defined for any language


                     Page 26 of 32
TOWARDS TOOL-ORIENTED QUERIES:
            HOW TO DEFINE THEM?

RULES OF THUMB:

- Given any piece of code one should be able to


 Identify type and place of declaration of all
  objects that appear in the code



 Whenever applicable, carry out the
  interpretation of the code



 Request instrumentation of the code




                        Page 27 of 32
 TOOL-ORIENTED QUERIES: ROUGH
    FUNCTIONAL TAXONOMY


 Browsing Queries




 Instrumentation Requests




                    Page 28 of 32
             BROWSING QUERIES
 IntraProcedural queries: Answer questions about
  individual procedures and functions.

    - Flowgraphs

    - Variables Referenced and Defined in statements


 InterProcedural queries: Answer questions about
  interacting subprograms

    - External View of Routine

    - Routine Call Graph

        Calling Routines and places where called

        Routines Called and places of calls

A supporting set of queries:


 VISIBILITY Analysis: Where do things come
  from?
                        Page 29 of 32
         TOOL-ORIENTED QUERIES:
         INSTRUMENTATION REQUESTS

    Allow user-defined insertion of breakpoints, e.g.

     Instrument
      (subprogramId, subprogram_instr,
            Monitor => My_Monitor)

subprogram_instr - instrumented version of

    subprogramID, with calls to My_monitor in
     front of every node in flow graph of
     Subprogram_Id.



    Allow My_Monitor to

     - read values of seleted variables at breakpoints

     - modify those values before execution is resumed



    More ??


                            Page 30 of 32
INSTRUMENTATION: A STAD SOLUTION
Program Series;
VAR k, s : integer;

   Procedure Sum
              (     i : integer;
                var s : integer);
   VAR
       k : integer;

      Function Sqr
               (n : integer) : integer;
      begin
         sqr := n * n
      end; { Function Sqr }

   begin
      s := 0;
      k := 1;
      while k <= i do
         begin
           s := s + sqr( k );
           k := k + 1 ;
         end;
      k := 1;
   end; { Procedure Sum }

begin
   write ( 'Enter an integer ... ');
   read   ( k );
   sum    ( k, s );
   writeln('Sum of squares is ', s );
end. { Program Series }

                      Page 31 of 32
  INSTRUMENTATION: STAD SOLUTION,
           procedure SUM

begin
STAD_ENTRY('Sum');
STAD_COVER(1);
write ;
STAD_COVER(2);
s := 0 ;
STAD_COVER(3);
k := 1 ;
STAD_COVER(4);
while k <= i do
BEGIN
begin
STAD_COVER(5);
s := s + sqr ( k ) ;
STAD_COVER(6);
k := k + 1 ;
end ; STAD_COVER(4);
END ;
STAD_COVER(7);
k := 1 ;
; STAD_EXIT(8);
end;




                 Page 32 of 32

								
To top