1 #ifndef ROSE_BinaryAnalysis_Debugger_Linux_H
2 #define ROSE_BinaryAnalysis_Debugger_Linux_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_DEBUGGER_LINUX
6 #include <Rose/BinaryAnalysis/Debugger/Base.h>
8 #include <Sawyer/Optional.h>
11 namespace BinaryAnalysis {
15 class Linux:
public Base {
34 REDIRECT_INPUT = 0x00000002,
35 REDIRECT_OUTPUT = 0x00000004,
36 REDIRECT_ERROR = 0x00000008,
37 CLOSE_FILES = 0x00000010,
38 DEFAULT_FLAGS = 0x00000013
45 BitFlags<Flag> flags_;
46 unsigned long persona_;
49 boost::filesystem::path program_;
50 std::vector<std::string> arguments_;
51 boost::filesystem::path workingDirectory_;
52 std::vector<boost::regex> clearEnvVars_;
53 std::map<std::string, std::string> setEnvVars_;
66 Specimen(
const boost::filesystem::path&);
69 Specimen(
const boost::filesystem::path &name,
const std::vector<std::string> &args);
72 Specimen(
const std::vector<std::string> &nameAndArgs);
81 const boost::filesystem::path& program()
const;
82 void program(
const boost::filesystem::path&);
91 const std::vector<std::string>& arguments()
const;
92 void arguments(
const std::vector<std::string>&);
100 void eraseEnvironmentVariable(
const std::string&);
107 void eraseMatchingEnvironmentVariables(
const boost::regex&);
112 void eraseAllEnvironmentVariables();
119 void insertEnvironmentVariable(
const std::string &name,
const std::string &value);
128 boost::filesystem::path workingDirectory()
const;
129 void workingDirectory(
const boost::filesystem::path&);
137 const BitFlags<Flag>& flags()
const;
138 BitFlags<Flag>& flags();
148 unsigned long persona()
const;
149 void persona(
unsigned long bits);
160 bool randomizedAddresses()
const;
161 void randomizedAddresses(
bool);
171 void process(
int pid);
175 void print(std::ostream &out)
const;
178 char** prepareEnvAdjustments()
const;
182 using RegisterPage = std::array<uint8_t, 512>;
185 struct AllRegisters {
195 enum class RegPage { NONE, REGS, FPREGS };
203 UserRegDefs userRegDefs_;
204 UserRegDefs userFpRegDefs_;
205 size_t kernelWordSize_ = 0;
206 RegisterPage regsPage_;
207 RegPage regsPageStatus_ = RegPage::NONE;
217 static Ptr instance();
248 void detachMode(DetachMode);
254 size_t kernelWordSize();
257 int waitpidStatus()
const;
264 void stepIntoSystemCall(ThreadId);
270 void runToSystemCall(ThreadId);
279 virtual AllRegisters readAllRegisters(ThreadId);
284 virtual void writeAllRegisters(ThreadId,
const AllRegisters&);
293 int64_t remoteSystemCall(ThreadId,
int syscallNumber);
294 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
296 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
297 uint64_t arg1, uint64_t arg2);
298 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
299 uint64_t arg1, uint64_t arg2, uint64_t arg3);
300 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
301 uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
302 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
303 uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5);
304 int64_t remoteSystemCall(ThreadId,
int syscallNumber,
305 uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6);
306 int64_t remoteSystemCall(ThreadId,
int syscallNumber, std::vector<uint64_t> args);
313 int remoteOpenFile(ThreadId,
const boost::filesystem::path &fileName,
unsigned flags, mode_t mode);
316 int remoteCloseFile(ThreadId,
unsigned remoteFd);
321 rose_addr_t remoteMmap(ThreadId, rose_addr_t va,
size_t nBytes,
unsigned prot,
unsigned flags,
const boost::filesystem::path&,
328 virtual bool isAttached()
override;
329 virtual void detach()
override;
330 virtual void terminate()
override;
331 virtual std::vector<ThreadId> threadIds()
override;
332 virtual void executionAddress(ThreadId, rose_addr_t)
override;
333 virtual rose_addr_t executionAddress(ThreadId)
override;
336 virtual void clearBreakPoints()
override;
337 virtual void singleStep(ThreadId)
override;
338 virtual void runToBreakPoint(ThreadId)
override;
341 virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value)
override;
342 virtual size_t readMemory(rose_addr_t va,
size_t nBytes, uint8_t *buffer)
override;
343 virtual std::vector<uint8_t> readMemory(rose_addr_t va,
size_t nBytes)
override;
345 virtual size_t writeMemory(rose_addr_t va,
size_t nBytes,
const uint8_t *bytes)
override;
346 virtual bool isTerminated()
override;
347 virtual std::string howTerminated()
override;
355 void devNullTo(
int targetFd,
int openFlags);
358 static unsigned long getPersonality();
359 static void setPersonality(
unsigned long);
365 std::ostream& operator<<(std::ostream&,
const Linux::Specimen&);
Continue the traversal as normal.
const char * DetachMode(int64_t)
Convert Rose::BinaryAnalysis::Debugger::Linux::DetachMode enum constant to a string.
void print(const StackVariables &, const Partitioner2::Partitioner &, std::ostream &out, const std::string &prefix="")
Print info about multiple local variables.
Main namespace for the ROSE library.
const char * RegPage(int64_t)
Convert Rose::BinaryAnalysis::Debugger::Linux::RegPage enum constant to a string. ...
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
Container associating values with keys.