1#ifndef ROSE_BinaryAnalysis_Reachability_H
2#define ROSE_BinaryAnalysis_Reachability_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/Address.h>
7#include <Rose/BinaryAnalysis/BasicTypes.h>
8#include <Rose/BinaryAnalysis/ByteOrder.h>
9#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
10#include <Rose/BitFlags.h>
12#include <Sawyer/CommandLine.h>
13#include <Sawyer/Map.h>
14#include <Sawyer/Message.h>
15#include <Sawyer/Tracker.h>
17#include <boost/serialization/access.hpp>
18#include <boost/serialization/split_member.hpp>
25namespace BinaryAnalysis {
106 std::vector<ReasonFlags> intrinsicReachability_;
107 std::vector<ReasonFlags> reachability_;
111#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
113 friend class boost::serialization::access;
116 void serialize(S &s,
const unsigned version) {
121 ASSERT_not_reachable(
"aborting due to unsupported old serialization file format");
123 s & BOOST_SERIALIZATION_NVP(intrinsicReachability_);
124 s & BOOST_SERIALIZATION_NVP(reachability_);
125 s & BOOST_SERIALIZATION_NVP(intrinsicReachability_);
126 s & BOOST_SERIALIZATION_NVP(reachability_);
188 Reason dfltArg,
const std::string &doc);
290 template<
class ForwardIterator>
380 static std::set<size_t>
397 static std::set<size_t>
Analysis that computes reachability of CFG vertices.
bool isIntrinsicallyReachable(size_t vertexId, ReasonFlags any=ReasonFlags(), ReasonFlags all=ReasonFlags(), ReasonFlags none=ReasonFlags()) const
Query whether a vertex is intrinsic reachable.
size_t intrinsicallyReachable(size_t vertexId, ReasonFlags how)
Change intrinsic reachability for one vertex.
std::vector< size_t > reachableVertices(ReasonFlags any=ReasonFlags(), ReasonFlags all=ReasonFlags(), ReasonFlags none=ReasonFlags()) const
Return a list of reachable vertex IDs.
const std::vector< ReasonFlags > & reachability() const
Query computed reachability.
size_t markStartingPoints(const Partitioner2::PartitionerConstPtr &)
Mark starting points as intrinsically reachable according to settings.
const std::vector< ReasonFlags > & intrinsicReachability() const
Query intrinsic reachability.
void clearReachability()
Clear all reachability.
ReasonFlags intrinsicReachability(size_t vertexId) const
Query intrinsic reachability.
size_t markEntryFunctions(const Partitioner2::PartitionerConstPtr &, ReasonFlags how=PROGRAM_ENTRY_POINT)
Mark entry points as intrinsically reachable.
Settings & settings()
Property: Settings that influence the analysis.
BitFlags< Reason, uint32_t > ReasonFlags
Bit flags for reachability.
void clear()
Clear previous results.
Reason
Predefined bit flags for why something is reachable.
@ USER_DEFINED_14
User-defined reason.
@ USER_DEFINED_7
User-defined reason.
@ USER_DEFINED_3
User-defined reason.
@ EXPORTED_FUNCTION
Vertex is an exported function.
@ IMPLICIT_FUNC_CONSTANT
Address appears during data-flow in some reachable function.
@ USER_DEFINED_10
User-defined reason.
@ USER_DEFINED_5
User-defined reason.
@ NOT_REACHABLE
Vertex is not reachable.
@ USER_DEFINED_8
User-defined reason.
@ USER_DEFINED_12
User-defined reason.
@ USER_DEFINED_9
User-defined reason.
@ USER_DEFINED_11
User-defined reason.
@ USER_DEFINED_4
User-defined reason.
@ USER_DEFINED_0
User-defined reason.
@ USER_DEFINED_13
User-defined reason.
@ USER_DEFINED_1
User-defined reason.
@ USER_DEFINED_15
User-defined reason.
@ USER_DEFINED_6
User-defined reason.
@ EXPLICIT_INSN_CONSTANT
Address appears as a constant in some reachable instruction.
@ USER_DEFINED_2
User-defined reason.
@ SIGNAL_HANDLER
Vertex is a signal handler.
@ PROGRAM_ENTRY_POINT
Vertex is a program entry point.
@ EXPLICIT_MEM_CONSTANT
Address appears in memory.
@ ASSUMED
Assumed reachable for cases when the analysis wasn't run.
size_t propagate(const Partitioner2::PartitionerConstPtr &, std::vector< size_t > &changedVertexIds)
Propagate intrinsic reachability through the graph.
size_t intrinsicallyReachable(ForwardIterator begin, ForwardIterator end, ReasonFlags how)
Change intrinsic reachabability for multiple vertices.
size_t markImplicitFunctionReferents(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &, ReasonFlags how=IMPLICIT_FUNC_CONSTANT)
Mark vertices whose addressses appear in a function.
static Sawyer::Message::Facility mlog
Facility for emitting diagnostics.
size_t markExportFunctions(const Partitioner2::PartitionerConstPtr &, ReasonFlags how=EXPORTED_FUNCTION)
Mark exported functions as intrinsically reachable.
static void initDiagnostics()
Initialize diagnostic streams.
size_t markExplicitInstructionReferents(const Partitioner2::PartitionerConstPtr &, const Partitioner2::BasicBlockPtr &, ReasonFlags how=EXPLICIT_INSN_CONSTANT)
Mark vertices whose addresses appear in instructions.
void settings(const Settings &s)
Property: Settings that influence the analysis.
static std::string reasonArgument(Reason)
Convert a reachability reason enum constant to a parsable reason name.
static Sawyer::CommandLine::SwitchGroup commandLineSwitches(Settings &settings)
Describes how to parse switches related to reachability.
static Sawyer::CommandLine::ValueParser::Ptr reasonParser(ReasonFlags &storage)
Creates a command-line parser for reachability reason names.
void iterate(const Partitioner2::PartitionerConstPtr &partitioner)
Iteratively propagate and mark.
static void insertReasonSwitch(Sawyer::CommandLine::SwitchGroup &, const std::string &switchName, ReasonFlags &storage, Reason dfltArg, const std::string &doc)
Insert a switch that takes a reason argument.
bool isReachable(size_t vertexId, ReasonFlags any=ReasonFlags(), ReasonFlags all=ReasonFlags(), ReasonFlags none=ReasonFlags()) const
Query whether a vertex is reachable.
static std::set< size_t > findExplicitInstructionReferents(const Partitioner2::PartitionerConstPtr &, const Partitioner2::BasicBlockPtr &)
Find all CFG vertices mentioned explicitly in a basic block.
size_t markSpecifiedVas(const Partitioner2::PartitionerConstPtr &, const std::vector< AddressInterval > &, ReasonFlags)
Mark all basic blocks with in the specified ranges.
const Settings & settings() const
Property: Settings that influence the analysis.
static std::string reasonDocumentation(Reason dflt)
Generate documentation for the command-line switches.
static std::set< size_t > findImplicitFunctionReferents(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Find all CFG vertices referenced from a function.
size_t propagate(const Partitioner2::PartitionerConstPtr &)
Propagate intrinsic reachability through the graph.
std::set< size_t > findExplicitMemoryReferents(const Partitioner2::PartitionerConstPtr &, const MemoryMapPtr &, size_t bytesPerWord=0, size_t alignment=0, ByteOrder::Endianness sex=ByteOrder::ORDER_UNSPECIFIED)
Find all CFG vertices mentioned in memory.
ReasonFlags reachability(size_t vertexId) const
Query computed reachability.
size_t markExplicitMemoryReferents(const Partitioner2::PartitionerConstPtr &, const MemoryMapPtr &, size_t bytesPerWord=0, size_t alignment=0, ByteOrder::Endianness sex=ByteOrder::ORDER_UNSPECIFIED, ReasonFlags how=EXPLICIT_MEM_CONSTANT)
Mark vertices whose addresses appear in memory.
size_t markStartingPoints(const Partitioner2::PartitionerConstPtr &, const MemoryMapPtr &)
Mark starting points as intrinsically reachable according to settings.
static std::string reasonArgumentDocumentation()
Documentation for the possible reason arguments.
static bool hasReasons(ReasonFlags reasons, ReasonFlags any=ReasonFlags(), ReasonFlags all=ReasonFlags(), ReasonFlags none=ReasonFlags())
Predicate to match reason flags.
Reachability()
Default constructor.
Stores a vector of enum bit flags.
A collection of related switch declarations.
Container associating values with keys.
Tracks whether something has been seen before.
Holds a value or nothing.
@ ORDER_UNSPECIFIED
Endianness is unspecified and unknown.
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for Function.
@ FATAL
Messages that indicate an abnormal situation from which the program was unable to recover.
Settings controlling the analysis.
ReasonFlags markingImplicitFunctionReferents
If not empty, run markImplicitFunctionReferents during iteration.
ReasonFlags markingExplicitMemoryReferents
If not empty, run markExplicitMemoryReferents at startup.
ReasonFlags markingExplicitInstructionReferents
If not empty, run markExplicitInstructionReferents during iteration.
ReasonFlags markingExportFunctions
If not empty, run markExportFunctions at startup.
bool precomputeImplicitFunctionReferents
Implicit function referents are precomputed in parallel.
ByteOrder::Endianness byteOrder
Byte order to use when reading constants from virtual memory.
rose_addr_t addressAlignment
Alignment when reading constants from virtual memory.
Sawyer::Optional< size_t > nThreads
Parallelism; 0 means system; unset means use global value.
size_t addressNBytes
Size of addresses when reading constants from virtual memory.
ReasonFlags markingEntryFunctions
If not empty, run markEntryFunctions at startup.