Filthy newline drama?
[craw.git] / craw / debug_registers.cpp
blob2a5b1a941eb7c4fac63cdc779ed4b5b6f6c1984c
1 #include <ail/string.hpp>
2 #include "debug_registers.hpp"
3 #include "utility.hpp"
5 namespace debug_register_data_type
7 uchar const
8 execute = 0,
9 write = 1,
10 read_write = 3;
13 namespace debug_register_data_size
15 uchar const
16 one = 0,
17 two = 1,
18 four = 3;
21 debug_register_data::debug_register_data()
25 debug_register_data::debug_register_data(unsigned address):
26 address(address),
27 type(debug_register_data_type::execute),
28 size(debug_register_data_size::one)
32 debug_register_data::debug_register_data(unsigned address, uchar type, uchar size):
33 address(address),
34 type(type),
35 size(size)
39 void set_debug_registers(CONTEXT & thread_context, unsigned address)
41 debug_register_vector entries;
42 entries.push_back(debug_register_data(address, debug_register_data_type::execute, debug_register_data_size::one));
43 set_debug_registers(thread_context, entries);
46 void set_debug_registers(CONTEXT & thread_context, debug_register_vector & entries)
48 DWORD * dr_addresses[] =
50 &thread_context.Dr0,
51 &thread_context.Dr1,
52 &thread_context.Dr2,
53 &thread_context.Dr3
56 thread_context.Dr6 = 0;
57 thread_context.Dr7 = 0;
59 thread_context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
61 for(std::size_t i = 0; i < 4 && i < entries.size(); i++)
63 debug_register_data & data = entries[i];
64 *(dr_addresses[i]) = data.address;
65 uchar high_group = (data.size << 2) | data.type;
66 thread_context.Dr7 |= (high_group << (4 * i + 16)) | (1 << (2 * i));
69 for(std::size_t i = entries.size(); i < 4; i++)
70 *(dr_addresses[i]) = 0;
73 void print_debug_registers(CONTEXT & thread_context)
75 write_line("DR0: " + ail::hex_string_32(thread_context.Dr0));
76 write_line("DR1: " + ail::hex_string_32(thread_context.Dr1));
77 write_line("DR2: " + ail::hex_string_32(thread_context.Dr2));
78 write_line("DR3: " + ail::hex_string_32(thread_context.Dr3));
79 write_line("DR7: " + ail::hex_string_32(thread_context.Dr7));