1#ifndef ROSE_BinaryAnalysis_Debugger_Gdb_H
2#define ROSE_BinaryAnalysis_Debugger_Gdb_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_DEBUGGER_GDB
5#include <Rose/BinaryAnalysis/Debugger/Base.h>
7#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
8#include <Rose/BinaryAnalysis/Debugger/GdbResponse.h>
11#include <boost/asio.hpp>
12#include <boost/filesystem.hpp>
13#include <boost/process.hpp>
15#include <condition_variable>
21namespace BinaryAnalysis {
25class Gdb:
public Base {
41 std::string host =
"localhost";
46 boost::filesystem::path gdbName_ =
"gdb-multiarch";
47 boost::filesystem::path executable_;
59 Specimen(
const boost::filesystem::path &exeName);
68 Specimen(
const boost::filesystem::path &exeName,
const std::string &host, uint16_t port);
74 const boost::filesystem::path &gdbName()
const;
75 void gdbName(
const boost::filesystem::path&);
84 const boost::filesystem::path& executable()
const;
85 void executable(
const boost::filesystem::path&);
91 const Remote& remote()
const;
92 void remote(
const Remote&);
93 void remote(
const std::string &host, uint16_t port);
104 std::condition_variable cond_;
106 std::list<Value> items_;
107 bool isClosed_ =
false;
111 void append(
const Value &item) {
112 const std::lock_guard<std::mutex> lock(mutex_);
113 items_.push_back(item);
119 const std::lock_guard<std::mutex> lock(mutex_);
127 const std::lock_guard<std::mutex> lock(mutex_);
135 const std::lock_guard<std::mutex> lock(mutex_);
136 if (items_.empty()) {
139 Value item = items_.front();
147 std::unique_lock<std::mutex> lock(mutex_);
148 while (items_.empty() && !isClosed_)
150 if (items_.empty()) {
153 Value item = items_.front();
161 std::lock_guard<std::mutex> lock(mutex_);
169 bool hasEndMarker =
false;
171 struct ResultRecord {
175 std::list<Yaml::Node> results;
178 std::list<ResultRecord> resultRecord;
186 std::thread gdbThread_;
187 Fifo<std::string> gdbOutput_;
188 boost::asio::io_service ios_;
189 boost::process::async_pipe gdbOutputPipe_;
190 boost::process::opstream gdbInput_;
191 boost::asio::streambuf gdbOutputBuffer_;
192 std::vector<std::pair<std::string, RegisterDescriptor>> registers_;
193 std::list<GdbResponse> responses_;
195 std::map<rose_addr_t,
unsigned > gdbBreakPoints_;
196 std::future<int> exitCodeFuture_;
211 static Ptr instance();
216 static Ptr instance(
const Specimen&);
225 virtual void attach(
const Specimen&);
237 const std::list<GdbResponse>& sendCommand(
const std::string&);
243 std::list<GdbResponse> readRequiredResponses();
249 std::list<GdbResponse> readOptionalResponses();
254 const std::list<GdbResponse>& responses()
const;
257 void resetResponses();
262 const std::vector<std::pair<std::string, RegisterDescriptor>>& registerNames()
const;
268 virtual bool isAttached()
override;
269 virtual void detach()
override;
270 virtual void terminate()
override;
271 virtual std::vector<ThreadId> threadIds()
override;
272 virtual void setBreakPoint(
const AddressInterval&)
override;
273 virtual void clearBreakPoint(
const AddressInterval&)
override;
274 virtual void clearBreakPoints()
override;
275 virtual void singleStep(ThreadId)
override;
276 virtual void runToBreakPoint(ThreadId)
override;
278 virtual std::vector<RegisterDescriptor> availableRegisters()
override;
280 virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value)
override;
281 virtual size_t readMemory(rose_addr_t va,
size_t nBytes, uint8_t *buffer)
override;
282 virtual std::vector<uint8_t> readMemory(rose_addr_t va,
size_t nBytes)
override;
284 virtual size_t writeMemory(rose_addr_t va,
size_t nBytes,
const uint8_t *bytes)
override;
285 virtual bool isTerminated()
override;
286 virtual std::string howTerminated()
override;
295 std::list<GdbResponse> readResponseSet(
bool required);
302 RegisterDescriptor findRegister(RegisterDescriptor)
const;
305 bool gdbHandlesBreakPoints()
const;
Holds a value or nothing.
ROSE_DLL_API void clear()
Empties the memory pool of all nodes.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
Sawyer::Container::IntervalSet< AddressInterval > AddressIntervalSet
A set of virtual addresses.
@ ERROR
Error messages that indicate an abnormal situation from which the program was able to at least partia...
const char * ResultClass(int64_t)
Convert Rose::BinaryAnalysis::Debugger::Gdb::Response::ResultRecord::ResultClass enum constant to a s...