OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 #include "debugger/core/debug_breakpoint.h" | |
5 #include "debugger/core/debug_logger.h" | |
6 #include "debugger/core/debuggee_iprocess.h" | |
7 | |
8 namespace { | |
9 const unsigned char kBreakpointCode = 0xCC; | |
10 } // namespace | |
11 | |
12 namespace debug { | |
13 Breakpoint::Breakpoint() | |
14 : address_(NULL), | |
15 original_code_byte_(0), | |
16 is_valid_(false), | |
17 process_(NULL) { | |
18 } | |
19 | |
20 Breakpoint::Breakpoint(void* address, IDebuggeeProcess* process) | |
21 : address_(address), | |
22 original_code_byte_(0), | |
23 is_valid_(false), | |
24 process_(process) { | |
25 } | |
26 | |
27 bool Breakpoint::is_valid() const { | |
28 return is_valid_; | |
29 } | |
30 | |
31 void* Breakpoint::address() const { | |
32 return address_; | |
33 } | |
34 | |
35 unsigned char Breakpoint::original_code_byte() const { | |
36 return original_code_byte_; | |
37 } | |
38 | |
39 bool Breakpoint::WriteBreakpointCode() { | |
40 if (!is_valid() || (NULL == process_)) | |
41 return false; | |
42 char code = kBreakpointCode; | |
43 bool res = process_->WriteMemory(address(), sizeof(code), &code); | |
44 | |
45 DBG_LOG("TR04.00", | |
46 "msg=Breakpoint::WriteBreakpointCode pid=%d addr=0x%p", | |
47 process_->id(), | |
48 address_); | |
49 return res; | |
50 } | |
51 | |
52 bool Breakpoint::RecoverCodeAtBreakpoint() { | |
53 if (!is_valid() || (NULL == process_)) | |
54 return false; | |
55 bool res = process_->WriteMemory(address(), | |
56 sizeof(original_code_byte_), | |
57 &original_code_byte_); | |
58 | |
59 DBG_LOG("TR04.01", | |
60 "msg=Breakpoint::RecoverCodeAtBreakpoint pid=%d addr=0x%p inst=0x%d", | |
61 process_->id(), | |
62 address_, | |
63 static_cast<int>(original_code_byte_)); | |
64 return res; | |
65 } | |
66 | |
67 bool Breakpoint::Init() { | |
68 if (NULL == process_) | |
69 return false; | |
70 if (!process_->ReadMemory(address(), | |
71 sizeof(original_code_byte_), | |
72 &original_code_byte_)) | |
73 return false; | |
74 | |
75 is_valid_ = true; | |
76 return (is_valid_ = WriteBreakpointCode()); | |
77 } | |
78 } // namespace debug | |
79 | |
OLD | NEW |