| 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 |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #include "vm/globals.h" |
| 6 | #if defined(TARGET_ARCH_ARM64) |
| 7 | |
| 8 | #include "vm/code_patcher.h" |
| 9 | #include "vm/cpu.h" |
| 10 | #include "vm/debugger.h" |
| 11 | #include "vm/instructions.h" |
| 12 | #include "vm/stub_code.h" |
| 13 | |
| 14 | namespace dart { |
| 15 | |
| 16 | #ifndef PRODUCT |
| 17 | |
| 18 | CodePtr CodeBreakpoint::OrigStubAddress() const { |
| 19 | return saved_value_; |
| 20 | } |
| 21 | |
| 22 | void CodeBreakpoint::PatchCode() { |
| 23 | ASSERT(!is_enabled_); |
| 24 | const Code& code = Code::Handle(code_); |
| 25 | switch (breakpoint_kind_) { |
| 26 | case PcDescriptorsLayout::kIcCall: { |
| 27 | Object& data = Object::Handle(); |
| 28 | saved_value_ = CodePatcher::GetInstanceCallAt(pc_, code, &data); |
| 29 | CodePatcher::PatchInstanceCallAt(pc_, code, data, |
| 30 | StubCode::ICCallBreakpoint()); |
| 31 | break; |
| 32 | } |
| 33 | case PcDescriptorsLayout::kUnoptStaticCall: { |
| 34 | saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); |
| 35 | CodePatcher::PatchPoolPointerCallAt( |
| 36 | pc_, code, StubCode::UnoptStaticCallBreakpoint()); |
| 37 | break; |
| 38 | } |
| 39 | case PcDescriptorsLayout::kRuntimeCall: { |
| 40 | saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); |
| 41 | CodePatcher::PatchPoolPointerCallAt(pc_, code, |
| 42 | StubCode::RuntimeCallBreakpoint()); |
| 43 | break; |
| 44 | } |
| 45 | default: |
| 46 | UNREACHABLE(); |
| 47 | } |
| 48 | is_enabled_ = true; |
| 49 | } |
| 50 | |
| 51 | void CodeBreakpoint::RestoreCode() { |
| 52 | ASSERT(is_enabled_); |
| 53 | const Code& code = Code::Handle(code_); |
| 54 | switch (breakpoint_kind_) { |
| 55 | case PcDescriptorsLayout::kIcCall: { |
| 56 | Object& data = Object::Handle(); |
| 57 | CodePatcher::GetInstanceCallAt(pc_, code, &data); |
| 58 | CodePatcher::PatchInstanceCallAt(pc_, code, data, |
| 59 | Code::Handle(saved_value_)); |
| 60 | break; |
| 61 | } |
| 62 | case PcDescriptorsLayout::kUnoptStaticCall: |
| 63 | case PcDescriptorsLayout::kRuntimeCall: { |
| 64 | CodePatcher::PatchPoolPointerCallAt(pc_, code, |
| 65 | Code::Handle(saved_value_)); |
| 66 | break; |
| 67 | } |
| 68 | default: |
| 69 | UNREACHABLE(); |
| 70 | } |
| 71 | is_enabled_ = false; |
| 72 | } |
| 73 | |
| 74 | #endif // !PRODUCT |
| 75 | |
| 76 | } // namespace dart |
| 77 | |
| 78 | #endif // defined TARGET_ARCH_ARM64 |
| 79 | |