1#ifndef ROSE_BinaryAnalysis_Debugger_Linux_H
2#define ROSE_BinaryAnalysis_Debugger_Linux_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_DEBUGGER_LINUX
5#include <Rose/BinaryAnalysis/Debugger/Base.h>
7#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
8#include <Rose/BinaryAnalysis/SystemCall.h>
10#include <Sawyer/Optional.h>
11#include <sys/ptrace.h>
14namespace BinaryAnalysis {
18class Linux:
public Base {
37 REDIRECT_INPUT = 0x00000002,
38 REDIRECT_OUTPUT = 0x00000004,
39 REDIRECT_ERROR = 0x00000008,
40 CLOSE_FILES = 0x00000010,
41 DEFAULT_FLAGS = 0x00000013
48 BitFlags<Flag> flags_;
49 unsigned long persona_;
52 boost::filesystem::path program_;
53 std::vector<std::string> arguments_;
54 boost::filesystem::path workingDirectory_;
55 std::vector<boost::regex> clearEnvVars_;
56 std::map<std::string, std::string> setEnvVars_;
69 Specimen(
const boost::filesystem::path&);
72 Specimen(
const boost::filesystem::path &name,
const std::vector<std::string> &args);
75 Specimen(
const std::vector<std::string> &nameAndArgs);
84 const boost::filesystem::path& program()
const;
85 void program(
const boost::filesystem::path&);
94 const std::vector<std::string>& arguments()
const;
95 void arguments(
const std::vector<std::string>&);
103 void eraseEnvironmentVariable(
const std::string&);
110 void eraseMatchingEnvironmentVariables(
const boost::regex&);
115 void eraseAllEnvironmentVariables();
122 void insertEnvironmentVariable(
const std::string &name,
const std::string &value);
131 boost::filesystem::path workingDirectory()
const;
132 void workingDirectory(
const boost::filesystem::path&);
140 const BitFlags<Flag>& flags()
const;
141 BitFlags<Flag>& flags();
151 unsigned long persona()
const;
152 void persona(
unsigned long bits);
163 bool randomizedAddresses()
const;
164 void randomizedAddresses(
bool);
174 void process(
int pid);
178 void print(std::ostream &out)
const;
181 char** prepareEnvAdjustments()
const;
194 using RegPage = std::array<uint8_t, 512>;
197 struct AllRegValues {
213 UserRegDefs userRegDefs_;
214 UserRegDefs userFpRegDefs_;
215 size_t kernelWordSize_ = 0;
219 SystemCall syscallDecls_;
228 static Ptr instance();
258 void detachMode(DetachMode);
264 size_t kernelWordSize();
267 int waitpidStatus()
const;
274 void stepIntoSystemCall(ThreadId);
280 void runToSystemCall(ThreadId);
289 int64_t remoteSystemCall(ThreadId,
int syscallNumber);
290 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
292 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
293 uint64_t arg1, uint64_t arg2);
294 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
295 uint64_t arg1, uint64_t arg2, uint64_t arg3);
296 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
297 uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
298 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
299 uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5);
300 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
301 uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6);
302 int64_t remoteSystemCall(ThreadId,
int syscallNumber, std::vector<uint64_t> args);
309 int remoteOpenFile(ThreadId,
const boost::filesystem::path &fileName,
unsigned flags, mode_t mode);
312 int remoteCloseFile(ThreadId,
unsigned remoteFd);
317 rose_addr_t remoteMmap(ThreadId, rose_addr_t va,
size_t nBytes,
unsigned prot,
unsigned flags,
const boost::filesystem::path&,
324 virtual bool isAttached()
override;
325 virtual void detach()
override;
326 virtual void terminate()
override;
327 virtual std::vector<ThreadId> threadIds()
override;
328 virtual void executionAddress(ThreadId, rose_addr_t)
override;
329 virtual rose_addr_t executionAddress(ThreadId)
override;
330 virtual void setBreakPoint(
const AddressInterval&)
override;
331 virtual void clearBreakPoint(
const AddressInterval&)
override;
332 virtual void clearBreakPoints()
override;
333 virtual void singleStep(ThreadId)
override;
334 virtual void runToBreakPoint(ThreadId)
override;
337 virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value)
override;
338 virtual size_t readMemory(rose_addr_t va,
size_t nBytes, uint8_t *buffer)
override;
339 virtual std::vector<uint8_t> readMemory(rose_addr_t va,
size_t nBytes)
override;
341 virtual size_t writeMemory(rose_addr_t va,
size_t nBytes,
const uint8_t *bytes)
override;
342 virtual bool isTerminated()
override;
343 virtual std::string howTerminated()
override;
344 virtual std::vector<RegisterDescriptor> availableRegisters()
override;
354 void devNullTo(
int targetFd,
int openFlags);
357 static unsigned long getPersonality();
358 static void setPersonality(
unsigned long);
364 AllRegValues loadAllRegisters(ThreadId);
365 void saveAllRegisters(ThreadId,
const AllRegValues&);
369 size_t updateRegCache(RegisterDescriptor);
372 long sendCommand(__ptrace_request,
void *addr =
nullptr,
void *data =
nullptr);
373 long sendCommandInt(__ptrace_request,
void *addr,
int i);
376 void declareSystemCalls(
size_t nBits);
379std::ostream& operator<<(std::ostream&,
const Linux::Specimen&);
Container associating values with keys.
Holds a value or nothing.
Flag
Flag to pass as type stringification style.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
@ CONTINUE
Continue the traversal as normal.
void print(const StackVariables &, const Partitioner2::PartitionerConstPtr &, std::ostream &out, const std::string &prefix="")
Print info about multiple local variables.
Sawyer::Container::IntervalSet< AddressInterval > AddressIntervalSet
A set of virtual addresses.
const char * RegCacheType(int64_t)
Convert Rose::BinaryAnalysis::Debugger::Linux::RegCacheType enum constant to a string.
const char * DetachMode(int64_t)
Convert Rose::BinaryAnalysis::Debugger::Linux::DetachMode enum constant to a string.