1 #ifndef AESALON_INTERFACE_PTRACE_PORTAL_H
2 #define AESALON_INTERFACE_PTRACE_PORTAL_H
9 #include "Breakpoint.h"
11 #include "SignalObserver.h"
12 #include "platform/MemoryAddress.h"
13 #include "platform/ArgumentList.h"
14 #include "misc/SmartPointer.h"
20 class PTraceException
: public Misc::Exception
{
22 PTraceException(std::string message
) : Misc::Exception(message
) {}
23 virtual ~PTraceException() {}
28 /** An enum representing the different registers available. */
30 #if AESALON_PLATFORM == AESALON_PLATFORM_x86_64
47 #elif AESALON_PLATFORM == AESALON_PLATFORM_x86
62 typedef std::vector
<Misc::SmartPointer
<Breakpoint
> > breakpoint_list_t
;
64 typedef std::vector
<Misc::SmartPointer
<SignalObserver
> > signal_observer_list_t
;
66 /** The PID of the attached process. */
69 /** The vector of breakpoints. */
70 breakpoint_list_t breakpoint_list
;
72 /** Adds a breakpoint onto the list.
73 @param breakpoint The breakpoint to add.
75 void add_breakpoint(Misc::SmartPointer
<Breakpoint
> breakpoint
) {
76 breakpoint_list
.push_back(breakpoint
);
79 signal_observer_list_t signal_observer_list
;
81 int wait_for_signal();
83 /** Generic constructor for PTracePortal.
84 @param pid The PID of the child process.
86 Portal(std::string executable
, Misc::SmartPointer
<Platform::ArgumentList
> argument_list
);
87 /** Virtual destructor, does nothing. */
90 /** Retrieve the value of a specific register.
91 @param which The register to get the value of.
92 @return The value of the specified register.
94 Platform::MemoryAddress
get_register(register_e which
) const;
96 /** Read a Word of memory.
97 @param address The address to read.
98 @return The value at @a address.
100 Word
read_memory(Platform::MemoryAddress address
) const;
101 /** Write a Word of memory.
102 @param address The address to write to.
103 @param value The value to write.
105 void write_memory(Platform::MemoryAddress address
, Word value
);
106 /** Write a Byte of memory.
107 @param address The address to write to.
108 @param value The value to write.
110 void write_memory(Platform::MemoryAddress address
, Byte value
);
112 /** Attaches onto the PID @a pid. */
115 /** Places a breakpoint at a specified address.
116 @param address The address to place the breakpoint at.
118 void place_breakpoint(Platform::MemoryAddress address
);
120 /** Returns a breakpoint by iterator.
121 @param which The breakpoint to find.
122 @return A SmartPointer to the given breakpoint. Not valid if the breakpoint iterator does not exist.
124 Misc::SmartPointer
<Breakpoint
> get_breakpoint(breakpoint_list_t::size_type which
) const {
125 return breakpoint_list
.at(which
);
127 /** Returns a breakpoint by address.
128 @param address The address to search for.
129 @return A SmartPointer to the given breakpoint. Not valid if no breakpoint exists at @a address.
131 /*Misc::SmartPointer<Breakpoint> get_breakpoint_by_address(Platform::MemoryAddress address) const;*/
133 void handle_signal();
134 /** Continues execution, with a given signal sent to the child.
135 @param signal The signal to send; none if zero.
137 void continue_execution(int signal
= 0);
138 /** Tells the child to execute a single instruction. */
141 void add_signal_observer(Misc::SmartPointer
<SignalObserver
> new_observer
) {
142 signal_observer_list
.push_back(new_observer
);
146 } // namespace PTrace
147 } // namespace Interface
148 } // namespace Aesalon