ROSE  0.11.109.0
Debugger/Base.h
1 #ifndef ROSE_BinaryAnalysis_Debugger_Base_H
2 #define ROSE_BinaryAnalysis_Debugger_Base_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 #include <Rose/BinaryAnalysis/Debugger/BasicTypes.h>
6 
7 #include <Rose/BinaryAnalysis/Debugger/ThreadId.h>
8 
9 #include <Sawyer/SharedObject.h>
10 #include <Sawyer/Trace.h>
11 
12 namespace Rose {
13 namespace BinaryAnalysis {
14 namespace Debugger {
15 
19 class Base: public Sawyer::SharedObject {
20 public:
22  using Ptr = Debugger::Ptr;
23 
24 protected:
25  Disassembler::BasePtr disassembler_; // how to disassemble instructions
26 
27 protected:
28  Base();
29 
30  // Debuggers are not copyable
31  Base(const Base&) = delete;
32  Base(Base&&) = delete;
33  Base& operator=(const Base&) = delete;
34  Base& operator=(Base&&) = delete;
35 
36 public:
37  virtual ~Base();
38 
39 public:
43  virtual bool isAttached() = 0;
44 
49  virtual void detach() = 0;
50 
54  virtual void terminate() = 0;
55 
59  virtual std::vector<ThreadId> threadIds() = 0;
60 
67  virtual void executionAddress(ThreadId, rose_addr_t);
68  virtual rose_addr_t executionAddress(ThreadId);
72  virtual void setBreakPoint(const AddressInterval&) = 0;
73 
75  virtual void clearBreakPoint(const AddressInterval&) = 0;
76 
78  virtual void clearBreakPoints() = 0;
79 
81  virtual void singleStep(ThreadId) = 0;
82 
84  virtual void runToBreakPoint(ThreadId) = 0;
85 
95 
100  virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value) = 0;
106  virtual size_t readMemory(rose_addr_t va, size_t nBytes, uint8_t *buffer) = 0;
107 
111  virtual std::vector<uint8_t> readMemory(rose_addr_t va, size_t nBytes) = 0;
112 
118  virtual Sawyer::Container::BitVector readMemory(rose_addr_t va, size_t nBytes, ByteOrder::Endianness order) = 0;
119 
123  virtual size_t writeMemory(rose_addr_t va, size_t nBytes, const uint8_t *bytes) = 0;
124 
128  template<typename T>
129  void writeMemory(rose_addr_t va, const T &value) {
130  size_t n = writeMemory(va, sizeof(T), (const uint8_t*)&value);
131  ASSERT_always_require(n == sizeof(T));
132  }
133 
139  virtual std::string readCString(rose_addr_t va, size_t maxBytes = UNLIMITED);
140 
142  virtual bool isTerminated() = 0;
143 
145  virtual std::string howTerminated() = 0;
146 
149 
152 
155 
161  template<class Filter>
164  while (!isTerminated()) {
165  rose_addr_t va = executionAddress(tid);
166  FilterAction action = filter(va);
167  if (action.isClear(FilterActionFlag::REJECT))
168  retval.append(va);
169  if (action.isSet(FilterActionFlag::STOP))
170  return retval;
171  singleStep(tid);
172  }
173  return retval;
174  }
175 };
176 
177 } // namespace
178 } // namespace
179 } // namespace
180 
181 #endif
182 #endif
Records and replays traces.
Definition: Trace.h:262
void append(const Label &label)
Append a label to a trace.
Definition: Trace.h:476
Sawyer::Container::Trace< rose_addr_t > trace(ThreadId tid, Filter &filter)
Run the program and return an execution trace.
virtual void executionAddress(ThreadId, rose_addr_t)
Execution address.
virtual void setBreakPoint(const AddressInterval &)=0
Set breakpoints.
void writeMemory(rose_addr_t va, const T &value)
Write subordinate memory.
bool isSet(Enum e) const
Test whether a bit is set.
Main namespace for the ROSE library.
Stores a vector of enum bit flags.
Definition: Rose/BitFlags.h:59
virtual Sawyer::Container::Trace< rose_addr_t > trace()
Run the program and return an execution trace.
const size_t UNLIMITED(static_cast< size_t >(-1))
Effictively unlimited size.
Reject the current address, not appending it to the trace.
virtual std::string howTerminated()=0
String describing how the subordinate process terminated.
virtual bool isAttached()=0
Tests whether this debugger is attached to a specimen.
virtual Disassembler::BasePtr disassembler()
Disassembler.
virtual void singleStep(ThreadId)=0
Execute one machine instruction.
Abort tracing, either appending or rejecting the current address.
Describes (part of) a physical CPU register.
virtual std::string readCString(rose_addr_t va, size_t maxBytes=UNLIMITED)
Read C-style NUL-terminated string from subordinate.
virtual size_t readMemory(rose_addr_t va, size_t nBytes, uint8_t *buffer)=0
Read subordinate memory.
virtual bool isTerminated()=0
Returns true if the subordinate terminated.
virtual void detach()=0
Detach from a specimen.
bool isClear(Enum e) const
Test whether a bit is clear.
virtual Sawyer::Container::BitVector readRegister(ThreadId, RegisterDescriptor)=0
Read subordinate register.
Base class for reference counted objects.
Definition: SharedObject.h:64
virtual void terminate()=0
Terminate the specimen.
virtual void clearBreakPoints()=0
Remove all breakpoints.
virtual RegisterDictionaryPtr registerDictionary()
Available registers.
virtual size_t writeMemory(rose_addr_t va, size_t nBytes, const uint8_t *bytes)=0
Writes some bytes to subordinate memory.
virtual void writeRegister(ThreadId, RegisterDescriptor, const Sawyer::Container::BitVector &)=0
Write subordinate register.
virtual std::vector< ThreadId > threadIds()=0
List of subordinate threads.
virtual void runToBreakPoint(ThreadId)=0
Run until the next breakpoint is reached.
Base class for debuggers.
Definition: Debugger/Base.h:19
virtual void clearBreakPoint(const AddressInterval &)=0
Remove breakpoints.