| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_DBC) | 6 #if defined(TARGET_ARCH_DBC) |
| 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 #ifndef PRODUCT | 16 #ifndef PRODUCT |
| 17 | 17 |
| 18 RawCode* CodeBreakpoint::OrigStubAddress() const { | 18 RawCode* CodeBreakpoint::OrigStubAddress() const { |
| 19 return reinterpret_cast<RawCode*>(static_cast<uintptr_t>(saved_value_)); | 19 return reinterpret_cast<RawCode*>(static_cast<uintptr_t>(saved_value_)); |
| 20 } | 20 } |
| 21 | 21 |
| 22 | 22 |
| 23 static Instr* CallInstructionFromReturnAddress(uword pc) { | 23 static Instr* CallInstructionFromReturnAddress(uword pc) { |
| 24 return reinterpret_cast<Instr*>(pc) - 1; | 24 return reinterpret_cast<Instr*>(pc) - 1; |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 static Instr* FastSmiInstructionFromReturnAddress(uword pc) { |
| 29 return reinterpret_cast<Instr*>(pc) - 2; |
| 30 } |
| 31 |
| 32 |
| 28 void CodeBreakpoint::PatchCode() { | 33 void CodeBreakpoint::PatchCode() { |
| 29 ASSERT(!is_enabled_); | 34 ASSERT(!is_enabled_); |
| 30 const Code& code = Code::Handle(code_); | 35 const Code& code = Code::Handle(code_); |
| 31 const Instructions& instrs = Instructions::Handle(code.instructions()); | 36 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 32 { | 37 { |
| 33 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 38 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 34 saved_value_ = *CallInstructionFromReturnAddress(pc_); | 39 saved_value_ = *CallInstructionFromReturnAddress(pc_); |
| 35 switch (breakpoint_kind_) { | 40 switch (breakpoint_kind_) { |
| 36 case RawPcDescriptors::kIcCall: | 41 case RawPcDescriptors::kIcCall: |
| 37 case RawPcDescriptors::kUnoptStaticCall: { | 42 case RawPcDescriptors::kUnoptStaticCall: { |
| 38 // DebugBreak has an A operand matching the call it replaces. | 43 // DebugBreak has an A operand matching the call it replaces. |
| 39 // This ensures that Return instructions continue to work - as they | 44 // This ensures that Return instructions continue to work - as they |
| 40 // look at calls to figure out how many arguments to drop. | 45 // look at calls to figure out how many arguments to drop. |
| 41 *CallInstructionFromReturnAddress(pc_) = | 46 *CallInstructionFromReturnAddress(pc_) = |
| 42 Bytecode::Encode(Bytecode::kDebugBreak, | 47 Bytecode::Encode(Bytecode::kDebugBreak, |
| 43 Bytecode::DecodeArgc(saved_value_), | 48 Bytecode::DecodeArgc(saved_value_), |
| 44 0, | 49 0, |
| 45 0); | 50 0); |
| 46 break; | 51 break; |
| 47 } | 52 } |
| 48 | 53 |
| 49 case RawPcDescriptors::kRuntimeCall: { | 54 case RawPcDescriptors::kRuntimeCall: { |
| 50 *CallInstructionFromReturnAddress(pc_) = Bytecode::kDebugBreak; | 55 *CallInstructionFromReturnAddress(pc_) = Bytecode::kDebugBreak; |
| 51 break; | 56 break; |
| 52 } | 57 } |
| 53 | 58 |
| 54 default: | 59 default: |
| 55 UNREACHABLE(); | 60 UNREACHABLE(); |
| 56 } | 61 } |
| 62 |
| 63 // If this call is the fall-through for a fast Smi op, also disable the fast |
| 64 // Smi op. |
| 65 if ((Bytecode::DecodeOpcode(saved_value_) == Bytecode::kInstanceCall2) && |
| 66 Bytecode::IsFastSmiOpcode(*FastSmiInstructionFromReturnAddress(pc_))) { |
| 67 saved_value_fastsmi_ = *FastSmiInstructionFromReturnAddress(pc_); |
| 68 *FastSmiInstructionFromReturnAddress(pc_) = |
| 69 Bytecode::Encode(Bytecode::kNop, 0, 0, 0); |
| 70 } else { |
| 71 saved_value_fastsmi_ = Bytecode::kTrap; |
| 72 } |
| 57 } | 73 } |
| 58 is_enabled_ = true; | 74 is_enabled_ = true; |
| 59 } | 75 } |
| 60 | 76 |
| 61 | 77 |
| 62 void CodeBreakpoint::RestoreCode() { | 78 void CodeBreakpoint::RestoreCode() { |
| 63 ASSERT(is_enabled_); | 79 ASSERT(is_enabled_); |
| 64 const Code& code = Code::Handle(code_); | 80 const Code& code = Code::Handle(code_); |
| 65 const Instructions& instrs = Instructions::Handle(code.instructions()); | 81 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 66 { | 82 { |
| 67 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 83 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 68 switch (breakpoint_kind_) { | 84 switch (breakpoint_kind_) { |
| 69 case RawPcDescriptors::kIcCall: | 85 case RawPcDescriptors::kIcCall: |
| 70 case RawPcDescriptors::kUnoptStaticCall: | 86 case RawPcDescriptors::kUnoptStaticCall: |
| 71 case RawPcDescriptors::kRuntimeCall: { | 87 case RawPcDescriptors::kRuntimeCall: { |
| 72 *CallInstructionFromReturnAddress(pc_) = saved_value_; | 88 *CallInstructionFromReturnAddress(pc_) = saved_value_; |
| 73 break; | 89 break; |
| 74 } | 90 } |
| 75 default: | 91 default: |
| 76 UNREACHABLE(); | 92 UNREACHABLE(); |
| 77 } | 93 } |
| 94 |
| 95 if (saved_value_fastsmi_ != Bytecode::kTrap) { |
| 96 Instr current_instr = *FastSmiInstructionFromReturnAddress(pc_); |
| 97 ASSERT(Bytecode::DecodeOpcode(current_instr) == Bytecode::kNop); |
| 98 *FastSmiInstructionFromReturnAddress(pc_) = saved_value_fastsmi_; |
| 99 } |
| 78 } | 100 } |
| 79 is_enabled_ = false; | 101 is_enabled_ = false; |
| 80 } | 102 } |
| 81 | 103 |
| 82 #endif // !PRODUCT | 104 #endif // !PRODUCT |
| 83 | 105 |
| 84 } // namespace dart | 106 } // namespace dart |
| 85 | 107 |
| 86 #endif // defined TARGET_ARCH_DBC | 108 #endif // defined TARGET_ARCH_DBC |
| OLD | NEW |