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 "misc/SmartPointer.h"
19 class PTraceException
: public Misc::Exception
{
21 PTraceException(std::string message
) : Misc::Exception(message
) {}
22 virtual ~PTraceException() {}
27 /** An enum representing the different registers available. */
29 #if AESALON_PLATFORM == AESALON_PLATFORM_x86_64
46 #elif AESALON_PLATFORM == AESALON_PLATFORM_x86
61 typedef std::vector
<Misc::SmartPointer
<Breakpoint
> > breakpoint_list_t
;
63 typedef std::vector
<Misc::SmartPointer
<PTraceSignalObserver
> > signal_observer_list_t
;
65 /** The PID of the attached process. */
68 /** The vector of breakpoints. */
69 breakpoint_list_t breakpoint_list
;
71 /** Adds a breakpoint onto the list.
72 @param breakpoint The breakpoint to add.
74 void add_breakpoint(Misc::SmartPointer
<Breakpoint
> breakpoint
) {
75 breakpoint_list
.push_back(breakpoint
);
78 signal_observer_list_t signal_observer_list
;
80 /** Generic constructor for PTracePortal.
81 @param pid The PID of the child process.
83 Portal(pid_t pid
) : pid(pid
) {}
84 /** Virtual destructor, does nothing. */
87 /** Retrieve the value of a specific register.
88 @param which The register to get the value of.
89 @return The value of the specified register.
91 Platform::MemoryAddress
get_register(register_e which
) const;
93 /** Read a Word of memory.
94 @param address The address to read.
95 @return The value at @a address.
97 Word
read_memory(Platform::MemoryAddress address
) const;
98 /** Write a Word of memory.
99 @param address The address to write to.
100 @param value The value to write.
102 void write_memory(Platform::MemoryAddress address
, Word value
);
103 /** Write a Byte of memory.
104 @param address The address to write to.
105 @param value The value to write.
107 void write_memory(Platform::MemoryAddress address
, Byte value
);
109 /** Attaches onto the PID @a pid. */
112 /** Places a breakpoint at a specified address.
113 @param address The address to place the breakpoint at.
115 void place_breakpoint(Platform::MemoryAddress address
);
117 /** Returns a breakpoint by iterator.
118 @param which The breakpoint to find.
119 @return A SmartPointer to the given breakpoint. Not valid if the breakpoint iterator does not exist.
121 Misc::SmartPointer
<Breakpoint
> get_breakpoint(breakpoint_list_t::size_type which
) const {
122 return breakpoint_list
.at(which
);
124 /** Returns a breakpoint by address.
125 @param address The address to search for.
126 @return A SmartPointer to the given breakpoint. Not valid if no breakpoint exists at @a address.
128 /*Misc::SmartPointer<Breakpoint> get_breakpoint_by_address(Platform::MemoryAddress address) const;*/
130 void handle_signal();
131 /** Continues execution, with a given signal sent to the child.
132 @param signal The signal to send; none if zero.
134 void continue_execution(int signal
= 0);
135 /** Tells the child to execute a single instruction. */
138 void wait_for_signal();
140 void add_signal_observer(Misc::SmartPointer
<PTraceSignalObserver
> new_observer
) {
141 signal_observer_list
.push_back(new_observer
);
145 } // namespace PTrace
146 } // namespace Interface
147 } // namespace Aesalon