Removed usage of BidirectionalPipe.
[aesalon.git] / src / interface / ptrace / Portal.h
blob4fb16c57aa4730fe70554c73b82c87a6a2f9d71b
1 #ifndef AESALON_INTERFACE_PTRACE_PORTAL_H
2 #define AESALON_INTERFACE_PTRACE_PORTAL_H
4 #include <sys/types.h>
5 #include <sys/user.h>
7 #include <vector>
9 #include "Breakpoint.h"
10 #include "Types.h"
11 #include "SignalObserver.h"
12 #include "platform/MemoryAddress.h"
13 #include "platform/ArgumentList.h"
14 #include "misc/SmartPointer.h"
16 namespace Aesalon {
17 namespace Interface {
18 namespace PTrace {
20 class PTraceException : public Misc::Exception {
21 public:
22 PTraceException(std::string message) : Misc::Exception(message) {}
23 virtual ~PTraceException() {}
26 class Portal {
27 public:
28 /** An enum representing the different registers available. */
29 enum register_e {
30 #if AESALON_PLATFORM == AESALON_PLATFORM_x86_64
31 RAX,
32 RBX,
33 RCX,
34 RDX,
35 R9,
36 R10,
37 R11,
38 R12,
39 R13,
40 R14,
41 R15,
42 RBP,
43 RSP,
44 RIP,
45 RDI,
46 RSI,
47 #elif AESALON_PLATFORM == AESALON_PLATFORM_x86
48 EAX,
49 EBX,
50 ECX,
51 EDX,
52 EBP,
53 ESP,
54 EIP,
55 EDI,
56 ESI,
57 #endif
58 CS,
62 typedef std::vector<Misc::SmartPointer<Breakpoint> > breakpoint_list_t;
64 typedef std::vector<Misc::SmartPointer<SignalObserver> > signal_observer_list_t;
65 private:
66 /** The PID of the attached process. */
67 pid_t pid;
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();
82 public:
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. */
88 virtual ~Portal() {}
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. */
113 void attach();
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. */
139 void single_step();
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
150 #endif