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" |
17 | 13 |
18 namespace dart { | 14 namespace dart { |
19 | 15 |
20 #ifndef PRODUCT | 16 #ifndef PRODUCT |
21 | 17 |
22 RawCode* CodeBreakpoint::OrigStubAddress() const { | 18 RawCode* CodeBreakpoint::OrigStubAddress() const { |
23 return saved_value_; | 19 return reinterpret_cast<RawCode*>(static_cast<uintptr_t>(saved_value_)); |
24 } | 20 } |
25 | 21 |
26 | 22 |
| 23 static Instr* CallInstructionFromReturnAddress(uword pc) { |
| 24 return reinterpret_cast<Instr*>(pc) - 1; |
| 25 } |
| 26 |
| 27 |
27 void CodeBreakpoint::PatchCode() { | 28 void CodeBreakpoint::PatchCode() { |
28 ASSERT(!is_enabled_); | 29 ASSERT(!is_enabled_); |
29 const Code& code = Code::Handle(code_); | 30 const Code& code = Code::Handle(code_); |
30 const Instructions& instrs = Instructions::Handle(code.instructions()); | 31 const Instructions& instrs = Instructions::Handle(code.instructions()); |
31 Code& stub_target = Code::Handle(); | |
32 { | 32 { |
33 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 33 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 34 saved_value_ = *CallInstructionFromReturnAddress(pc_); |
34 switch (breakpoint_kind_) { | 35 switch (breakpoint_kind_) { |
35 case RawPcDescriptors::kIcCall: | 36 case RawPcDescriptors::kIcCall: |
36 case RawPcDescriptors::kUnoptStaticCall: { | 37 case RawPcDescriptors::kUnoptStaticCall: { |
37 stub_target = StubCode::ICCallBreakpoint_entry()->code(); | 38 // DebugBreak has an A operand matching the call it replaces. |
| 39 // This ensures that Return instructions continue to work - as they |
| 40 // look at calls to figure out how many arguments to drop. |
| 41 *CallInstructionFromReturnAddress(pc_) = |
| 42 Bytecode::Encode(Bytecode::kDebugBreak, |
| 43 Bytecode::DecodeArgc(saved_value_), |
| 44 0, |
| 45 0); |
38 break; | 46 break; |
39 } | 47 } |
| 48 |
40 case RawPcDescriptors::kRuntimeCall: { | 49 case RawPcDescriptors::kRuntimeCall: { |
41 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); | 50 *CallInstructionFromReturnAddress(pc_) = Bytecode::kDebugBreak; |
42 stub_target = StubCode::RuntimeCallBreakpoint_entry()->code(); | |
43 break; | 51 break; |
44 } | 52 } |
| 53 |
45 default: | 54 default: |
46 UNREACHABLE(); | 55 UNREACHABLE(); |
47 } | 56 } |
48 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code); | |
49 CodePatcher::PatchStaticCallAt(pc_, code, stub_target); | |
50 } | 57 } |
51 is_enabled_ = true; | 58 is_enabled_ = true; |
52 } | 59 } |
53 | 60 |
54 | 61 |
55 void CodeBreakpoint::RestoreCode() { | 62 void CodeBreakpoint::RestoreCode() { |
56 ASSERT(is_enabled_); | 63 ASSERT(is_enabled_); |
57 const Code& code = Code::Handle(code_); | 64 const Code& code = Code::Handle(code_); |
58 const Instructions& instrs = Instructions::Handle(code.instructions()); | 65 const Instructions& instrs = Instructions::Handle(code.instructions()); |
59 { | 66 { |
60 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 67 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
61 switch (breakpoint_kind_) { | 68 switch (breakpoint_kind_) { |
62 case RawPcDescriptors::kIcCall: | 69 case RawPcDescriptors::kIcCall: |
63 case RawPcDescriptors::kUnoptStaticCall: | 70 case RawPcDescriptors::kUnoptStaticCall: |
64 case RawPcDescriptors::kRuntimeCall: { | 71 case RawPcDescriptors::kRuntimeCall: { |
65 CodePatcher::PatchStaticCallAt(pc_, code, Code::Handle(saved_value_)); | 72 *CallInstructionFromReturnAddress(pc_) = saved_value_; |
66 break; | 73 break; |
67 } | 74 } |
68 default: | 75 default: |
69 UNREACHABLE(); | 76 UNREACHABLE(); |
70 } | 77 } |
71 } | 78 } |
72 is_enabled_ = false; | 79 is_enabled_ = false; |
73 } | 80 } |
74 | 81 |
75 #endif // !PRODUCT | 82 #endif // !PRODUCT |
76 | 83 |
77 } // namespace dart | 84 } // namespace dart |
78 | 85 |
79 #endif // defined TARGET_ARCH_IA32 | 86 #endif // defined TARGET_ARCH_DBC |
OLD | NEW |