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_X64) |
7 | |
8 | #include "vm/debugger.h" |
9 | |
10 | #include "vm/code_patcher.h" |
11 | #include "vm/cpu.h" |
12 | #include "vm/instructions.h" |
13 | #include "vm/stub_code.h" |
14 | |
15 | namespace dart { |
16 | |
17 | #ifndef PRODUCT |
18 | |
19 | CodePtr CodeBreakpoint::OrigStubAddress() const { |
20 | return saved_value_; |
21 | } |
22 | |
23 | void CodeBreakpoint::PatchCode() { |
24 | ASSERT(!is_enabled_); |
25 | Code& stub_target = Code::Handle(); |
26 | switch (breakpoint_kind_) { |
27 | case PcDescriptorsLayout::kIcCall: |
28 | stub_target = StubCode::ICCallBreakpoint().raw(); |
29 | break; |
30 | case PcDescriptorsLayout::kUnoptStaticCall: |
31 | stub_target = StubCode::UnoptStaticCallBreakpoint().raw(); |
32 | break; |
33 | case PcDescriptorsLayout::kRuntimeCall: |
34 | stub_target = StubCode::RuntimeCallBreakpoint().raw(); |
35 | break; |
36 | default: |
37 | UNREACHABLE(); |
38 | } |
39 | const Code& code = Code::Handle(code_); |
40 | saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); |
41 | CodePatcher::PatchPoolPointerCallAt(pc_, code, stub_target); |
42 | is_enabled_ = true; |
43 | } |
44 | |
45 | void CodeBreakpoint::RestoreCode() { |
46 | ASSERT(is_enabled_); |
47 | const Code& code = Code::Handle(code_); |
48 | switch (breakpoint_kind_) { |
49 | case PcDescriptorsLayout::kIcCall: |
50 | case PcDescriptorsLayout::kUnoptStaticCall: |
51 | case PcDescriptorsLayout::kRuntimeCall: { |
52 | CodePatcher::PatchPoolPointerCallAt(pc_, code, |
53 | Code::Handle(saved_value_)); |
54 | break; |
55 | } |
56 | default: |
57 | UNREACHABLE(); |
58 | } |
59 | is_enabled_ = false; |
60 | } |
61 | |
62 | #endif // !PRODUCT |
63 | |
64 | } // namespace dart |
65 | |
66 | #endif // defined TARGET_ARCH_X64 |
67 |