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

Side by Side Diff: src/x64/debug-x64.cc

Issue 967323002: Refactor BreakLocationIterator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: static_cast instead Created 5 years, 9 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
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | src/x87/assembler-x87.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #if V8_TARGET_ARCH_X64 7 #if V8_TARGET_ARCH_X64
8 8
9 #include "src/assembler.h" 9 #include "src/assembler.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
11 #include "src/debug.h" 11 #include "src/debug.h"
12 12
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 bool BreakLocationIterator::IsDebugBreakAtReturn() { 17 // Patch the code at the current PC with a call to the target address.
18 return Debug::IsDebugBreakAtReturn(rinfo()); 18 // Additional guard int3 instructions can be added if required.
19 void PatchCodeWithCall(Address pc, Address target, int guard_bytes) {
20 int code_size = Assembler::kCallSequenceLength + guard_bytes;
21
22 // Create a code patcher.
23 CodePatcher patcher(pc, code_size);
24
25 // Add a label for checking the size of the code used for returning.
26 #ifdef DEBUG
27 Label check_codesize;
28 patcher.masm()->bind(&check_codesize);
29 #endif
30
31 // Patch the code.
32 patcher.masm()->movp(kScratchRegister, reinterpret_cast<void*>(target),
33 Assembler::RelocInfoNone());
34 patcher.masm()->call(kScratchRegister);
35
36 // Check that the size of the code generated is as expected.
37 DCHECK_EQ(Assembler::kCallSequenceLength,
38 patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize));
39
40 // Add the requested number of int3 instructions after the call.
41 for (int i = 0; i < guard_bytes; i++) {
42 patcher.masm()->int3();
43 }
44
45 CpuFeatures::FlushICache(pc, code_size);
19 } 46 }
20 47
21 48
22 // Patch the JS frame exit code with a debug break call. See 49 // Patch the JS frame exit code with a debug break call. See
23 // CodeGenerator::VisitReturnStatement and VirtualFrame::Exit in codegen-x64.cc 50 // CodeGenerator::VisitReturnStatement and VirtualFrame::Exit in codegen-x64.cc
24 // for the precise return instructions sequence. 51 // for the precise return instructions sequence.
25 void BreakLocationIterator::SetDebugBreakAtReturn() { 52 void BreakLocation::SetDebugBreakAtReturn() {
26 DCHECK(Assembler::kJSReturnSequenceLength >= Assembler::kCallSequenceLength); 53 DCHECK(Assembler::kJSReturnSequenceLength >= Assembler::kCallSequenceLength);
27 rinfo()->PatchCodeWithCall( 54 PatchCodeWithCall(
28 debug_info_->GetIsolate()->builtins()->Return_DebugBreak()->entry(), 55 pc(), debug_info_->GetIsolate()->builtins()->Return_DebugBreak()->entry(),
29 Assembler::kJSReturnSequenceLength - Assembler::kCallSequenceLength); 56 Assembler::kJSReturnSequenceLength - Assembler::kCallSequenceLength);
30 } 57 }
31 58
32 59
33 // Restore the JS frame exit code. 60 void BreakLocation::SetDebugBreakAtSlot() {
34 void BreakLocationIterator::ClearDebugBreakAtReturn() {
35 rinfo()->PatchCode(original_rinfo()->pc(),
36 Assembler::kJSReturnSequenceLength);
37 }
38
39
40 // A debug break in the frame exit code is identified by the JS frame exit code
41 // having been patched with a call instruction.
42 bool Debug::IsDebugBreakAtReturn(v8::internal::RelocInfo* rinfo) {
43 DCHECK(RelocInfo::IsJSReturn(rinfo->rmode()));
44 return rinfo->IsPatchedReturnSequence();
45 }
46
47
48 bool BreakLocationIterator::IsDebugBreakAtSlot() {
49 DCHECK(IsDebugBreakSlot()); 61 DCHECK(IsDebugBreakSlot());
50 // Check whether the debug break slot instructions have been patched. 62 PatchCodeWithCall(
51 return rinfo()->IsPatchedDebugBreakSlotSequence(); 63 pc(), debug_info_->GetIsolate()->builtins()->Slot_DebugBreak()->entry(),
52 }
53
54
55 void BreakLocationIterator::SetDebugBreakAtSlot() {
56 DCHECK(IsDebugBreakSlot());
57 rinfo()->PatchCodeWithCall(
58 debug_info_->GetIsolate()->builtins()->Slot_DebugBreak()->entry(),
59 Assembler::kDebugBreakSlotLength - Assembler::kCallSequenceLength); 64 Assembler::kDebugBreakSlotLength - Assembler::kCallSequenceLength);
60 } 65 }
61 66
62 67
63 void BreakLocationIterator::ClearDebugBreakAtSlot() {
64 DCHECK(IsDebugBreakSlot());
65 rinfo()->PatchCode(original_rinfo()->pc(), Assembler::kDebugBreakSlotLength);
66 }
67
68
69 #define __ ACCESS_MASM(masm) 68 #define __ ACCESS_MASM(masm)
70 69
71 70
72 static void Generate_DebugBreakCallHelper(MacroAssembler* masm, 71 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
73 RegList object_regs, 72 RegList object_regs,
74 RegList non_object_regs, 73 RegList non_object_regs,
75 bool convert_call_to_jmp) { 74 bool convert_call_to_jmp) {
76 // Enter an internal frame. 75 // Enter an internal frame.
77 { 76 {
78 FrameScope scope(masm, StackFrame::INTERNAL); 77 FrameScope scope(masm, StackFrame::INTERNAL);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 __ jmp(rdx); 300 __ jmp(rdx);
302 } 301 }
303 302
304 const bool LiveEdit::kFrameDropperSupported = true; 303 const bool LiveEdit::kFrameDropperSupported = true;
305 304
306 #undef __ 305 #undef __
307 306
308 } } // namespace v8::internal 307 } } // namespace v8::internal
309 308
310 #endif // V8_TARGET_ARCH_X64 309 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/assembler-x64.cc ('k') | src/x87/assembler-x87.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698