ROSE 0.11.145.250
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/AddressIntervalSet.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 virtual void setBreakPoints(const AddressIntervalSet&) = 0;
97
99 virtual void clearBreakPoint(const AddressInterval&) = 0;
100
102 virtual void clearBreakPoints() = 0;
103
106
108 // Execution
110public:
111
123 virtual void singleStep(ThreadId) = 0;
124
126 virtual void runToBreakPoint(ThreadId) = 0;
127
130
136 template<class Filter>
139 while (!isTerminated()) {
140 Address va = executionAddress(tid);
141 FilterAction action = filter(va);
143 retval.append(va);
144 if (action.isSet(FilterActionFlag::STOP))
145 return retval;
146 singleStep(tid);
147 }
148 return retval;
149 }
150
152 // Registers
154public:
155
158
160 virtual std::string registerName(RegisterDescriptor);
161
171
176 virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value) = 0;
180 virtual std::vector<RegisterDescriptor> availableRegisters() = 0;
181
186
192
194 // Memory
196public:
197
201 virtual size_t readMemory(Address va, size_t nBytes, uint8_t *buffer) = 0;
202
206 virtual std::vector<uint8_t> readMemory(Address va, size_t nBytes) = 0;
207
214
218 virtual size_t writeMemory(Address va, size_t nBytes, const uint8_t *bytes) = 0;
219
223 template<typename T>
224 void writeMemory(Address va, const T &value) {
225 size_t n = writeMemory(va, sizeof(T), (const uint8_t*)&value);
226 ASSERT_always_require(n == sizeof(T));
227 }
228
234 virtual std::string readCString(Address va, size_t maxBytes = UNLIMITED);
235
236
237
238
239};
240
241} // namespace
242} // namespace
243} // namespace
244
245#endif
246#endif
Base class for debuggers.
Sawyer::Container::Trace< Address > trace(ThreadId tid, Filter &filter)
Run the program and return an execution trace.
virtual AddressIntervalSet breakPoints()=0
All known breakpoints.
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 void executionAddress(ThreadId, Address)
Execution address.
virtual Sawyer::Container::BitVector readMemory(Address va, size_t nBytes, ByteOrder::Endianness order)=0
Read subordinate memory as a bit vector.
virtual std::string registerName(RegisterDescriptor)
Convert a register descriptor to a register name.
virtual Sawyer::Container::Trace< Address > trace()
Run the program and return an execution trace.
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.
void writeMemory(Address va, const T &value)
Write subordinate memory.
virtual Address executionAddress(ThreadId)
Execution address.
virtual Sawyer::Container::BitVector readRegister(ThreadId, RegisterDescriptor)=0
Read subordinate register.
virtual std::vector< uint8_t > readMemory(Address va, size_t nBytes)=0
Read subordinate memory as an array of bytes.
virtual std::string howTerminated()=0
String describing how the subordinate process terminated.
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 readMemory(Address va, size_t nBytes, uint8_t *buffer)=0
Read 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 size_t writeMemory(Address va, size_t nBytes, const uint8_t *bytes)=0
Writes some bytes to subordinate memory.
virtual std::string readCString(Address 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 RegisterDictionaryPtr registerDictionary()
Register dictionary for the architecture.
virtual void clearBreakPoints()=0
Remove all breakpoints.
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.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.
const size_t UNLIMITED
Effectively unlimited size.
Definition Constants.h:19