| 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_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
| 9 | 9 |
| 10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 ASSERT((offset % kWordSize) == 0); | 43 ASSERT((offset % kWordSize) == 0); |
| 44 const intptr_t index = (offset - Array::data_offset()) / kWordSize; | 44 const intptr_t index = (offset - Array::data_offset()) / kWordSize; |
| 45 const uword stub_address = reinterpret_cast<uword>(object_pool.At(index)); | 45 const uword stub_address = reinterpret_cast<uword>(object_pool.At(index)); |
| 46 ASSERT(stub_address % kWordSize == 0); | 46 ASSERT(stub_address % kWordSize == 0); |
| 47 return stub_address; | 47 return stub_address; |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 void CodeBreakpoint::PatchCode() { | 51 void CodeBreakpoint::PatchCode() { |
| 52 ASSERT(!is_enabled_); | 52 ASSERT(!is_enabled_); |
| 53 switch (breakpoint_kind_) { | 53 const Code& code = |
| 54 case PcDescriptors::kIcCall: { | 54 Code::Handle(Function::Handle(function_).unoptimized_code()); |
| 55 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); | 55 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 56 ASSERT((offset > 0) && ((offset % 8) == 7)); | 56 { |
| 57 saved_value_ = static_cast<uword>(offset); | 57 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 58 const int32_t stub_offset = | 58 switch (breakpoint_kind_) { |
| 59 InstructionPattern::OffsetFromPPIndex( | 59 case PcDescriptors::kIcCall: { |
| 60 Assembler::kBreakpointDynamicCPIndex); | 60 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); |
| 61 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); | 61 ASSERT((offset > 0) && ((offset % 8) == 7)); |
| 62 break; | 62 saved_value_ = static_cast<uword>(offset); |
| 63 const int32_t stub_offset = |
| 64 InstructionPattern::OffsetFromPPIndex( |
| 65 Assembler::kBreakpointDynamicCPIndex); |
| 66 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); |
| 67 break; |
| 68 } |
| 69 case PcDescriptors::kUnoptStaticCall: { |
| 70 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); |
| 71 ASSERT((offset > 0) && ((offset % 8) == 7)); |
| 72 saved_value_ = static_cast<uword>(offset); |
| 73 const uint32_t stub_offset = |
| 74 InstructionPattern::OffsetFromPPIndex( |
| 75 Assembler::kBreakpointStaticCPIndex); |
| 76 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); |
| 77 break; |
| 78 } |
| 79 case PcDescriptors::kRuntimeCall: |
| 80 case PcDescriptors::kClosureCall: |
| 81 case PcDescriptors::kReturn: { |
| 82 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); |
| 83 ASSERT((offset > 0) && ((offset % 8) == 7)); |
| 84 saved_value_ = static_cast<uword>(offset); |
| 85 const uint32_t stub_offset = |
| 86 InstructionPattern::OffsetFromPPIndex( |
| 87 Assembler::kBreakpointRuntimeCPIndex); |
| 88 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); |
| 89 break; |
| 90 } |
| 91 default: |
| 92 UNREACHABLE(); |
| 63 } | 93 } |
| 64 case PcDescriptors::kUnoptStaticCall: { | |
| 65 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); | |
| 66 ASSERT((offset > 0) && ((offset % 8) == 7)); | |
| 67 saved_value_ = static_cast<uword>(offset); | |
| 68 const uint32_t stub_offset = | |
| 69 InstructionPattern::OffsetFromPPIndex( | |
| 70 Assembler::kBreakpointStaticCPIndex); | |
| 71 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); | |
| 72 break; | |
| 73 } | |
| 74 case PcDescriptors::kRuntimeCall: | |
| 75 case PcDescriptors::kClosureCall: | |
| 76 case PcDescriptors::kReturn: { | |
| 77 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_); | |
| 78 ASSERT((offset > 0) && ((offset % 8) == 7)); | |
| 79 saved_value_ = static_cast<uword>(offset); | |
| 80 const uint32_t stub_offset = | |
| 81 InstructionPattern::OffsetFromPPIndex( | |
| 82 Assembler::kBreakpointRuntimeCPIndex); | |
| 83 CodePatcher::SetPoolOffsetAt(pc_, stub_offset); | |
| 84 break; | |
| 85 } | |
| 86 default: | |
| 87 UNREACHABLE(); | |
| 88 } | 94 } |
| 89 is_enabled_ = true; | 95 is_enabled_ = true; |
| 90 } | 96 } |
| 91 | 97 |
| 92 | 98 |
| 93 void CodeBreakpoint::RestoreCode() { | 99 void CodeBreakpoint::RestoreCode() { |
| 94 ASSERT(is_enabled_); | 100 ASSERT(is_enabled_); |
| 95 switch (breakpoint_kind_) { | 101 const Code& code = |
| 96 case PcDescriptors::kIcCall: | 102 Code::Handle(Function::Handle(function_).unoptimized_code()); |
| 97 case PcDescriptors::kUnoptStaticCall: | 103 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 98 case PcDescriptors::kClosureCall: | 104 { |
| 99 case PcDescriptors::kRuntimeCall: | 105 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 100 case PcDescriptors::kReturn: { | 106 switch (breakpoint_kind_) { |
| 101 CodePatcher::SetPoolOffsetAt(pc_, static_cast<int32_t>(saved_value_)); | 107 case PcDescriptors::kIcCall: |
| 102 break; | 108 case PcDescriptors::kUnoptStaticCall: |
| 109 case PcDescriptors::kClosureCall: |
| 110 case PcDescriptors::kRuntimeCall: |
| 111 case PcDescriptors::kReturn: { |
| 112 CodePatcher::SetPoolOffsetAt(pc_, static_cast<int32_t>(saved_value_)); |
| 113 break; |
| 114 } |
| 115 default: |
| 116 UNREACHABLE(); |
| 103 } | 117 } |
| 104 default: | |
| 105 UNREACHABLE(); | |
| 106 } | 118 } |
| 107 is_enabled_ = false; | 119 is_enabled_ = false; |
| 108 } | 120 } |
| 109 | 121 |
| 110 | 122 |
| 111 } // namespace dart | 123 } // namespace dart |
| 112 | 124 |
| 113 #endif // defined TARGET_ARCH_X64 | 125 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |