| 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 |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #include "vm/globals.h" |
| 6 | #if defined(TARGET_ARCH_ARM) |
| 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 | Code& stub_target = Code::Handle(); |
| 25 | switch (breakpoint_kind_) { |
| 26 | case PcDescriptorsLayout::kIcCall: |
| 27 | stub_target = StubCode::ICCallBreakpoint().raw(); |
| 28 | break; |
| 29 | case PcDescriptorsLayout::kUnoptStaticCall: |
| 30 | stub_target = StubCode::UnoptStaticCallBreakpoint().raw(); |
| 31 | break; |
| 32 | case PcDescriptorsLayout::kRuntimeCall: |
| 33 | stub_target = StubCode::RuntimeCallBreakpoint().raw(); |
| 34 | break; |
| 35 | default: |
| 36 | UNREACHABLE(); |
| 37 | } |
| 38 | const Code& code = Code::Handle(code_); |
| 39 | saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); |
| 40 | CodePatcher::PatchStaticCallAt(pc_, code, stub_target); |
| 41 | is_enabled_ = true; |
| 42 | } |
| 43 | |
| 44 | void CodeBreakpoint::RestoreCode() { |
| 45 | ASSERT(is_enabled_); |
| 46 | const Code& code = Code::Handle(code_); |
| 47 | switch (breakpoint_kind_) { |
| 48 | case PcDescriptorsLayout::kIcCall: |
| 49 | case PcDescriptorsLayout::kUnoptStaticCall: |
| 50 | case PcDescriptorsLayout::kRuntimeCall: { |
| 51 | CodePatcher::PatchStaticCallAt(pc_, code, Code::Handle(saved_value_)); |
| 52 | break; |
| 53 | } |
| 54 | default: |
| 55 | UNREACHABLE(); |
| 56 | } |
| 57 | is_enabled_ = false; |
| 58 | } |
| 59 | |
| 60 | #endif // !PRODUCT |
| 61 | |
| 62 | } // namespace dart |
| 63 | |
| 64 | #endif // defined TARGET_ARCH_ARM |
| 65 | |