OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
7 | 7 |
8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
11 #include "vm/instructions.h" | 11 #include "vm/instructions.h" |
12 #include "vm/stub_code.h" | 12 #include "vm/stub_code.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 uword CodeBreakpoint::OrigStubAddress() const { | 16 uword CodeBreakpoint::OrigStubAddress() const { |
17 const Code& code = Code::Handle(code_); | 17 return saved_value_; |
18 const Array& object_pool = Array::Handle(code.ObjectPool()); | |
19 const uword offset = saved_value_; | |
20 ASSERT((offset % kWordSize) == 0); | |
21 const intptr_t index = (offset - Array::data_offset()) / kWordSize; | |
22 const uword stub_address = reinterpret_cast<uword>(object_pool.At(index)); | |
23 ASSERT(stub_address % kWordSize == 0); | |
24 return stub_address; | |
25 } | 18 } |
26 | 19 |
27 | 20 |
28 void CodeBreakpoint::PatchCode() { | 21 void CodeBreakpoint::PatchCode() { |
29 ASSERT(!is_enabled_); | 22 ASSERT(!is_enabled_); |
| 23 StubCode* stub_code = Isolate::Current()->stub_code(); |
| 24 uword stub_target = 0; |
| 25 switch (breakpoint_kind_) { |
| 26 case RawPcDescriptors::kIcCall: |
| 27 case RawPcDescriptors::kUnoptStaticCall: |
| 28 stub_target = stub_code->ICCallBreakpointEntryPoint(); |
| 29 break; |
| 30 case RawPcDescriptors::kClosureCall: |
| 31 stub_target = stub_code->ClosureCallBreakpointEntryPoint(); |
| 32 break; |
| 33 case RawPcDescriptors::kRuntimeCall: { |
| 34 stub_target = stub_code->RuntimeCallBreakpointEntryPoint(); |
| 35 break; |
| 36 } |
| 37 default: |
| 38 UNREACHABLE(); |
| 39 } |
30 const Code& code = Code::Handle(code_); | 40 const Code& code = Code::Handle(code_); |
31 const Instructions& instrs = Instructions::Handle(code.instructions()); | 41 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); |
32 { | 42 CodePatcher::PatchPoolPointerCallAt(pc_, code, stub_target); |
33 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | |
34 switch (breakpoint_kind_) { | |
35 case RawPcDescriptors::kIcCall: | |
36 case RawPcDescriptors::kUnoptStaticCall: { | |
37 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); | |
38 ASSERT((offset > 0) && ((offset & 0x7) == 0)); | |
39 saved_value_ = static_cast<uword>(offset); | |
40 const uint32_t stub_offset = | |
41 InstructionPattern::OffsetFromPPIndex( | |
42 Assembler::kICCallBreakpointCPIndex); | |
43 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); | |
44 break; | |
45 } | |
46 case RawPcDescriptors::kClosureCall: { | |
47 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); | |
48 ASSERT((offset > 0) && ((offset & 0x7) == 0)); | |
49 saved_value_ = static_cast<uword>(offset); | |
50 const uint32_t stub_offset = | |
51 InstructionPattern::OffsetFromPPIndex( | |
52 Assembler::kClosureCallBreakpointCPIndex); | |
53 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); | |
54 break; | |
55 } | |
56 case RawPcDescriptors::kRuntimeCall: { | |
57 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); | |
58 ASSERT((offset > 0) && ((offset & 0x7) == 0)); | |
59 saved_value_ = static_cast<uword>(offset); | |
60 const uint32_t stub_offset = | |
61 InstructionPattern::OffsetFromPPIndex( | |
62 Assembler::kRuntimeCallBreakpointCPIndex); | |
63 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); | |
64 break; | |
65 } | |
66 default: | |
67 UNREACHABLE(); | |
68 } | |
69 } | |
70 is_enabled_ = true; | 43 is_enabled_ = true; |
71 } | 44 } |
72 | 45 |
73 | 46 |
74 void CodeBreakpoint::RestoreCode() { | 47 void CodeBreakpoint::RestoreCode() { |
75 ASSERT(is_enabled_); | 48 ASSERT(is_enabled_); |
76 const Code& code = Code::Handle(code_); | 49 const Code& code = Code::Handle(code_); |
77 const Instructions& instrs = Instructions::Handle(code.instructions()); | 50 switch (breakpoint_kind_) { |
78 { | 51 case RawPcDescriptors::kIcCall: |
79 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 52 case RawPcDescriptors::kUnoptStaticCall: |
80 switch (breakpoint_kind_) { | 53 case RawPcDescriptors::kClosureCall: |
81 case RawPcDescriptors::kIcCall: | 54 case RawPcDescriptors::kRuntimeCall: { |
82 case RawPcDescriptors::kUnoptStaticCall: | 55 CodePatcher::PatchPoolPointerCallAt(pc_, code, saved_value_); |
83 case RawPcDescriptors::kClosureCall: | 56 break; |
84 case RawPcDescriptors::kRuntimeCall: { | |
85 CodePatcher::SetPoolOffsetAt(pc_, static_cast<int32_t>(saved_value_)); | |
86 break; | |
87 } | |
88 default: | |
89 UNREACHABLE(); | |
90 } | 57 } |
| 58 default: |
| 59 UNREACHABLE(); |
91 } | 60 } |
92 is_enabled_ = false; | 61 is_enabled_ = false; |
93 } | 62 } |
94 | 63 |
95 } // namespace dart | 64 } // namespace dart |
96 | 65 |
97 #endif // defined TARGET_ARCH_ARM64 | 66 #endif // defined TARGET_ARCH_ARM64 |
OLD | NEW |