2 #include <sys/ptrace.h>
5 #include "PTracePortal.h"
10 Platform::MemoryAddress
PTracePortal::get_register(register_e which
) const {
11 struct user_regs_struct regs
;
12 ptrace(PTRACE_GETREGS
, pid
, 0, ®s
);
14 #if AESALON_PLATFORM == AESALON_PLATFORM_x86_64
47 #elif AESALON_PLATFORM == AESALON_PLATFORM_x86
50 /* TODO: implement the rest of the 32-bit registers */
61 Word
PTracePortal::read_memory(Platform::MemoryAddress address
) const {
62 Word ret
= ptrace(PTRACE_PEEKDATA
, pid
, address
, NULL
);
67 void PTracePortal::write_memory(Platform::MemoryAddress address
, Word value
) {
68 ptrace(PTRACE_POKEDATA
, pid
, address
, value
);
71 void PTracePortal::write_memory(Platform::MemoryAddress address
, Byte value
) {
72 Word original
= read_memory(address
);
73 /* Clear the first eight bits of original */
74 original
&= ~Word(0xff);
75 /* Set first eight bits to new value */
77 ptrace(PTRACE_POKEDATA
, pid
, address
, value
);
81 void PTracePortal::attach() {
82 ptrace(PTRACE_ATTACH
, pid
, NULL
, NULL
);
85 void PTracePortal::place_breakpoint(Platform::MemoryAddress address
) {
86 add_breakpoint(new Breakpoint(address
, read_memory(address
) & 0xff));
87 write_memory(address
, Byte(0xcc));
90 Misc::SmartPointer
<Breakpoint
> PTracePortal::get_breakpoint_by_address(Platform::MemoryAddress address
) const {
91 breakpoint_list_t::const_iterator i
= breakpoint_list
.begin();
92 for(; i
!= breakpoint_list
.end(); i
++) {
93 if((*i
)->get_address() == address
) return *i
;
98 } // namespace Interface
99 } // namespace Aesalon