OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
7 | 7 |
8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
9 | 9 |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
11 #include "vm/cpu.h" | 11 #include "vm/cpu.h" |
12 #include "vm/disassembler.h" | 12 #include "vm/disassembler.h" |
13 #include "vm/object.h" | 13 #include "vm/object.h" |
14 #include "vm/os.h" | 14 #include "vm/os.h" |
15 #include "vm/stack_frame.h" | 15 #include "vm/stack_frame.h" |
16 #include "vm/stub_code.h" | 16 #include "vm/stub_code.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 | 19 |
20 RawCode* CodeBreakpoint::OrigStubAddress() const { | 20 uword CodeBreakpoint::OrigStubAddress() const { |
21 return saved_value_; | 21 return saved_value_; |
22 } | 22 } |
23 | 23 |
24 | 24 |
25 void CodeBreakpoint::PatchCode() { | 25 void CodeBreakpoint::PatchCode() { |
26 ASSERT(!is_enabled_); | 26 ASSERT(!is_enabled_); |
27 const Code& code = Code::Handle(code_); | 27 const Code& code = Code::Handle(code_); |
28 const Instructions& instrs = Instructions::Handle(code.instructions()); | 28 const Instructions& instrs = Instructions::Handle(code.instructions()); |
29 Code& stub_target = Code::Handle(); | |
30 { | 29 { |
31 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 30 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
32 switch (breakpoint_kind_) { | 31 switch (breakpoint_kind_) { |
33 case RawPcDescriptors::kIcCall: | 32 case RawPcDescriptors::kIcCall: |
34 case RawPcDescriptors::kUnoptStaticCall: { | 33 case RawPcDescriptors::kUnoptStaticCall: { |
35 stub_target = StubCode::ICCallBreakpoint_entry()->code(); | 34 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); |
| 35 CodePatcher::PatchStaticCallAt( |
| 36 pc_, code, StubCode::ICCallBreakpoint_entry()->EntryPoint()); |
36 break; | 37 break; |
37 } | 38 } |
38 case RawPcDescriptors::kRuntimeCall: { | 39 case RawPcDescriptors::kRuntimeCall: { |
39 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); | 40 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); |
40 stub_target = StubCode::RuntimeCallBreakpoint_entry()->code(); | 41 CodePatcher::PatchStaticCallAt( |
| 42 pc_, code, StubCode::RuntimeCallBreakpoint_entry()->EntryPoint()); |
41 break; | 43 break; |
42 } | 44 } |
43 default: | 45 default: |
44 UNREACHABLE(); | 46 UNREACHABLE(); |
45 } | 47 } |
46 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); | |
47 CodePatcher::PatchStaticCallAt(pc_, code, stub_target); | |
48 } | 48 } |
49 is_enabled_ = true; | 49 is_enabled_ = true; |
50 } | 50 } |
51 | 51 |
52 | 52 |
53 void CodeBreakpoint::RestoreCode() { | 53 void CodeBreakpoint::RestoreCode() { |
54 ASSERT(is_enabled_); | 54 ASSERT(is_enabled_); |
55 const Code& code = Code::Handle(code_); | 55 const Code& code = Code::Handle(code_); |
56 const Instructions& instrs = Instructions::Handle(code.instructions()); | 56 const Instructions& instrs = Instructions::Handle(code.instructions()); |
57 { | 57 { |
58 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 58 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
59 switch (breakpoint_kind_) { | 59 switch (breakpoint_kind_) { |
60 case RawPcDescriptors::kIcCall: | 60 case RawPcDescriptors::kIcCall: |
61 case RawPcDescriptors::kUnoptStaticCall: | 61 case RawPcDescriptors::kUnoptStaticCall: |
62 case RawPcDescriptors::kRuntimeCall: { | 62 case RawPcDescriptors::kRuntimeCall: { |
63 CodePatcher::PatchStaticCallAt(pc_, code, Code::Handle(saved_value_)); | 63 CodePatcher::PatchStaticCallAt(pc_, code, saved_value_); |
64 break; | 64 break; |
65 } | 65 } |
66 default: | 66 default: |
67 UNREACHABLE(); | 67 UNREACHABLE(); |
68 } | 68 } |
69 } | 69 } |
70 is_enabled_ = false; | 70 is_enabled_ = false; |
71 } | 71 } |
72 | 72 |
73 } // namespace dart | 73 } // namespace dart |
74 | 74 |
75 #endif // defined TARGET_ARCH_IA32 | 75 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |