Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, 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_IA32) | 6 #if defined(TARGET_ARCH_DBC) |
| 7 | |
| 8 #include "vm/debugger.h" | |
| 9 | 7 |
| 10 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
| 11 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
| 12 #include "vm/disassembler.h" | 10 #include "vm/debugger.h" |
| 13 #include "vm/object.h" | 11 #include "vm/instructions.h" |
| 14 #include "vm/os.h" | |
| 15 #include "vm/stack_frame.h" | |
| 16 #include "vm/stub_code.h" | 12 #include "vm/stub_code.h" |
| 13 #include "vm/log.h" | |
|
zra
2016/04/08 22:37:35
move above stub_code.h
Vyacheslav Egorov (Google)
2016/04/11 10:49:11
Done.
| |
| 17 | 14 |
| 18 namespace dart { | 15 namespace dart { |
| 19 | 16 |
| 20 #ifndef PRODUCT | 17 #ifndef PRODUCT |
| 21 | 18 |
| 22 RawCode* CodeBreakpoint::OrigStubAddress() const { | 19 RawCode* CodeBreakpoint::OrigStubAddress() const { |
| 23 return saved_value_; | 20 return reinterpret_cast<RawCode*>(static_cast<uintptr_t>(saved_value_)); |
| 24 } | 21 } |
| 25 | 22 |
| 26 | 23 |
| 27 void CodeBreakpoint::PatchCode() { | 24 void CodeBreakpoint::PatchCode() { |
| 28 ASSERT(!is_enabled_); | 25 ASSERT(!is_enabled_); |
| 29 const Code& code = Code::Handle(code_); | 26 const Code& code = Code::Handle(code_); |
| 30 const Instructions& instrs = Instructions::Handle(code.instructions()); | 27 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 31 Code& stub_target = Code::Handle(); | |
| 32 { | 28 { |
| 33 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 29 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 30 saved_value_ = reinterpret_cast<uint32_t*>(pc_)[-1]; | |
|
zra
2016/04/08 22:37:35
A comment about what is going on here could be use
Vyacheslav Egorov (Google)
2016/04/11 10:49:10
Done.
| |
| 34 switch (breakpoint_kind_) { | 31 switch (breakpoint_kind_) { |
| 35 case RawPcDescriptors::kIcCall: | 32 case RawPcDescriptors::kIcCall: |
| 36 case RawPcDescriptors::kUnoptStaticCall: { | 33 case RawPcDescriptors::kUnoptStaticCall: { |
| 37 stub_target = StubCode::ICCallBreakpoint_entry()->code(); | 34 // DebugBreak has A operand matching the call it replaces. |
|
zra
2016/04/08 22:37:35
an operand
Vyacheslav Egorov (Google)
2016/04/11 10:49:10
Done.
| |
| 35 // This ensures that Return instructions continue to work - as they | |
| 36 // look at calls to figure out how many arguments to drop. | |
| 37 reinterpret_cast<uint32_t*>(pc_)[-1] = | |
|
zra
2016/04/08 22:37:35
Since this appears a few times, maybe calculate th
Vyacheslav Egorov (Google)
2016/04/11 10:49:10
Done.
| |
| 38 Bytecode::Encode(Bytecode::kDebugBreak, | |
| 39 Bytecode::DecodeArgc(saved_value_), | |
| 40 0, | |
| 41 0); | |
| 38 break; | 42 break; |
| 39 } | 43 } |
| 44 | |
| 40 case RawPcDescriptors::kRuntimeCall: { | 45 case RawPcDescriptors::kRuntimeCall: { |
| 41 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); | 46 reinterpret_cast<uint32_t*>(pc_)[-1] = Bytecode::kDebugBreak; |
| 42 stub_target = StubCode::RuntimeCallBreakpoint_entry()->code(); | |
| 43 break; | 47 break; |
| 44 } | 48 } |
| 49 | |
| 45 default: | 50 default: |
| 46 UNREACHABLE(); | 51 UNREACHABLE(); |
| 47 } | 52 } |
| 48 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); | |
| 49 CodePatcher::PatchStaticCallAt(pc_, code, stub_target); | |
| 50 } | 53 } |
| 51 is_enabled_ = true; | 54 is_enabled_ = true; |
| 52 } | 55 } |
| 53 | 56 |
| 54 | 57 |
| 55 void CodeBreakpoint::RestoreCode() { | 58 void CodeBreakpoint::RestoreCode() { |
| 56 ASSERT(is_enabled_); | 59 ASSERT(is_enabled_); |
| 57 const Code& code = Code::Handle(code_); | 60 const Code& code = Code::Handle(code_); |
| 58 const Instructions& instrs = Instructions::Handle(code.instructions()); | 61 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 59 { | 62 { |
| 60 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 63 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 61 switch (breakpoint_kind_) { | 64 switch (breakpoint_kind_) { |
| 62 case RawPcDescriptors::kIcCall: | 65 case RawPcDescriptors::kIcCall: |
| 63 case RawPcDescriptors::kUnoptStaticCall: | 66 case RawPcDescriptors::kUnoptStaticCall: |
| 64 case RawPcDescriptors::kRuntimeCall: { | 67 case RawPcDescriptors::kRuntimeCall: { |
| 65 CodePatcher::PatchStaticCallAt(pc_, code, Code::Handle(saved_value_)); | 68 reinterpret_cast<uint32_t*>(pc_)[-1] = saved_value_; |
|
zra
2016/04/08 22:37:35
Yah, maybe add something to CodeBreakpoint to calc
Vyacheslav Egorov (Google)
2016/04/11 10:49:11
Done.
| |
| 66 break; | 69 break; |
| 67 } | 70 } |
| 68 default: | 71 default: |
| 69 UNREACHABLE(); | 72 UNREACHABLE(); |
| 70 } | 73 } |
| 71 } | 74 } |
| 72 is_enabled_ = false; | 75 is_enabled_ = false; |
| 73 } | 76 } |
| 74 | 77 |
| 75 #endif // !PRODUCT | 78 #endif // !PRODUCT |
| 76 | 79 |
| 77 } // namespace dart | 80 } // namespace dart |
| 78 | 81 |
| 79 #endif // defined TARGET_ARCH_IA32 | 82 #endif // defined TARGET_ARCH_DBC |
| OLD | NEW |