1 #ifndef ROSE_BinaryAnalysis_Debugger_Gdb_H
2 #define ROSE_BinaryAnalysis_Debugger_Gdb_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_DEBUGGER_GDB
6 #include <Rose/BinaryAnalysis/Debugger/Base.h>
7 #include <Rose/BinaryAnalysis/Debugger/GdbResponse.h>
10 #include <boost/asio.hpp>
11 #include <boost/filesystem.hpp>
12 #include <boost/process.hpp>
14 #include <condition_variable>
20 namespace BinaryAnalysis {
24 class Gdb:
public Base {
40 std::string host =
"localhost";
45 boost::filesystem::path gdbName_ =
"gdb-multiarch";
46 boost::filesystem::path executable_;
58 Specimen(
const boost::filesystem::path &exeName);
67 Specimen(
const boost::filesystem::path &exeName,
const std::string &host, uint16_t port);
73 const boost::filesystem::path &gdbName()
const;
74 void gdbName(
const boost::filesystem::path&);
83 const boost::filesystem::path& executable()
const;
84 void executable(
const boost::filesystem::path&);
90 const Remote& remote()
const;
91 void remote(
const Remote&);
92 void remote(
const std::string &host, uint16_t port);
103 std::condition_variable cond_;
105 std::list<Value> items_;
106 bool isClosed_ =
false;
110 void append(
const Value &item) {
111 const std::lock_guard<std::mutex> lock(mutex_);
112 items_.push_back(item);
118 const std::lock_guard<std::mutex> lock(mutex_);
126 const std::lock_guard<std::mutex> lock(mutex_);
134 const std::lock_guard<std::mutex> lock(mutex_);
135 if (items_.empty()) {
138 Value item = items_.front();
146 std::unique_lock<std::mutex> lock(mutex_);
147 while (items_.empty() && !isClosed_)
149 if (items_.empty()) {
152 Value item = items_.front();
160 std::lock_guard<std::mutex> lock(mutex_);
168 bool hasEndMarker =
false;
170 struct ResultRecord {
174 std::list<Yaml::Node> results;
177 std::list<ResultRecord> resultRecord;
185 std::thread gdbThread_;
186 Fifo<std::string> gdbOutput_;
187 boost::asio::io_service ios_;
188 boost::process::async_pipe gdbOutputPipe_;
189 boost::process::opstream gdbInput_;
190 boost::asio::streambuf gdbOutputBuffer_;
191 std::vector<std::pair<std::string, RegisterDescriptor>> registers_;
192 std::list<GdbResponse> responses_;
194 std::map<rose_addr_t,
unsigned > gdbBreakPoints_;
195 std::future<int> exitCodeFuture_;
210 static Ptr instance();
215 static Ptr instance(
const Specimen&);
224 virtual void attach(
const Specimen&);
236 const std::list<GdbResponse>& sendCommand(
const std::string&);
242 std::list<GdbResponse> readRequiredResponses();
248 std::list<GdbResponse> readOptionalResponses();
253 const std::list<GdbResponse>& responses()
const;
256 void resetResponses();
261 const std::vector<std::pair<std::string, RegisterDescriptor>>& registerNames()
const;
267 virtual bool isAttached()
override;
268 virtual void detach()
override;
269 virtual void terminate()
override;
270 virtual std::vector<ThreadId> threadIds()
override;
273 virtual void clearBreakPoints()
override;
274 virtual void singleStep(ThreadId)
override;
275 virtual void runToBreakPoint(ThreadId)
override;
277 virtual std::vector<RegisterDescriptor> availableRegisters()
override;
279 virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value)
override;
280 virtual size_t readMemory(rose_addr_t va,
size_t nBytes, uint8_t *buffer)
override;
281 virtual std::vector<uint8_t> readMemory(rose_addr_t va,
size_t nBytes)
override;
283 virtual size_t writeMemory(rose_addr_t va,
size_t nBytes,
const uint8_t *bytes)
override;
284 virtual bool isTerminated()
override;
285 virtual std::string howTerminated()
override;
294 std::list<GdbResponse> readResponseSet(
bool required);
301 RegisterDescriptor findRegister(RegisterDescriptor)
const;
304 bool gdbHandlesBreakPoints()
const;
ROSE_DLL_API void clear()
Empties the memory pool of all nodes.
Error messages that indicate an abnormal situation from which the program was able to at least partia...
Main namespace for the ROSE library.
const char * ResultClass(int64_t)
Convert Rose::BinaryAnalysis::Debugger::Gdb::Response::ResultRecord::ResultClass enum constant to a s...
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.