ROSE 0.11.145.192
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/AddressInterval.h>
8#include <Rose/BinaryAnalysis/BasicTypes.h>
9#include <Rose/BinaryAnalysis/ByteOrder.h>
10#include <Rose/BinaryAnalysis/Debugger/ThreadId.h>
11#include <Rose/Constants.h>
12
13#include <Sawyer/BitVector.h>
14#include <Sawyer/SharedObject.h>
15#include <Sawyer/Trace.h>
16
17namespace Rose {
18namespace BinaryAnalysis {
19namespace Debugger {
20
25public:
28
29protected:
30 Disassembler::BasePtr disassembler_; // how to disassemble instructions
31
32protected:
33 Base();
34
35 // Debuggers are not copyable
36 Base(const Base&) = delete;
37 Base(Base&&) = delete;
38 Base& operator=(const Base&) = delete;
39 Base& operator=(Base&&) = delete;
40
41public:
42 virtual ~Base();
43
45 // Properties
47public:
48
51
53 // Process state
55public:
56
60 virtual bool isAttached() = 0;
61
66 virtual void detach() = 0;
67
71 virtual void terminate() = 0;
72
74 virtual bool isTerminated() = 0;
75
77 virtual std::string howTerminated() = 0;
78
80 // Threads
82public:
83
87 virtual std::vector<ThreadId> threadIds() = 0;
88
90 // Break points
92public:
93
95 virtual void setBreakPoint(const AddressInterval&) = 0;
96
98 virtual void clearBreakPoint(const AddressInterval&) = 0;
99
101 virtual void clearBreakPoints() = 0;
102
104 // Execution
106public:
107
114 virtual void executionAddress(ThreadId, rose_addr_t);
115 virtual rose_addr_t executionAddress(ThreadId);
119 virtual void singleStep(ThreadId) = 0;
120
122 virtual void runToBreakPoint(ThreadId) = 0;
123
126
132 template<class Filter>
135 while (!isTerminated()) {
136 rose_addr_t va = executionAddress(tid);
137 FilterAction action = filter(va);
139 retval.append(va);
140 if (action.isSet(FilterActionFlag::STOP))
141 return retval;
142 singleStep(tid);
143 }
144 return retval;
145 }
146
148 // Registers
150public:
151
154
156 virtual std::string registerName(RegisterDescriptor);
157
167
172 virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value) = 0;
176 virtual std::vector<RegisterDescriptor> availableRegisters() = 0;
177
182
188
190 // Memory
192public:
193
197 virtual size_t readMemory(rose_addr_t va, size_t nBytes, uint8_t *buffer) = 0;
198
202 virtual std::vector<uint8_t> readMemory(rose_addr_t va, size_t nBytes) = 0;
203
209 virtual Sawyer::Container::BitVector readMemory(rose_addr_t va, size_t nBytes, ByteOrder::Endianness order) = 0;
210
214 virtual size_t writeMemory(rose_addr_t va, size_t nBytes, const uint8_t *bytes) = 0;
215
219 template<typename T>
220 void writeMemory(rose_addr_t va, const T &value) {
221 size_t n = writeMemory(va, sizeof(T), (const uint8_t*)&value);
222 ASSERT_always_require(n == sizeof(T));
223 }
224
230 virtual std::string readCString(rose_addr_t va, size_t maxBytes = UNLIMITED);
231
232
233
234
235};
236
237} // namespace
238} // namespace
239} // namespace
240
241#endif
242#endif
Base class for debuggers.
virtual void runToBreakPoint(ThreadId)=0
Run until the next breakpoint is reached.
virtual void clearBreakPoint(const AddressInterval &)=0
Remove breakpoints.
virtual void writeAllRegisters(ThreadId, const Sawyer::Container::BitVector &)=0
Write all registers as a single bit vector.
virtual Sawyer::Container::BitVector readMemory(rose_addr_t va, size_t nBytes, ByteOrder::Endianness order)=0
Read subordinate memory as a bit vector.
Sawyer::Container::Trace< rose_addr_t > trace(ThreadId tid, Filter &filter)
Run the program and return an execution trace.
virtual rose_addr_t executionAddress(ThreadId)
Execution address.
virtual std::string registerName(RegisterDescriptor)
Convert a register descriptor to a register name.
virtual bool isAttached()=0
Tests whether this debugger is attached to a specimen.
virtual void singleStep(ThreadId)=0
Execute one machine instruction.
virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value)=0
Write subordinate register.
virtual Sawyer::Container::BitVector readRegister(ThreadId, RegisterDescriptor)=0
Read subordinate register.
virtual std::string howTerminated()=0
String describing how the subordinate process terminated.
virtual void executionAddress(ThreadId, rose_addr_t)
Execution address.
virtual std::vector< ThreadId > threadIds()=0
List of subordinate threads.
virtual void writeRegister(ThreadId, RegisterDescriptor, const Sawyer::Container::BitVector &)=0
Write subordinate register.
virtual void setBreakPoint(const AddressInterval &)=0
Set breakpoints.
virtual bool isTerminated()=0
Returns true if the subordinate terminated.
virtual size_t writeMemory(rose_addr_t va, size_t nBytes, const uint8_t *bytes)=0
Writes some bytes to subordinate memory.
virtual size_t readMemory(rose_addr_t va, size_t nBytes, uint8_t *buffer)=0
Read subordinate memory.
void writeMemory(rose_addr_t va, const T &value)
Write subordinate memory.
virtual void terminate()=0
Terminate the specimen.
virtual std::vector< RegisterDescriptor > availableRegisters()=0
List of available registers.
virtual void detach()=0
Detach from a specimen.
virtual std::string readCString(rose_addr_t va, size_t maxBytes=UNLIMITED)
Read C-style NUL-terminated string from subordinate.
virtual Disassembler::BasePtr disassembler()
Property: Disassembler.
virtual Sawyer::Container::BitVector readAllRegisters(ThreadId)=0
Read all available register values as a single bit vector.
virtual Sawyer::Container::Trace< rose_addr_t > trace()
Run the program and return an execution trace.
virtual RegisterDictionaryPtr registerDictionary()
Register dictionary for the architecture.
virtual void clearBreakPoints()=0
Remove all breakpoints.
virtual std::vector< uint8_t > readMemory(rose_addr_t va, size_t nBytes)=0
Read subordinate memory as an array of bytes.
Describes (part of) a physical CPU register.
Stores a vector of enum bit flags.
bool isClear(Enum e) const
Test whether a bit is clear.
bool isSet(Enum e) const
Test whether a bit is set.
Records and replays traces.
Definition Trace.h:262
void append(const Label &label)
Append a label to a trace.
Definition Trace.h:476
Base class for reference counted objects.
@ REJECT
Reject the current address, not appending it to the trace.
@ STOP
Abort tracing, either appending or rejecting the current address.
The ROSE library.
const size_t UNLIMITED
Effectively unlimited size.
Definition Constants.h:19