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_;                         
 
   50        Architecture::BaseConstPtr arch_;               
 
   53        boost::filesystem::path program_;               
 
   54        std::vector<std::string> arguments_;            
 
   55        boost::filesystem::path workingDirectory_;      
 
   56        std::vector<boost::regex> clearEnvVars_;        
 
   57        std::map<std::string, std::string> setEnvVars_; 
 
   70        Specimen(
const boost::filesystem::path&);       
 
   73        Specimen(
const boost::filesystem::path &name, 
const std::vector<std::string> &args);
 
   76        Specimen(
const std::vector<std::string> &nameAndArgs); 
 
   85        const boost::filesystem::path& program() 
const;
 
   86        void program(
const boost::filesystem::path&);
 
   95        const std::vector<std::string>& arguments() 
const;
 
   96        void arguments(
const std::vector<std::string>&);
 
  104        void eraseEnvironmentVariable(
const std::string&);
 
  111        void eraseMatchingEnvironmentVariables(
const boost::regex&);
 
  116        void eraseAllEnvironmentVariables();
 
  123        void insertEnvironmentVariable(
const std::string &name, 
const std::string &value);
 
  132        boost::filesystem::path workingDirectory() 
const;
 
  133        void workingDirectory(
const boost::filesystem::path&);
 
  141        const BitFlags<Flag>& flags() 
const;
 
  142        BitFlags<Flag>& flags();
 
  152        unsigned long persona() 
const;
 
  153        void persona(
unsigned long bits);
 
  161        Architecture::BaseConstPtr architecture() 
const;
 
  162        void architecture(
const Architecture::BaseConstPtr&);
 
  173        bool randomizedAddresses() 
const;
 
  174        void randomizedAddresses(
bool);
 
  184        void process(
int pid);
 
  188        void print(std::ostream &out) 
const;
 
  191        char** prepareEnvAdjustments() 
const;
 
  204    using RegPage = std::array<uint8_t, 512>;
 
  207    struct AllRegValues {
 
  223    UserRegDefs userRegDefs_;                           
 
  224    UserRegDefs userFpRegDefs_;                         
 
  225    size_t kernelWordSize_ = 0;                         
 
  229    SystemCall syscallDecls_;                           
 
  238    static Ptr instance();
 
  268    void detachMode(DetachMode);
 
  274    size_t kernelWordSize();
 
  277    int waitpidStatus() 
const;
 
  284    void stepIntoSystemCall(ThreadId);
 
  290    void runToSystemCall(ThreadId);
 
  296    int pendingSignal() 
const;
 
  305    int64_t remoteSystemCall(ThreadId, 
int syscallNumber);
 
  306    int64_t remoteSystemCall(ThreadId, 
int syscallNumber,
 
  308    int64_t remoteSystemCall(ThreadId, 
int syscallNumber,
 
  309                             uint64_t arg1, uint64_t arg2);
 
  310    int64_t remoteSystemCall(ThreadId, 
int syscallNumber,
 
  311                             uint64_t arg1, uint64_t arg2, uint64_t arg3);
 
  312    int64_t remoteSystemCall(ThreadId, 
int syscallNumber,
 
  313                             uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
 
  314    int64_t remoteSystemCall(ThreadId, 
int syscallNumber,
 
  315                             uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5);
 
  316    int64_t remoteSystemCall(ThreadId, 
int syscallNumber,
 
  317                             uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6);
 
  318    int64_t remoteSystemCall(ThreadId, 
int syscallNumber, std::vector<uint64_t> args);
 
  325    int remoteOpenFile(ThreadId, 
const boost::filesystem::path &fileName, 
unsigned flags, mode_t mode);
 
  328    int remoteCloseFile(ThreadId, 
unsigned remoteFd);
 
  333    Address remoteMmap(ThreadId, Address va, 
size_t nBytes, 
unsigned prot, 
unsigned flags, 
const boost::filesystem::path&,
 
  340    virtual bool isAttached() 
override;
 
  341    virtual void detach() 
override;
 
  342    virtual void terminate() 
override;
 
  343    virtual std::vector<ThreadId> threadIds() 
override;
 
  344    virtual void executionAddress(ThreadId, Address) 
override;
 
  345    virtual Address executionAddress(ThreadId) 
override;
 
  346    virtual void setBreakPoint(
const AddressInterval&) 
override;
 
  347    virtual void setBreakPoints(
const AddressIntervalSet&) 
override;
 
  349    virtual void clearBreakPoint(
const AddressInterval&) 
override;
 
  350    virtual void clearBreakPoints() 
override;
 
  351    virtual void singleStep(ThreadId) 
override;
 
  352    virtual void runToBreakPoint(ThreadId) 
override;
 
  355    virtual void writeRegister(ThreadId, RegisterDescriptor, uint64_t value) 
override;
 
  356    virtual size_t readMemory(Address va, 
size_t nBytes, uint8_t *buffer) 
override;
 
  357    virtual std::vector<uint8_t> readMemory(Address va, 
size_t nBytes) 
override;
 
  359    virtual size_t writeMemory(Address va, 
size_t nBytes, 
const uint8_t *bytes) 
override;
 
  360    virtual bool isTerminated() 
override;
 
  361    virtual std::string howTerminated() 
override;
 
  362    virtual std::vector<RegisterDescriptor> availableRegisters() 
override;
 
  375    void devNullTo(
int targetFd, 
int openFlags);
 
  378    static unsigned long getPersonality();
 
  379    static void setPersonality(
unsigned long);
 
  385    AllRegValues loadAllRegisters(ThreadId);
 
  386    void saveAllRegisters(ThreadId, 
const AllRegValues&);
 
  390    size_t updateRegCache(RegisterDescriptor);
 
  393    long sendCommand(__ptrace_request, 
void *addr = 
nullptr, 
void *data = 
nullptr);
 
  394    long sendCommandInt(__ptrace_request, 
void *addr, 
int i);
 
  397    void declareSystemCalls();
 
  401    Architecture::BaseConstPtr guessSpecimenArchitecture() 
const;
 
  404std::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 GlobalVariables &, const Partitioner2::PartitionerConstPtr &, std::ostream &out, const std::string &prefix="")
Print info about multiple global variables.
 
Sawyer::Container::IntervalSet< AddressInterval > AddressIntervalSet
A set of virtual addresses.
 
std::uint64_t Address
Address.
 
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.