ROSE  0.11.145.0
FeasiblePath.h
1 #ifndef ROSE_BinaryAnalysis_FeasiblePath_H
2 #define ROSE_BinaryAnalysis_FeasiblePath_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics/SymbolicSemantics.h>
8 #include <Rose/BinaryAnalysis/SmtSolver.h>
9 #include <Rose/BinaryAnalysis/SymbolicExpressionParser.h>
10 #include <Rose/BinaryAnalysis/Partitioner2/CfgPath.h>
11 #include <Rose/Exception.h>
12 #include <Sawyer/CommandLine.h>
13 #include <Sawyer/Message.h>
14 #include <boost/filesystem/path.hpp>
15 #include <boost/logic/tribool.hpp>
16 
17 namespace Rose {
18 namespace BinaryAnalysis {
19 
23 class FeasiblePath {
25  // Types and public data members
27 public:
29  class Exception: public Rose::Exception {
30  public:
31  Exception(const std::string &what)
32  : Rose::Exception(what) {}
33  ~Exception() throw () {}
34  };
35 
37  enum SearchMode {
41  };
42 
47  };
48 
54  };
55 
57  enum IoMode { READ, WRITE };
58 
60  enum MayOrMust { MAY, MUST };
61 
63  typedef std::set<rose_addr_t> AddressSet;
64 
71  struct Expression {
73  std::string parsable;
76  Expression() {}
77  /*implicit*/ Expression(const std::string &parsable): parsable(parsable) {}
78  /*implicit*/ Expression(const SymbolicExpressionPtr &expr): expr(expr) {}
79 
80  void print(std::ostream&) const;
81  };
82 
84  struct Settings {
85  // Path feasibility
88  size_t maxVertexVisit;
89  size_t maxPathLength;
90  size_t maxCallDepth;
92  std::vector<Expression> assertions;
93  std::vector<std::string> assertionLocations;
94  std::vector<rose_addr_t> summarizeFunctions;
96  std::string solverName;
103  std::vector<rose_addr_t> ipRewrite;
105  size_t maxExprSize;
108  // Null dereferences
109  struct NullDeref {
110  bool check;
112  bool constOnly;
113  rose_addr_t minValid;
115  NullDeref()
116  : check(false), mode(MUST), constOnly(false), minValid(1024) {}
117  } nullDeref;
119  std::string exprParserDoc;
123  : searchMode(SEARCH_SINGLE_DFS), maxVertexVisit((size_t)-1), maxPathLength(200), maxCallDepth((size_t)-1),
124  maxRecursionDepth((size_t)-1), nonAddressIsFeasible(true), solverName("best"),
125  memoryParadigm(LIST_BASED_MEMORY), processFinalVertex(false), ignoreSemanticFailure(false),
126  kCycleCoefficient(0.0), edgeVisitOrder(VISIT_NATURAL), trackingCodeCoverage(true), maxExprSize(UNLIMITED),
127  traceSemantics(false) {}
128  };
129 
131  struct Statistics {
132  size_t nPathsExplored;
139  Statistics()
140  : nPathsExplored(0), maxVertexVisitHits(0), maxPathLengthHits(0), maxCallDepthHits(0), maxRecursionDepthHits(0) {}
141 
142  Statistics& operator+=(const Statistics&);
143  };
144 
147 
156 
158  struct VarDetail {
159  std::string registerName;
160  std::string firstAccessMode;
164  size_t memSize;
165  size_t memByteNumber;
168  VarDetail(): firstAccessInsn(NULL), memSize(0), memByteNumber(0) {}
169  std::string toString() const;
170  };
171 
174 
179  public:
180  enum Action {
183  };
184 
185  virtual ~PathProcessor() {}
186 
203  virtual Action found(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path,
205  const SmtSolverPtr &solver);
206 
240  virtual Action nullDeref(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn,
243 
283  virtual Action memoryIo(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn,
287  };
288 
293  rose_addr_t address = 0;
295  std::string name;
298  FunctionSummary();
299 
301  FunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgFuncVertex, uint64_t stackDelta);
302  };
303 
306 
311  public:
314  protected:
315  FunctionSummarizer() {}
316  public:
318  virtual void init(const FeasiblePath &analysis, FunctionSummary &summary /*in,out*/,
319  const Partitioner2::FunctionPtr &function,
320  Partitioner2::ControlFlowGraph::ConstVertexIterator cfgCallTarget) = 0;
321 
326  virtual bool process(const FeasiblePath &analysis, const FunctionSummary &summary,
328 
334  returnValue(const FeasiblePath &analysis, const FunctionSummary &summary,
336  };
337 
339  // Private data members
341 private:
342  Partitioner2::PartitionerConstPtr partitioner_; // binary analysis context, might be null
343  RegisterDictionaryPtr registers_; // registers augmented with "path" pseudo-register
344  RegisterDescriptor REG_RETURN_; // FIXME[Robb P Matzke 2016-10-11]: see source
345  Settings settings_;
346  FunctionSummaries functionSummaries_;
347  Partitioner2::CfgVertexMap vmap_; // relates CFG vertices to path vertices
348  Partitioner2::ControlFlowGraph paths_; // all possible paths, feasible or otherwise
349  Partitioner2::CfgConstVertexSet pathsBeginVertices_;// vertices of paths_ where searching starts
350  Partitioner2::CfgConstVertexSet pathsEndVertices_; // vertices of paths_ where searching stops
351  bool isDirectedSearch_ = true; // use pathsEndVertices_?
352  Partitioner2::CfgConstEdgeSet cfgAvoidEdges_; // CFG edges to avoid
353  Partitioner2::CfgConstVertexSet cfgEndAvoidVertices_;// CFG end-of-path and other avoidance vertices
354  FunctionSummarizer::Ptr functionSummarizer_; // user-defined function for handling function summaries
355  InstructionSemantics::BaseSemantics::StatePtr initialState_; // set by setInitialState.
356  static Sawyer::Attribute::Id POST_STATE; // stores semantic state after executing the insns for a vertex
357  static Sawyer::Attribute::Id POST_INSN_LENGTH; // path length in instructions at end of vertex
358  static Sawyer::Attribute::Id EFFECTIVE_K; // (double) effective maximimum path length
359 
360  mutable SAWYER_THREAD_TRAITS::Mutex statsMutex_; // protects the following data member
361  Statistics stats_; // statistical results of the analysis
362 
364  // Construction, destruction
366 public:
368  FeasiblePath();
369  virtual ~FeasiblePath();
370 
372  void reset();
373 
378  SAWYER_THREAD_TRAITS::LockGuard lock(statsMutex_);
379  stats_ = Statistics();
380  }
381 
383  static void initDiagnostics();
384 
385 
387  // Settings affecting behavior
389 public:
393  const Settings& settings() const { return settings_; }
394  Settings& settings() { return settings_; }
395  void settings(const Settings &s) { settings_ = s; }
403 
405  static std::string expressionDocumentation();
406 
407 
409  // Overridable processing functions
411 public:
419 
426  virtual void
428  const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsBeginVertex);
429 
434  virtual void
436  const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex);
437 
441  virtual void
442  processIndeterminateBlock(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex,
444  size_t pathInsnIndex);
445 
449  virtual void
450  processFunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex,
452  size_t pathInsnIndex);
453 
457  virtual void
459  const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex,
460  size_t pathInsnIndex);
461 
463  virtual bool
464  shouldSummarizeCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex,
466  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget);
467 
469  virtual bool
470  shouldInline(const Partitioner2::CfgPath &path, const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget);
471 
480  FunctionSummarizer::Ptr functionSummarizer() const { return functionSummarizer_; }
481  void functionSummarizer(const FunctionSummarizer::Ptr &f) { functionSummarizer_ = f; }
484  // Utilities
487 public:
489  Partitioner2::ControlFlowGraph::ConstVertexIterator
490  pathToCfg(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex) const;
491 
495 
501 
504 
506  bool isFunctionCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator&) const;
507 
509  void printPathVertex(std::ostream &out, const Partitioner2::ControlFlowGraph::Vertex &pathVertex,
510  size_t &insnIdx /*in,out*/) const;
511 
515  void printPath(std::ostream &out, const Partitioner2::CfgPath&) const;
516 
522  const Partitioner2::ControlFlowGraph::ConstVertexIterator &beginVertex,
523  const Partitioner2::CfgConstVertexSet &endVertices);
524 
526  // Functions for describing the search space
528 public:
529 
538  void
540  const Partitioner2::CfgConstVertexSet &cfgBeginVertices,
541  const Partitioner2::CfgConstVertexSet &cfgEndVertices,
544  void
546  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgBeginVertex,
547  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgEndVertex,
550  void
552  const Partitioner2::CfgConstVertexSet &cfgBeginVertices,
555  void
557  const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgBeginVertex,
567  bool isDirectedSearch() const {
568  return isDirectedSearch_;
569  }
570 
572  // Functions for searching for paths
574 public:
579  void depthFirstSearch(PathProcessor &pathProcessor);
580 
581 
583  // Functions for getting the results
585 public:
591 
595  const FunctionSummaries& functionSummaries() const {
596  return functionSummaries_;
597  }
598 
603  const FunctionSummary& functionSummary(rose_addr_t entryVa) const;
604 
606  const VarDetail& varDetail(const InstructionSemantics::BaseSemantics::StatePtr&, const std::string &varName) const;
607 
609  const VarDetails& varDetails(const InstructionSemantics::BaseSemantics::StatePtr&) const;
610 
613 
616 
622  double pathEffectiveK(const Partitioner2::CfgPath&) const;
623 
630  static size_t pathLength(const Partitioner2::CfgPath&, int position = -1);
631 
638  SAWYER_THREAD_TRAITS::LockGuard lock(statsMutex_);
639  return stats_;
640  }
641 
643  // Private supporting functions
645 private:
646  // Check that analysis settings are valid, or throw an exception.
647  void checkSettings() const;
648 
649  static rose_addr_t virtualAddress(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex);
650 
651  void insertCallSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsCallSite,
653  const Partitioner2::ControlFlowGraph::ConstEdgeIterator &cfgCallEdge);
654 
655  boost::filesystem::path emitPathGraph(size_t callId, size_t graphId); // emit paths graph to "rose-debug" directory
656 
657  // Pop an edge (or more) from the path and follow some other edge. Also, adjust the SMT solver's stack in a similar
658  // way. The SMT solver will have an initial state, plus one pushed state per edge of the path.
659  void backtrack(Partitioner2::CfgPath &path /*in,out*/, const SmtSolverPtr&);
660 
661  // Process one edge of a path to find any path constraints. When called, the cpu's current state should be the virtual
662  // machine state at it exists just prior to executing the target vertex of the specified edge.
663  //
664  // Returns a null pointer if the edge's assertion is trivially unsatisfiable, such as when the edge points to a basic block
665  // whose address doesn't match the contents of the instruction pointer register after executing the edge's source
666  // block. Otherwise, returns a symbolic expression which must be tree if the edge is feasible. For trivially feasible
667  // edges, the return value is the constant 1 (one bit wide; i.e., true).
668  SymbolicExpressionPtr pathEdgeConstraint(const Partitioner2::ControlFlowGraph::ConstEdgeIterator &pathEdge,
670 
671  // Parse the expression if it's a parsable string, otherwise return the expression as is. */
672  Expression parseExpression(Expression, const std::string &where, SymbolicExpressionParser&) const;
673 
674  SymbolicExpressionPtr expandExpression(const Expression&, const SymbolicExpressionParser&);
675 
676  // Based on the last vertex of the path, insert user-specified assertions into the SMT solver.
677  void insertAssertions(const SmtSolverPtr&, const Partitioner2::CfgPath&,
678  const std::vector<Expression> &assertions, bool atEndOfPath, const SymbolicExpressionParser&);
679 
680  // Size of vertex. How much of "k" does this vertex consume?
681  static size_t vertexSize(const Partitioner2::ControlFlowGraph::ConstVertexIterator&);
682 
683  // Information needed for adding user-supplied assertions to the solver.
684  struct Substitutions {
685  SymbolicExpressionParser exprParser;
686  std::vector<Expression> assertions;
689  };
690 
691  // Insert the edge assertion and any applicable user assertions (after delayed expansion of the expressions' register
692  // and memory references), and run the solver, returning its result.
694  solvePathConstraints(const SmtSolverPtr&, const Partitioner2::CfgPath&, const SymbolicExpressionPtr &edgeAssertion,
695  const Substitutions&, bool atEndOfPath);
696 
697  // Mark vertex as being reached
698  void markAsReached(const Partitioner2::ControlFlowGraph::ConstVertexIterator&);
699 
700  // Top-level info for debugging
701  void dfsDebugHeader(Sawyer::Message::Stream &trace, Sawyer::Message::Stream &debug, size_t callId, size_t graphId);
702 
703  // Top-level info for debugging a path.
704  void dfsDebugCurrentPath(Sawyer::Message::Stream&, const Partitioner2::CfgPath&, const SmtSolverPtr&, size_t effectiveK);
705 
706  // Prepare substitutions for registers and memory based on user-supplied symbolic expressions.
707  Substitutions parseSubstitutions();
708 
709  // Substitute registers and memory values into user-supplied symbolic expressions.
710  void makeSubstitutions(const Substitutions&, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr&);
711 
712  // Create an SMT solver. It will have an initial state plus, eventually, a transaction for each path edge.
713  SmtSolverPtr createSmtSolver();
714 
715  // The parts of the instruction semantics framework
716  struct Semantics {
720  };
721 
722  // Create the parts of the instruction semantics framework.
723  Semantics createSemantics(const Partitioner2::CfgPath&, PathProcessor&, const SmtSolverPtr&);
724 
725  // Convert a position to an index. Negative positions measure from the end of the sequence so that -1 refers to the last
726  // element, -2 to the second-to-last element, etc. Non-negative positions are the same thing as an index. Returns nothing
727  // if the position is out of range.
728  static Sawyer::Optional<size_t> positionToIndex(int position, size_t nElmts);
729 
730  // Obtain the incoming state for the specified path vertex. This is a pointer to the state, so copy it if you make changes.
731  // The incoming state for the first vertex is the specified initial state.
733  incomingState(const Partitioner2::CfgPath&, int position, const InstructionSemantics::BaseSemantics::StatePtr &initialState);
734 
735  // Number of steps (e.g., instructions) up to but not including the specified path vertex.
736  size_t incomingStepCount(const Partitioner2::CfgPath&, int position);
737 
738  // Number of steps (e.g., instructions) up to and including the specified path vertex.
739  size_t outgoingStepCount(const Partitioner2::CfgPath&, int position);
740 
741  // Evaluate semantics up to and including the specified path vertex, returning the outgoing state for that vertex. If
742  // semantics fails, then returns a null state pointer.
743  InstructionSemantics::BaseSemantics::StatePtr evaluate(Partitioner2::CfgPath&, int position, const Semantics&);
744 
745  // Check whether the last vertex of the path is feasible. Returns true if provably feasible, false if provably infeasible,
746  // or indeterminate if not provable one way or the other.
747  boost::logic::tribool isFeasible(Partitioner2::CfgPath&, const Substitutions&, const Semantics&, const SmtSolverPtr&);
748 
749  // Safely call the path processor's "found" action for the path's final vertex and return its value.
750  PathProcessor::Action callPathProcessorFound(PathProcessor&, Partitioner2::CfgPath&, const Semantics&, const SmtSolverPtr&);
751 
752  // Given an effective K value, adjust it based on how often the last vertex of the path has been visited. Returns a new
753  // effective K. As a special case, the new K is zero if the last vertex has been visited too often.
754  double adjustEffectiveK(Partitioner2::CfgPath&, double oldK);
755 
756  // Given a path that ends with a function call, inline the function or a summary of the function, adjusting the paths_
757  // control flow graph.
758  void summarizeOrInline(Partitioner2::CfgPath&, const Semantics&);
759 };
760 
761 } // namespace
762 } // namespace
763 
764 std::ostream& operator<<(std::ostream&, const Rose::BinaryAnalysis::FeasiblePath::Expression&);
765 
766 // Convert string to feasible path expression during command-line parsing
767 namespace Sawyer {
768  namespace CommandLine {
769  template<>
770  struct LexicalCast<Rose::BinaryAnalysis::FeasiblePath::Expression> {
771  static Rose::BinaryAnalysis::FeasiblePath::Expression convert(const std::string &src) {
773  }
774  };
775  }
776 }
777 
778 #endif
779 #endif
std::string firstAccessMode
How was variable first accessed ("read" or "write").
Definition: FeasiblePath.h:160
bool traceSemantics
Trace all instruction semantics operations.
Definition: FeasiblePath.h:106
size_t maxPathLengthHits
Number of times settings.maxPathLength was hit (effective K).
Definition: FeasiblePath.h:134
std::vector< rose_addr_t > summarizeFunctions
Functions to always summarize.
Definition: FeasiblePath.h:94
Sawyer::Container::Map< rose_addr_t, FunctionSummary > FunctionSummaries
Summaries for multiple functions.
Definition: FeasiblePath.h:305
MayOrMust mode
Check for addrs that may or must be null.
Definition: FeasiblePath.h:111
EdgeVisitOrder edgeVisitOrder
Order in which to visit edges.
Definition: FeasiblePath.h:101
size_t maxCallDepthHits
Number of times settings.maxCallDepth was hit.
Definition: FeasiblePath.h:135
size_t nPathsExplored
Number of paths explored.
Definition: FeasiblePath.h:132
rose_addr_t address
Address of summarized function.
Definition: FeasiblePath.h:293
SemanticMemoryParadigm memoryParadigm
Type of memory state when there's a choice to be made.
Definition: FeasiblePath.h:97
virtual void setInitialState(const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsBeginVertex)
Initialize state for first vertex of path.
bool trackingCodeCoverage
If set, track which block addresses are reached.
Definition: FeasiblePath.h:102
static size_t pathLength(const Partitioner2::CfgPath &, int position=-1)
Total length of path up to and including the specified vertex.
InstructionSemantics::BaseSemantics::StatePtr initialState() const
Get the initial state before the first path vertex.
SymbolicExpressionPtr expr
Symbolic expression.
Definition: FeasiblePath.h:74
double pathEffectiveK(const Partitioner2::CfgPath &) const
Effective maximum path length.
void printPathVertex(std::ostream &out, const Partitioner2::ControlFlowGraph::Vertex &pathVertex, size_t &insnIdx) const
Print one vertex of a path for debugging.
std::string parsable
String to be parsed as an expression.
Definition: FeasiblePath.h:73
Information stored per V_USER_DEFINED path vertex.
Definition: FeasiblePath.h:292
Sawyer::Container::Map< std::string, FeasiblePath::VarDetail > VarDetails
Variable detail by name.
Definition: FeasiblePath.h:173
MayOrMust
Types of comparisons.
Definition: FeasiblePath.h:60
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
void depthFirstSearch(PathProcessor &pathProcessor)
Find all feasible paths.
Base class for machine instructions.
Sawyer::Optional< rose_addr_t > returnFrom
This variable is the return value from the specified function.
Definition: FeasiblePath.h:166
Collection of streams.
Definition: Message.h:1606
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to symbolic RISC operations.
FeasiblePath()
Constructs a new feasible path analyzer.
SearchMode
How to search for paths.
Definition: FeasiblePath.h:37
static InstructionSemantics::BaseSemantics::StatePtr pathPostState(const Partitioner2::CfgPath &, size_t vertexIdx)
Get the state at the end of the specified vertex.
virtual void processVertex(const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex, size_t pathInsnIndex)
Process one vertex.
const VarDetails & varDetails(const InstructionSemantics::BaseSemantics::StatePtr &) const
Details about all variables by name.
RegisterDescriptor REG_PATH
Descriptor of path pseudo-registers.
Definition: FeasiblePath.h:155
virtual Action nullDeref(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &cpu, const SmtSolverPtr &solver, IoMode ioMode, const InstructionSemantics::BaseSemantics::SValuePtr &addr)
Function invoked whenever a null pointer dereference is detected.
size_t maxRecursionDepthHits
Number of times settings.maxRecursionDepth was hit.
Definition: FeasiblePath.h:136
std::string name
Name of summarized function.
Definition: FeasiblePath.h:295
Sawyer::Optional< size_t > firstAccessIdx
Instruction position in path where this var was first read.
Definition: FeasiblePath.h:162
A collection of related switch declarations.
Sawyer::Container::Map< rose_addr_t, size_t > reachedBlockVas
Number of times each basic block was reached.
Definition: FeasiblePath.h:137
Sawyer::Optional< boost::chrono::duration< double > > smtTimeout
Max seconds allowed per SMT solve call.
Definition: FeasiblePath.h:104
SymbolicExpressionPtr memAddress
Address where variable is located.
Definition: FeasiblePath.h:163
Main namespace for the ROSE library.
const size_t UNLIMITED(static_cast< size_t >(-1))
Effictively unlimited size.
Satisfiable
Satisfiability constants.
Definition: SmtSolver.h:87
size_t maxCallDepth
Max length of path in terms of function calls.
Definition: FeasiblePath.h:90
size_t maxExprSize
Maximum symbolic expression size before replacement.
Definition: FeasiblePath.h:105
struct Rose::BinaryAnalysis::FeasiblePath::Settings::NullDeref nullDeref
Settings for null-dereference analysis.
Blast everything at once to the SMT solver.
Definition: FeasiblePath.h:40
virtual void processFunctionSummary(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathsVertex, const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process a function summary vertex.
Feasible path analysis.
Definition: FeasiblePath.h:23
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
Name space for the entire library.
Definition: FeasiblePath.h:767
std::vector< std::string > assertionLocations
Locations at which "constraints" are checked.
Definition: FeasiblePath.h:93
size_t maxVertexVisitHits
Number of times settings.maxVertexVisit was hit.
Definition: FeasiblePath.h:133
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
static const int64_t INVALID_STACK_DELTA
Represents an invalid stack delta.
const FunctionSummaries & functionSummaries() const
Function summary information.
Definition: FeasiblePath.h:595
Partitioner2::CfgConstVertexSet cfgToPaths(const Partitioner2::CfgConstVertexSet &) const
Convert CFG vertices to path vertices.
virtual bool shouldInline(const Partitioner2::CfgPath &path, const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget)
Determines whether a function call should be inlined.
std::vector< rose_addr_t > ipRewrite
An even number of from,to pairs for rewriting the insn ptr reg.
Definition: FeasiblePath.h:103
virtual InstructionSemantics::BaseSemantics::DispatcherPtr buildVirtualCpu(const Partitioner2::PartitionerConstPtr &, const Partitioner2::CfgPath *, PathProcessor *, const SmtSolverPtr &)
Create the virtual CPU.
static std::string expressionDocumentation()
Documentation for the symbolic expression parser.
void settings(const Settings &s)
Property: Settings used by this analysis.
Definition: FeasiblePath.h:395
size_t maxPathLength
Limit path length in terms of number of instructions.
Definition: FeasiblePath.h:89
bool constOnly
If true, check only constants or sets of constants.
Definition: FeasiblePath.h:112
Base class for callbacks for function summaries.
Definition: FeasiblePath.h:310
void setSearchBoundary(const Partitioner2::PartitionerConstPtr &partitioner, const Partitioner2::CfgConstVertexSet &cfgBeginVertices, const Partitioner2::CfgConstVertexSet &cfgEndVertices, const Partitioner2::CfgConstVertexSet &cfgAvoidVertices=Partitioner2::CfgConstVertexSet(), const Partitioner2::CfgConstEdgeSet &cfgAvoidEdges=Partitioner2::CfgConstEdgeSet())
Specify search boundary.
AddressIntervalSet location
Location where constraint applies.
Definition: FeasiblePath.h:72
virtual Action found(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, const SmtSolverPtr &solver)
Function invoked whenever a complete path is found.
Visit edges in reverse of the natural order.
Definition: FeasiblePath.h:52
bool isDirectedSearch() const
Property: Whether search is directed or not.
Definition: FeasiblePath.h:567
virtual Action memoryIo(const FeasiblePath &analyzer, const Partitioner2::CfgPath &path, SgAsmInstruction *insn, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &cpu, const SmtSolverPtr &solver, IoMode ioMode, const InstructionSemantics::BaseSemantics::SValuePtr &addr, const InstructionSemantics::BaseSemantics::SValuePtr &value)
Function invoked every time a memory reference occurs.
FunctionSummary()
Construct empty function summary.
bool nonAddressIsFeasible
Indeterminate/undiscovered vertices are feasible?
Definition: FeasiblePath.h:95
size_t maxVertexVisit
Max times to visit a particular vertex in one path.
Definition: FeasiblePath.h:88
Describes (part of) a physical CPU register.
size_t maxRecursionDepth
Max path length in terms of recursive function calls.
Definition: FeasiblePath.h:91
void reset()
Reset to initial state without changing settings.
A path through a control flow graph.
Definition: CfgPath.h:17
virtual void processIndeterminateBlock(const Partitioner2::ControlFlowGraph::ConstVertexIterator &vertex, const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process an indeterminate block.
rose_addr_t minValid
Minnimum address that is not treated as a null dereference.
Definition: FeasiblePath.h:113
Information about a variable seen on a path.
Definition: FeasiblePath.h:158
FunctionSummarizer::Ptr functionSummarizer() const
Property: Function summary handling.
Definition: FeasiblePath.h:480
Exception for errors specific to feasible path analysis.
Definition: FeasiblePath.h:29
virtual bool shouldSummarizeCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex, const Partitioner2::ControlFlowGraph &cfg, const Partitioner2::ControlFlowGraph::ConstVertexIterator &cfgCallTarget)
Determines whether a function call should be summarized instead of inlined.
Partitioner2::PartitionerConstPtr partitioner() const
Property: Partitioner currently in use.
bool isFunctionCall(const Partitioner2::ControlFlowGraph::ConstVertexIterator &) const
True if vertex is a function call.
bool ignoreSemanticFailure
Whether to ignore instructions with no semantic info.
Definition: FeasiblePath.h:99
const VarDetail & varDetail(const InstructionSemantics::BaseSemantics::StatePtr &, const std::string &varName) const
Details about a variable.
SearchMode searchMode
Method to use when searching for feasible paths.
Definition: FeasiblePath.h:86
size_t Id
Attribute identification.
Definition: Attribute.h:140
bool pathEndsWithFunctionCall(const Partitioner2::CfgPath &) const
True if path ends with a function call.
IoMode
Read or write operation.
Definition: FeasiblePath.h:57
void printPath(std::ostream &out, const Partitioner2::CfgPath &) const
Print the path to the specified output stream.
Statistics statistics() const
Cumulative statistics about prior analyses.
Definition: FeasiblePath.h:637
void resetStatistics()
Reset only statistics.
Definition: FeasiblePath.h:377
std::set< rose_addr_t > AddressSet
Set of basic block addresses.
Definition: FeasiblePath.h:63
Parses symbolic expressions from text.
const Settings & settings() const
Property: Settings used by this analysis.
Definition: FeasiblePath.h:393
size_t memByteNumber
Byte number for memory access.
Definition: FeasiblePath.h:165
int64_t stackDelta
Stack delta for summarized function.
Definition: FeasiblePath.h:294
Base class for reference counted objects.
Definition: SharedObject.h:64
double kCycleCoefficient
Coefficient for adjusting maxPathLengh during CFG cycles.
Definition: FeasiblePath.h:100
static Sawyer::CommandLine::SwitchGroup commandLineSwitches(Settings &settings)
Describe command-line switches.
Sawyer::SharedPointer< FunctionSummarizer > Ptr
Reference counting pointer.
Definition: FeasiblePath.h:313
static Sawyer::Message::Facility mlog
Diagnostic output.
Definition: FeasiblePath.h:146
virtual bool process(const FeasiblePath &analysis, const FunctionSummary &summary, const InstructionSemantics::SymbolicSemantics::RiscOperatorsPtr &ops)=0
Invoked when the analysis traverses the summary.
bool isAnyEndpointReachable(const Partitioner2::ControlFlowGraph &cfg, const Partitioner2::ControlFlowGraph::ConstVertexIterator &beginVertex, const Partitioner2::CfgConstVertexSet &endVertices)
Determine whether any ending vertex is reachable.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
Partitioner2::ControlFlowGraph::ConstVertexIterator pathToCfg(const Partitioner2::ControlFlowGraph::ConstVertexIterator &pathVertex) const
Convert path vertex to a CFG vertex.
Visit edges in their natural, forward order.
Definition: FeasiblePath.h:51
virtual InstructionSemantics::SymbolicSemantics::SValuePtr returnValue(const FeasiblePath &analysis, const FunctionSummary &summary, const InstructionSemantics::SymbolicSemantics::RiscOperatorsPtr &ops)=0
Return value for function.
const FunctionSummary & functionSummary(rose_addr_t entryVa) const
Function summary information.
Converts text to messages.
Definition: Message.h:1396
virtual void init(const FeasiblePath &analysis, FunctionSummary &summary, const Partitioner2::FunctionPtr &function, Partitioner2::ControlFlowGraph::ConstVertexIterator cfgCallTarget)=0
Invoked when a new summary is created.
Statistics from path searching.
Definition: FeasiblePath.h:131
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
std::string solverName
Type of SMT solver.
Definition: FeasiblePath.h:96
EdgeVisitOrder
Edge visitation order.
Definition: FeasiblePath.h:50
void functionSummarizer(const FunctionSummarizer::Ptr &f)
Property: Function summary handling.
Definition: FeasiblePath.h:481
Settings & settings()
Property: Settings used by this analysis.
Definition: FeasiblePath.h:394
size_t memSize
Size of total memory access in bytes.
Definition: FeasiblePath.h:164
std::string exprParserDoc
String documenting how expressions are parsed, empty for default.
Definition: FeasiblePath.h:119
bool processFinalVertex
Whether to process the last vertex of the path.
Definition: FeasiblePath.h:98
SgAsmInstruction * firstAccessInsn
Instruction address where this var was first read.
Definition: FeasiblePath.h:161
virtual void processBasicBlock(const Partitioner2::BasicBlockPtr &bblock, const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu, size_t pathInsnIndex)
Process instructions for one basic block on the specified virtual CPU.
Settings that control this analysis.
Definition: FeasiblePath.h:84
static void initDiagnostics()
Initialize diagnostic output.
bool check
If true, look for null dereferences along the paths.
Definition: FeasiblePath.h:110
Sawyer::Optional< rose_addr_t > initialStackPtr
Concrete value to use for stack pointer register initial value.
Definition: FeasiblePath.h:87
SemanticMemoryParadigm
Organization of semantic memory.
Definition: FeasiblePath.h:44
std::vector< Expression > assertions
Constraints to be satisfied at some point along the path.
Definition: FeasiblePath.h:92