Flutter Engine
The Flutter Engine
debugger_ia32.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/globals.h"
6#if defined(TARGET_ARCH_IA32)
7
8#include "vm/debugger.h"
9
10#include "vm/code_patcher.h"
12#include "vm/cpu.h"
13#include "vm/object.h"
14#include "vm/os.h"
15#include "vm/stack_frame.h"
16#include "vm/stub_code.h"
17
18namespace dart {
19
20#ifndef PRODUCT
21
22CodePtr CodeBreakpoint::OrigStubAddress() const {
23 return saved_value_;
24}
25
26void CodeBreakpoint::PatchCode() {
27 ASSERT(!IsEnabled());
28 auto thread = Thread::Current();
29 auto zone = thread->zone();
30 const Code& code = Code::Handle(zone, code_);
31 const Instructions& instrs = Instructions::Handle(zone, code.instructions());
32 Code& stub_target = Code::Handle(zone);
33 thread->isolate_group()->RunWithStoppedMutators([&]() {
34 WritableInstructionsScope writable(instrs.PayloadStart(), instrs.Size());
35 switch (breakpoint_kind_) {
36 case UntaggedPcDescriptors::kIcCall: {
37 stub_target = StubCode::ICCallBreakpoint().ptr();
38 break;
39 }
40 case UntaggedPcDescriptors::kUnoptStaticCall: {
41 stub_target = StubCode::UnoptStaticCallBreakpoint().ptr();
42 break;
43 }
44 case UntaggedPcDescriptors::kRuntimeCall: {
45 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code);
46 stub_target = StubCode::RuntimeCallBreakpoint().ptr();
47 break;
48 }
49 default:
51 }
52 saved_value_ = CodePatcher::GetStaticCallTargetAt(pc_, code);
53 CodePatcher::PatchStaticCallAt(pc_, code, stub_target);
54 });
55}
56
57void CodeBreakpoint::RestoreCode() {
59 auto thread = Thread::Current();
60 auto zone = thread->zone();
61 const Code& code = Code::Handle(zone, code_);
62 const Instructions& instrs = Instructions::Handle(zone, code.instructions());
63 thread->isolate_group()->RunWithStoppedMutators([&]() {
64 WritableInstructionsScope writable(instrs.PayloadStart(), instrs.Size());
65 switch (breakpoint_kind_) {
66 case UntaggedPcDescriptors::kIcCall:
67 case UntaggedPcDescriptors::kUnoptStaticCall:
68 case UntaggedPcDescriptors::kRuntimeCall: {
70 break;
71 }
72 default:
74 }
75 });
76}
77
78#endif // !PRODUCT
79
80} // namespace dart
81
82#endif // defined TARGET_ARCH_IA32
#define UNREACHABLE()
Definition: assert.h:248
bool IsEnabled() const
Definition: debugger.h:235
CodePtr OrigStubAddress() const
static CodePtr GetStaticCallTargetAt(uword return_address, const Code &code)
static void PatchStaticCallAt(uword return_address, const Code &code, const Code &new_target)
static Object & Handle()
Definition: object.h:407
static Thread * Current()
Definition: thread.h:362
#define ASSERT(E)
Definition: dart_vm.cc:33