Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: runtime/vm/debugger_x64.cc

Issue 131853006: Fix debugger stub patching on x64 architecture (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/debugger_mips.cc ('k') | runtime/vm/instructions_x64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "vm/code_patcher.h"
11 #include "vm/cpu.h" 12 #include "vm/cpu.h"
13 #include "vm/instructions.h"
12 #include "vm/stub_code.h" 14 #include "vm/stub_code.h"
13 15
14 namespace dart { 16 namespace dart {
15 17
16 RawInstance* ActivationFrame::GetInstanceCallReceiver( 18 RawInstance* ActivationFrame::GetInstanceCallReceiver(
17 intptr_t num_actual_args) { 19 intptr_t num_actual_args) {
18 ASSERT(num_actual_args > 0); // At minimum we have a receiver on the stack. 20 ASSERT(num_actual_args > 0); // At minimum we have a receiver on the stack.
19 // Stack pointer points to last argument that was pushed on the stack. 21 // Stack pointer points to last argument that was pushed on the stack.
20 uword receiver_addr = sp() + ((num_actual_args - 1) * kWordSize); 22 uword receiver_addr = sp() + ((num_actual_args - 1) * kWordSize);
21 return reinterpret_cast<RawInstance*>( 23 return reinterpret_cast<RawInstance*>(
22 *reinterpret_cast<uword*>(receiver_addr)); 24 *reinterpret_cast<uword*>(receiver_addr));
23 } 25 }
24 26
25 27
26 RawObject* ActivationFrame::GetClosureObject(intptr_t num_actual_args) { 28 RawObject* ActivationFrame::GetClosureObject(intptr_t num_actual_args) {
27 // At a minimum we have the closure object on the stack. 29 // At a minimum we have the closure object on the stack.
28 ASSERT(num_actual_args > 0); 30 ASSERT(num_actual_args > 0);
29 // Stack pointer points to last argument that was pushed on the stack. 31 // Stack pointer points to last argument that was pushed on the stack.
30 uword closure_addr = sp() + ((num_actual_args - 1) * kWordSize); 32 uword closure_addr = sp() + ((num_actual_args - 1) * kWordSize);
31 return reinterpret_cast<RawObject*>( 33 return reinterpret_cast<RawObject*>(
32 *reinterpret_cast<uword*>(closure_addr)); 34 *reinterpret_cast<uword*>(closure_addr));
33 } 35 }
34 36
37
38 uword CodeBreakpoint::OrigStubAddress() const {
39 const Code& code =
40 Code::Handle(Function::Handle(function_).unoptimized_code());
41 const Array& object_pool = Array::Handle(code.ObjectPool());
42 uword offset = saved_value_ + kHeapObjectTag;
43 ASSERT((offset % kWordSize) == 0);
44 const intptr_t index = (offset - Array::data_offset()) / kWordSize;
45 const uword stub_address = reinterpret_cast<uword>(object_pool.At(index));
46 ASSERT(stub_address % kWordSize == 0);
47 return stub_address;
48 }
49
50
51 void CodeBreakpoint::PatchCode() {
52 ASSERT(!is_enabled_);
53 switch (breakpoint_kind_) {
54 case PcDescriptors::kIcCall: {
55 int32_t offset = CodePatcher::GetPoolOffsetAt(pc_);
56 ASSERT((offset > 0) && ((offset % 8) == 7));
57 saved_value_ = static_cast<uword>(offset);
58 const int32_t stub_offset =
59 InstructionPattern::OffsetFromPPIndex(
60 Assembler::kBreakpointDynamicCPIndex);
61 CodePatcher::SetPoolOffsetAt(pc_, stub_offset);
62 break;
63 }
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 }
89 is_enabled_ = true;
90 }
91
92
93 void CodeBreakpoint::RestoreCode() {
94 ASSERT(is_enabled_);
95 switch (breakpoint_kind_) {
96 case PcDescriptors::kIcCall:
97 case PcDescriptors::kUnoptStaticCall:
98 case PcDescriptors::kClosureCall:
99 case PcDescriptors::kRuntimeCall:
100 case PcDescriptors::kReturn: {
101 CodePatcher::SetPoolOffsetAt(pc_, static_cast<int32_t>(saved_value_));
102 break;
103 }
104 default:
105 UNREACHABLE();
106 }
107 is_enabled_ = false;
108 }
109
110
35 } // namespace dart 111 } // namespace dart
36 112
37 #endif // defined TARGET_ARCH_X64 113 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/debugger_mips.cc ('k') | runtime/vm/instructions_x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698