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/x87/debug-x87.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/x87/assembler-x87.cc ('k') | test/cctest/test-debug.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_X87 7 #if V8_TARGET_ARCH_X87
8 8
9 #include "src/codegen.h" 9 #include "src/codegen.h"
10 #include "src/debug.h" 10 #include "src/debug.h"
11 11
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 bool BreakLocationIterator::IsDebugBreakAtReturn() { 16 // Patch the code at the current PC with a call to the target address.
17 return Debug::IsDebugBreakAtReturn(rinfo()); 17 // Additional guard int3 instructions can be added if required.
18 void RelocInfo::PatchCodeWithCall(Address pc, Address target, int guard_bytes) {
19 // Call instruction takes up 5 bytes and int3 takes up one byte.
20 static const int kCallCodeSize = 5;
21 int code_size = kCallCodeSize + guard_bytes;
22
23 // Create a code patcher.
24 CodePatcher patcher(pc, code_size);
25
26 // Add a label for checking the size of the code used for returning.
27 #ifdef DEBUG
28 Label check_codesize;
29 patcher.masm()->bind(&check_codesize);
30 #endif
31
32 // Patch the code.
33 patcher.masm()->call(target, RelocInfo::NONE32);
34
35 // Check that the size of the code generated is as expected.
36 DCHECK_EQ(kCallCodeSize,
37 patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize));
38
39 // Add the requested number of int3 instructions after the call.
40 DCHECK_GE(guard_bytes, 0);
41 for (int i = 0; i < guard_bytes; i++) {
42 patcher.masm()->int3();
43 }
44
45 CpuFeatures::FlushICache(pc, code_size);
18 } 46 }
19 47
20 48
21 // 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
22 // CodeGenerator::VisitReturnStatement and VirtualFrame::Exit in codegen-x87.cc 50 // CodeGenerator::VisitReturnStatement and VirtualFrame::Exit in codegen-x87.cc
23 // for the precise return instructions sequence. 51 // for the precise return instructions sequence.
24 void BreakLocationIterator::SetDebugBreakAtReturn() { 52 void BreakLocation::SetDebugBreakAtReturn() {
25 DCHECK(Assembler::kJSReturnSequenceLength >= 53 DCHECK(Assembler::kJSReturnSequenceLength >=
26 Assembler::kCallInstructionLength); 54 Assembler::kCallInstructionLength);
27 rinfo()->PatchCodeWithCall( 55 PatchCodeWithCall(
28 debug_info_->GetIsolate()->builtins()->Return_DebugBreak()->entry(), 56 pc(), debug_info_->GetIsolate()->builtins()->Return_DebugBreak()->entry(),
29 Assembler::kJSReturnSequenceLength - Assembler::kCallInstructionLength); 57 Assembler::kJSReturnSequenceLength - Assembler::kCallInstructionLength);
30 } 58 }
31 59
32 60
33 // Restore the JS frame exit code.
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(RelocInfo* rinfo) {
43 DCHECK(RelocInfo::IsJSReturn(rinfo->rmode()));
44 return rinfo->IsPatchedReturnSequence();
45 }
46
47
48 bool BreakLocationIterator::IsDebugBreakAtSlot() {
49 DCHECK(IsDebugBreakSlot());
50 // Check whether the debug break slot instructions have been patched.
51 return rinfo()->IsPatchedDebugBreakSlotSequence();
52 }
53
54
55 void BreakLocationIterator::SetDebugBreakAtSlot() { 61 void BreakLocationIterator::SetDebugBreakAtSlot() {
56 DCHECK(IsDebugBreakSlot()); 62 DCHECK(IsDebugBreakSlot());
57 Isolate* isolate = debug_info_->GetIsolate(); 63 Isolate* isolate = debug_info_->GetIsolate();
58 rinfo()->PatchCodeWithCall( 64 rinfo().PatchCodeWithCall(
59 isolate->builtins()->Slot_DebugBreak()->entry(), 65 pc(), isolate->builtins()->Slot_DebugBreak()->entry(),
60 Assembler::kDebugBreakSlotLength - Assembler::kCallInstructionLength); 66 Assembler::kDebugBreakSlotLength - Assembler::kCallInstructionLength);
61 } 67 }
62 68
63 69
64 void BreakLocationIterator::ClearDebugBreakAtSlot() {
65 DCHECK(IsDebugBreakSlot());
66 rinfo()->PatchCode(original_rinfo()->pc(), Assembler::kDebugBreakSlotLength);
67 }
68
69
70 #define __ ACCESS_MASM(masm) 70 #define __ ACCESS_MASM(masm)
71 71
72 static void Generate_DebugBreakCallHelper(MacroAssembler* masm, 72 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
73 RegList object_regs, 73 RegList object_regs,
74 RegList non_object_regs, 74 RegList non_object_regs,
75 bool convert_call_to_jmp) { 75 bool convert_call_to_jmp) {
76 // Enter an internal frame. 76 // Enter an internal frame.
77 { 77 {
78 FrameScope scope(masm, StackFrame::INTERNAL); 78 FrameScope scope(masm, StackFrame::INTERNAL);
79 79
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 322
323 323
324 const bool LiveEdit::kFrameDropperSupported = true; 324 const bool LiveEdit::kFrameDropperSupported = true;
325 325
326 #undef __ 326 #undef __
327 327
328 } } // namespace v8::internal 328 } } // namespace v8::internal
329 329
330 #endif // V8_TARGET_ARCH_X87 330 #endif // V8_TARGET_ARCH_X87
OLDNEW
« no previous file with comments | « src/x87/assembler-x87.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698