class step_xform¶
A program state transform along a path in the CFG.
Used by step visitors ( step_state ) to describe program transformations for step_state.transition().
Example¶
The step_xform and xform_query_bounds_result methods are not
suitable for interactive exploration in the console. The following
small plug-in uses a simple step visitor to illustrate them. To see
the plug-in in action:
- Copy the plug-in code and save as
codesonar/plugins/step_xform_plugin.py. - Re-run the CodeSonar analysis on
apitest.cppwithout enabling the interactive Python console (if you run it by mistake, exit from the console so that the analysis can finish running). - Open the Analysis Log page and search for string ‘Call site at’.
Examples for methods on this page correspond to the output for the
call site to whoknows() in mymalloc, which will start with a
line of the form Call site at (<cs.sfileinst path/to/apitest.cpp>, 6)
(where path/to will depend on your working directory).
# its only role is to write the results of various step_xform
# operations into the analysis log.
import cs
class step_xform_illustrator(cs.step_state):
def __init__(self):
super(step_xform_illustrator,self).__init__()
def copy(self):
return step_xform_illustrator()
def transition(self,
srcpt,
edgelabel,
destpt,
tosrc_xform,
edge_xform,
tosrc_path):
try:
fl = srcpt.file_line()
if srcpt.get_kind()==cs.point_kind.CALL_SITE:
print('---')
print('Call site at', fl)
print('Basic step_xform representations')
print(' - hash(tosrc_xform) = ', hash(tosrc_xform))
print(' - repr(tosrc_xform) = ', repr(tosrc_xform))
print(' - str(tosrc_xform) = ', str(tosrc_xform))
print('Performing a trivial xform_query equivalent to 5==5')
xfq_result = edge_xform.query(cs.xform_expr(5),
cs.xform_operator.EQUAL,
cs.xform_expr(5))
print(' - step_xform.query() result:', xfq_result)
print('Getting bounds on a trivial xform_expr equivalent to 5')
xfq_bounds_result = edge_xform.query_bounds(cs.xform_expr(5))
print(' - repr(xfq_bounds_result) = ', repr(xfq_bounds_result))
print(' - str(xfq_bounds_result) = ', str(xfq_bounds_result))
print(' - xfq_bounds_result.feasible() = ', xfq_bounds_result.feasible())
print(' - xfq_bounds_result.get_lower() = ', xfq_bounds_result.get_lower())
print(' - xfq_bounds_result.get_lower_suspect() = ', xfq_bounds_result.get_lower_suspect())
print(' - xfq_bounds_result.get_upper() = ', xfq_bounds_result.get_upper())
print(' - xfq_bounds_result.get_upper_suspect() = ', xfq_bounds_result.get_upper_suspect())
print(' - xfq_bounds_result.has_lower() = ', xfq_bounds_result.has_lower())
print(' - xfq_bounds_result.has_upper() = ', xfq_bounds_result.has_upper())
print(' - xfq_bounds_result.modified() = ', xfq_bounds_result.modified())
except cs.result as r:
pass
# We defined step_xform_illustrator.__init__ to suitably initialize the state, so
# just pass a new instance to cs.analysis.add_step_bottom_up_visitor()
cs.analysis.add_step_bottom_up_visitor(step_xform_illustrator())
step_xform Members¶
| Constructor | __init__() |
| Methods | __hash__(), __repr__(), __str__(), query(), query_bounds() |
step_xform Details¶
-
class
cs.step_xform¶ A program state transform along a path in the CFG.
-
__init__(other)¶ Parameters: other ( step_xform) –>>> step_xform(<cs.step_xform ...>) <cs.step_xform ...>
-
__hash__()¶ Get a hash value for a
step_xform.Return type: int --- Call site at (<cs.sfileinst C:\alex\test\apitest.cpp>, 6) Basic step_xform representations - hash(tosrc_xform) = 1922401584 - repr(tosrc_xform) = <cs.step_xform ...> - str(tosrc_xform) = <cs.step_xform ...> Performing a trivial xform_query equivalent to 5==5 - step_xform.query() result: redundant Getting bounds on a trivial xform_expr equivalent to 5 - repr(xfq_bounds_result) = <cs.xform_query_bounds_result [5, 5]> - str(xfq_bounds_result) = [5, 5] - xfq_bounds_result.feasible() = True - xfq_bounds_result.get_lower() = 5 - xfq_bounds_result.get_lower_suspect() = False - xfq_bounds_result.get_upper() = 5 - xfq_bounds_result.get_upper_suspect() = False - xfq_bounds_result.has_lower() = True - xfq_bounds_result.has_upper() = True - xfq_bounds_result.modified() = True
>>> hash(<cs.step_xform ...>) 69557648
-
__repr__()¶ Get a representation of a
step_xformobject that includes information useful for debugging.Return type: str Returns: The string representation. --- Call site at (<cs.sfileinst C:\alex\test\apitest.cpp>, 6) Basic step_xform representations - hash(tosrc_xform) = 1922401584 - repr(tosrc_xform) = <cs.step_xform ...> - str(tosrc_xform) = <cs.step_xform ...> Performing a trivial xform_query equivalent to 5==5 - step_xform.query() result: redundant Getting bounds on a trivial xform_expr equivalent to 5 - repr(xfq_bounds_result) = <cs.xform_query_bounds_result [5, 5]> - str(xfq_bounds_result) = [5, 5] - xfq_bounds_result.feasible() = True - xfq_bounds_result.get_lower() = 5 - xfq_bounds_result.get_lower_suspect() = False - xfq_bounds_result.get_upper() = 5 - xfq_bounds_result.get_upper_suspect() = False - xfq_bounds_result.has_lower() = True - xfq_bounds_result.has_upper() = True - xfq_bounds_result.modified() = True
>>> repr(<cs.step_xform ...>) '<cs.step_xform ...>'
-
__str__()¶ Get a simple string representation of a
step_xformobject.Return type: str Returns: The string representation. --- Call site at (<cs.sfileinst C:\alex\test\apitest.cpp>, 6) Basic step_xform representations - hash(tosrc_xform) = 1922401584 - repr(tosrc_xform) = <cs.step_xform ...> - str(tosrc_xform) = <cs.step_xform ...> Performing a trivial xform_query equivalent to 5==5 - step_xform.query() result: redundant Getting bounds on a trivial xform_expr equivalent to 5 - repr(xfq_bounds_result) = <cs.xform_query_bounds_result [5, 5]> - str(xfq_bounds_result) = [5, 5] - xfq_bounds_result.feasible() = True - xfq_bounds_result.get_lower() = 5 - xfq_bounds_result.get_lower_suspect() = False - xfq_bounds_result.get_upper() = 5 - xfq_bounds_result.get_upper_suspect() = False - xfq_bounds_result.has_lower() = True - xfq_bounds_result.has_upper() = True - xfq_bounds_result.modified() = True
>>> str(<cs.step_xform ...>) '<cs.step_xform ...>'
-
query(lhs, op, rhs)¶ Issue a query with respect to a program state transformation (
step_xform).Parameters: - lhs (
xform_expr) – The left hand side of the query expression. - op (
xform_operator) – The operator in the query expression. - rhs (
xform_expr) – The right hand side of the query expression.
Return type: Returns: The query result, as a
xform_query_result.Raises: result.ERROR_INVALID_OPERATORresult.ERROR_INVALID_ATTRIBUTEif the attribute inlhsorrhsdoes not exist.result.PATH_INFEASIBLEif the transform cannot occur.
--- Call site at (<cs.sfileinst C:\alex\test\apitest.cpp>, 6) Basic step_xform representations - hash(tosrc_xform) = 1922401584 - repr(tosrc_xform) = <cs.step_xform ...> - str(tosrc_xform) = <cs.step_xform ...> Performing a trivial xform_query equivalent to 5==5 - step_xform.query() result: redundant Getting bounds on a trivial xform_expr equivalent to 5 - repr(xfq_bounds_result) = <cs.xform_query_bounds_result [5, 5]> - str(xfq_bounds_result) = [5, 5] - xfq_bounds_result.feasible() = True - xfq_bounds_result.get_lower() = 5 - xfq_bounds_result.get_lower_suspect() = False - xfq_bounds_result.get_upper() = 5 - xfq_bounds_result.get_upper_suspect() = False - xfq_bounds_result.has_lower() = True - xfq_bounds_result.has_upper() = True - xfq_bounds_result.modified() = True
>>> v0 = xform_expr(-9) >>> v1 = xform_expr(64, 198) >>> <cs.step_xform ...>.query(v0, xform_operator.LESS_THAN_OR_EQUAL, v1) <cs.xform_query_result redundant>
- lhs (
-
query_bounds(expr)¶ Get bounds on an expression with respect to a program state transformation (
step_xform).Parameters: expr ( xform_expr) – The query expression.Return type: xform_query_bounds_resultReturns: The bounds, as an xform_query_bounds_result.--- Call site at (<cs.sfileinst C:\alex\test\apitest.cpp>, 6) Basic step_xform representations - hash(tosrc_xform) = 1922401584 - repr(tosrc_xform) = <cs.step_xform ...> - str(tosrc_xform) = <cs.step_xform ...> Performing a trivial xform_query equivalent to 5==5 - step_xform.query() result: redundant Getting bounds on a trivial xform_expr equivalent to 5 - repr(xfq_bounds_result) = <cs.xform_query_bounds_result [5, 5]> - str(xfq_bounds_result) = [5, 5] - xfq_bounds_result.feasible() = True - xfq_bounds_result.get_lower() = 5 - xfq_bounds_result.get_lower_suspect() = False - xfq_bounds_result.get_upper() = 5 - xfq_bounds_result.get_upper_suspect() = False - xfq_bounds_result.has_lower() = True - xfq_bounds_result.has_upper() = True - xfq_bounds_result.modified() = True
>>> v0 = xform_expr(128) >>> <cs.step_xform ...>.query_bounds(v0) <cs.xform_query_bounds_result [128, 128]>
-