ROSE  0.11.145.0
SourceLocations.h
1 #ifndef ROSE_BinaryAnalysis_SourceLocations_H
2 #define ROSE_BinaryAnalysis_SourceLocations_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/SourceLocation.h>
7 
8 #include <boost/filesystem.hpp>
9 #include <boost/serialization/access.hpp>
10 #include <Sawyer/IntervalMap.h>
11 #include <Sawyer/Map.h>
12 #include <Sawyer/Optional.h>
13 #include <Sawyer/Synchronization.h>
14 #include <set>
15 #include <string>
16 
17 namespace Rose {
18 namespace BinaryAnalysis {
19 
25 public:
28 
29 private:
30  mutable SAWYER_THREAD_TRAITS::Mutex mutex_; // protects the following data members
31  AddressToSource addrToSrc_;
32  SourceToAddress srcToAddr_;
33 
34 private:
35 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
36  friend class boost::serialization::access;
37 
38  template<class S>
39  void serialize(S &s, const unsigned /*version*/) {
40  s & BOOST_SERIALIZATION_NVP(addrToSrc_);
41  s & BOOST_SERIALIZATION_NVP(srcToAddr_);
42  }
43 #endif
44 
45 public:
50 
63  void insert(const SourceLocation&, rose_addr_t);
64  void insert(const SourceLocation&, const AddressInterval&);
65  void insert(const SourceLocation&, const AddressIntervalSet&);
75  void erase(const SourceLocation&, rose_addr_t);
76  void erase(const SourceLocation&, const AddressInterval&);
77  void erase(const SourceLocation&, const AddressIntervalSet&);
83  void erase(rose_addr_t);
84  void erase(const AddressInterval&);
85  void erase(const AddressIntervalSet&);
89  void erase(const SourceLocation&);
90 
92  void clear();
93 
98  void insertFromDebug(SgNode *ast);
99 
107  void fillHoles(size_t maxHoleSize = 64);
108 
112  SourceLocation get(rose_addr_t) const;
113  SourceLocation operator()(rose_addr_t va) const {
114  return get(va);
115  }
119  AddressIntervalSet get(const SourceLocation&) const;
120 
126  return firstAddress(loc);
127  }
131  std::set<boost::filesystem::path> allFileNames() const;
132 
140 
146  void printSrcToAddr(std::ostream&, const std::string &prefix = "") const;
147  void print(std::ostream&, const std::string &prefix = "") const;
153  void printAddrToSrc(std::ostream&, const std::string &prefix = "") const;
154 
155 private:
156  // Non-synchronized erasing of a link between source code and binary address.
157  void eraseNS(const SourceLocation&, rose_addr_t);
158  void eraseNS(rose_addr_t va);
159 };
160 
161 std::ostream& operator<<(std::ostream&, const SourceLocations&);
162 
163 } // namespace
164 } // namespace
165 
166 #endif
167 #endif
Sawyer::Optional< rose_addr_t > operator()(const SourceLocation &loc) const
Find the first address associated with a source location.
Information about a source location.
SourceLocation nextSourceLocation(const SourceLocation &current=SourceLocation()) const
Given a source location, return the next source location.
Bidirectional mapping between addresses and source locations.
SourceLocation operator()(rose_addr_t va) const
Find the source location for an address.
std::set< boost::filesystem::path > allFileNames() const
Get the list of all known source files.
SourceLocations()
Default constructor.
Main namespace for the ROSE library.
void clear()
Remove all links.
Sawyer::Optional< rose_addr_t > firstAddress(const SourceLocation &) const
Find the first address associated with a source location.
void fillHoles(size_t maxHoleSize=64)
Fill in small holes in the address space.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9846
void insertFromDebug(SgNode *ast)
Insert information from debug tables.
void print(std::ostream &, const std::string &prefix="") const
Print the source to address mapping.
void erase(const SourceLocation &, rose_addr_t)
Remove links between source and addresses.
void insert(const SourceLocation &, rose_addr_t)
Insert links between source and adresseses.
void printSrcToAddr(std::ostream &, const std::string &prefix="") const
Print the source to address mapping.
SourceLocations & operator=(const SourceLocations &)
Atomic copy.
void printAddrToSrc(std::ostream &, const std::string &prefix="") const
Print the address to source mapping.