| 1 | // Copyright (c) 2019, 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(DART_PRECOMPILED_RUNTIME) | 
| 7 | |
| 8 | #include "vm/debugger.h" | 
| 9 | #include "vm/instructions_kbc.h" | 
| 10 | #include "vm/interpreter.h" | 
| 11 | |
| 12 | namespace dart { | 
| 13 | |
| 14 | #ifndef PRODUCT | 
| 15 | void CodeBreakpoint::SetBytecodeBreakpoint() { | 
| 16 | ASSERT(!is_enabled_); | 
| 17 | is_enabled_ = true; | 
| 18 | Interpreter::Current()->set_is_debugging(true); | 
| 19 | } | 
| 20 | |
| 21 | void CodeBreakpoint::UnsetBytecodeBreakpoint() { | 
| 22 | ASSERT(is_enabled_); | 
| 23 | is_enabled_ = false; | 
| 24 | if (!Isolate::Current()->single_step() && | 
| 25 | !Isolate::Current()->debugger()->HasEnabledBytecodeBreakpoints()) { | 
| 26 | Interpreter::Current()->set_is_debugging(false); | 
| 27 | } | 
| 28 | } | 
| 29 | |
| 30 | bool Debugger::HasEnabledBytecodeBreakpoints() const { | 
| 31 | CodeBreakpoint* cbpt = code_breakpoints_; | 
| 32 | while (cbpt != nullptr) { | 
| 33 | if (cbpt->IsEnabled() && cbpt->IsInterpreted()) { | 
| 34 | return true; | 
| 35 | } | 
| 36 | cbpt = cbpt->next(); | 
| 37 | } | 
| 38 | return false; | 
| 39 | } | 
| 40 | |
| 41 | bool Debugger::HasBytecodeBreakpointAt(const KBCInstr* next_pc) const { | 
| 42 | CodeBreakpoint* cbpt = code_breakpoints_; | 
| 43 | while (cbpt != nullptr) { | 
| 44 | if ((reinterpret_cast<uword>(next_pc)) == cbpt->pc_ && cbpt->IsEnabled()) { | 
| 45 | ASSERT(cbpt->IsInterpreted()); | 
| 46 | return true; | 
| 47 | } | 
| 48 | cbpt = cbpt->next(); | 
| 49 | } | 
| 50 | return false; | 
| 51 | } | 
| 52 | #endif // !PRODUCT | 
| 53 | |
| 54 | } // namespace dart | 
| 55 | |
| 56 | #endif // !defined(DART_PRECOMPILED_RUNTIME) | 
| 57 | 
