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 "backend/js_pt_hooks.h"
17
18 #include "agent/debugger_impl.h"
19
20 namespace panda::ecmascript::tooling {
DebuggerStmt(const JSPtLocation & location)21 void JSPtHooks::DebuggerStmt(const JSPtLocation &location)
22 {
23 LOG_DEBUGGER(INFO) << "JSPHooks: Debugger => " << location.GetMethodId() << ": "
24 << location.GetBytecodeOffset();
25 [[maybe_unused]] LocalScope scope(debugger_->vm_);
26 debugger_->NotifyPaused(location, OTHER);
27 }
28
Breakpoint(const JSPtLocation & location)29 void JSPtHooks::Breakpoint(const JSPtLocation &location)
30 {
31 LOG_DEBUGGER(VERBOSE) << "JSPtHooks: Breakpoint => " << location.GetMethodId() << ": "
32 << location.GetBytecodeOffset();
33
34 [[maybe_unused]] LocalScope scope(debugger_->vm_);
35 debugger_->NotifyPaused(location, OTHER);
36 }
37
Exception(const JSPtLocation & location)38 void JSPtHooks::Exception([[maybe_unused]] const JSPtLocation &location)
39 {
40 LOG_DEBUGGER(VERBOSE) << "JSPtHooks: Exception";
41 [[maybe_unused]] LocalScope scope(debugger_->vm_);
42
43 debugger_->NotifyPaused({}, EXCEPTION);
44 }
45
SingleStep(const JSPtLocation & location)46 bool JSPtHooks::SingleStep(const JSPtLocation &location)
47 {
48 LOG_DEBUGGER(VERBOSE) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset();
49
50 [[maybe_unused]] LocalScope scope(debugger_->vm_);
51 if (UNLIKELY(firstTime_)) {
52 firstTime_ = false;
53
54 debugger_->NotifyPaused({}, BREAK_ON_START);
55 return false;
56 }
57
58 // pause or step complete
59 if (debugger_->NotifySingleStep(location)) {
60 debugger_->NotifyPaused({}, OTHER);
61 return true;
62 }
63
64 // temporary "safepoint" to handle possible protocol command
65 debugger_->NotifyHandleProtocolCommand();
66
67 return false;
68 }
69
LoadModule(std::string_view pandaFileName,std::string_view entryPoint)70 void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entryPoint)
71 {
72 LOG_DEBUGGER(VERBOSE) << "JSPtHooks: LoadModule: " << pandaFileName;
73
74 [[maybe_unused]] LocalScope scope(debugger_->vm_);
75
76 static uint32_t scriptId = 0;
77 if (debugger_->NotifyScriptParsed(scriptId++, pandaFileName.data(), entryPoint)) {
78 firstTime_ = true;
79 }
80 }
81
NativeCalling(const void * nativeAddress)82 void JSPtHooks::NativeCalling(const void *nativeAddress)
83 {
84 LOG_DEBUGGER(INFO) << "JSPtHooks: NativeCalling, addr = " << nativeAddress;
85
86 [[maybe_unused]] LocalScope scope(debugger_->vm_);
87
88 debugger_->NotifyNativeCalling(nativeAddress);
89 }
90 } // namespace panda::ecmascript::tooling
91