1 #ifndef AESALON_INTERFACE_PTRACE_PORTAL_H
2 #define AESALON_INTERFACE_PTRACE_PORTAL_H
9 #include "Breakpoint.h"
11 #include "PTraceSignalObserver.h"
12 #include "platform/MemoryAddress.h"
13 #include "misc/SmartPointer.h"
18 class PTraceException
: public Misc::Exception
{
20 PTraceException(std::string message
) : Misc::Exception(message
) {}
21 virtual ~PTraceException() {}
26 /** An enum representing the different registers available. */
28 #if AESALON_PLATFORM == AESALON_PLATFORM_x86_64
45 #elif AESALON_PLATFORM == AESALON_PLATFORM_x86
60 typedef std::vector
<Misc::SmartPointer
<Breakpoint
> > breakpoint_list_t
;
62 typedef std::vector
<Misc::SmartPointer
<PTraceSignalObserver
> > signal_observer_list_t
;
64 /** The PID of the attached process. */
67 /** The vector of breakpoints. */
68 breakpoint_list_t breakpoint_list
;
70 /** Adds a breakpoint onto the list.
71 @param breakpoint The breakpoint to add.
73 void add_breakpoint(Misc::SmartPointer
<Breakpoint
> breakpoint
) {
74 breakpoint_list
.push_back(breakpoint
);
77 signal_observer_list_t signal_observer_list
;
79 /** Generic constructor for PTracePortal.
80 @param pid The PID of the child process.
82 PTracePortal(pid_t pid
) : pid(pid
) {}
83 /** Virtual destructor, does nothing. */
84 virtual ~PTracePortal() {}
86 /** Retrieve the value of a specific register.
87 @param which The register to get the value of.
88 @return The value of the specified register.
90 Platform::MemoryAddress
get_register(register_e which
) const;
92 /** Read a Word of memory.
93 @param address The address to read.
94 @return The value at @a address.
96 Word
read_memory(Platform::MemoryAddress address
) const;
97 /** Write a Word of memory.
98 @param address The address to write to.
99 @param value The value to write.
101 void write_memory(Platform::MemoryAddress address
, Word value
);
102 /** Write a Byte of memory.
103 @param address The address to write to.
104 @param value The value to write.
106 void write_memory(Platform::MemoryAddress address
, Byte value
);
108 /** Attaches onto the PID @a pid. */
111 /** Places a breakpoint at a specified address.
112 @param address The address to place the breakpoint at.
114 void place_breakpoint(Platform::MemoryAddress address
);
116 /** Returns a breakpoint by iterator.
117 @param which The breakpoint to find.
118 @return A SmartPointer to the given breakpoint. Not valid if the breakpoint iterator does not exist.
120 Misc::SmartPointer
<Breakpoint
> get_breakpoint(breakpoint_list_t::size_type which
) const {
121 return breakpoint_list
.at(which
);
123 /** Returns a breakpoint by address.
124 @param address The address to search for.
125 @return A SmartPointer to the given breakpoint. Not valid if no breakpoint exists at @a address.
127 /*Misc::SmartPointer<Breakpoint> get_breakpoint_by_address(Platform::MemoryAddress address) const;*/
129 /** Handles a signal from the child.
130 @return The signal caught.
133 /** Continues execution, with a given signal sent to the child.
134 @param signal The signal to send; none if zero.
136 void continue_execution(int signal
= 0);
137 /** Tells the child to execute a single instruction. */
140 void wait_for_signal();
142 void add_signal_observer(Misc::SmartPointer
<PTraceSignalObserver
> new_observer
) {
143 signal_observer_list
.push_back(new_observer
);
147 } // namespace Interface
148 } // namespace Aesalon