1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ecmascript/tooling/backend/js_pt_hooks.h"
17
18 #include "ecmascript/tooling/agent/debugger_impl.h"
19
20 namespace panda::ecmascript::tooling {
Breakpoint(const JSPtLocation & location)21 void JSPtHooks::Breakpoint(const JSPtLocation &location)
22 {
23 LOG(DEBUG, DEBUGGER) << "JSPtHooks: Breakpoint => " << location.GetMethodId() << ": "
24 << location.GetBytecodeOffset();
25
26 [[maybe_unused]] LocalScope scope(debugger_->vm_);
27 debugger_->NotifyPaused(location, INSTRUMENTATION);
28 }
29
Exception(const JSPtLocation & location)30 void JSPtHooks::Exception([[maybe_unused]] const JSPtLocation &location)
31 {
32 LOG(DEBUG, DEBUGGER) << "JSPtHooks: Exception";
33 [[maybe_unused]] LocalScope scope(debugger_->vm_);
34
35 debugger_->NotifyPaused({}, EXCEPTION);
36 }
37
SingleStep(const JSPtLocation & location)38 bool JSPtHooks::SingleStep(const JSPtLocation &location)
39 {
40 LOG(DEBUG, DEBUGGER) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset();
41
42 [[maybe_unused]] LocalScope scope(debugger_->vm_);
43 if (UNLIKELY(firstTime_)) {
44 firstTime_ = false;
45
46 debugger_->NotifyPaused({}, BREAK_ON_START);
47 return false;
48 }
49
50 // pause or step complete
51 if (debugger_->NotifySingleStep(location)) {
52 debugger_->NotifyPaused({}, OTHER);
53 return true;
54 }
55
56 // temporary "safepoint" to handle possible protocol command
57 debugger_->NotifyHandleProtocolCommand();
58
59 return false;
60 }
61
LoadModule(std::string_view pandaFileName)62 void JSPtHooks::LoadModule(std::string_view pandaFileName)
63 {
64 LOG(INFO, DEBUGGER) << "JSPtHooks: LoadModule: " << pandaFileName;
65
66 [[maybe_unused]] LocalScope scope(debugger_->vm_);
67
68 static uint32_t scriptId = 0;
69 if (debugger_->NotifyScriptParsed(scriptId++, pandaFileName.data())) {
70 firstTime_ = true;
71 }
72 }
73
PendingJobEntry()74 void JSPtHooks::PendingJobEntry()
75 {
76 LOG(DEBUG, DEBUGGER) << "JSPtHooks: PendingJobEntry";
77
78 [[maybe_unused]] LocalScope scope(debugger_->vm_);
79
80 debugger_->NotifyPendingJobEntry();
81 }
82 } // namespace panda::ecmascript::tooling
83