1 /* 2 * Copyright (c) 2021-2022 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 #ifndef ECMASCRIPT_TOOLING_INTERFACE_JS_DEBUG_INTERFACE_H 17 #define ECMASCRIPT_TOOLING_INTERFACE_JS_DEBUG_INTERFACE_H 18 19 #include <string_view> 20 21 #include "ecmascript/napi/include/jsnapi.h" 22 #include "ecmascript/debugger/js_pt_location.h" 23 #include "libpandafile/file.h" 24 #include "libpandabase/macros.h" 25 #include "libpandabase/utils/expected.h" 26 27 namespace panda::ecmascript::tooling { 28 struct JSPtStepRange { 29 uint32_t startBcOffset {0}; 30 uint32_t endBcOffset {0}; 31 }; 32 33 enum PauseReason { 34 AMBIGUOUS, 35 ASSERT, 36 DEBUGCOMMAND, 37 DOM, 38 EVENTLISTENER, 39 EXCEPTION, 40 INSTRUMENTATION, 41 OOM, 42 OTHER, 43 PROMISEREJECTION, 44 XHR, 45 BREAK_ON_START 46 }; 47 48 class PtHooks { 49 public: 50 PtHooks() = default; 51 52 /** 53 * \brief called by the ecmavm when breakpoint hits. Thread where breakpoint hits is stopped until 54 * continue or step event will be received 55 * @param thread Identifier of the thread where breakpoint hits. Now the callback is called in the same 56 * thread 57 * @param location Breakpoint location 58 */ 59 virtual void Breakpoint(const JSPtLocation &location) = 0; 60 61 /** 62 * \brief called by the ecmavm when panda file is loaded 63 * @param pandaFileName Path to panda file that is loaded 64 */ 65 virtual void LoadModule(std::string_view pandaFileName, std::string_view entryPoint) = 0; 66 67 /** 68 * \brief called before executing pending job 69 */ 70 virtual void PendingJobEntry() = 0; 71 72 /** 73 * \brief called by the ecmavm when virtual machine start initialization 74 */ 75 virtual void VmStart() = 0; 76 77 /** 78 * \brief called by the ecmavm when virtual machine death 79 */ 80 virtual void VmDeath() = 0; 81 82 virtual void Exception(const JSPtLocation &location) = 0; 83 84 virtual bool SingleStep(const JSPtLocation &location) = 0; 85 86 virtual void NativeCalling(const void *nativeAddress) = 0; 87 88 virtual ~PtHooks() = default; 89 90 NO_COPY_SEMANTIC(PtHooks); 91 NO_MOVE_SEMANTIC(PtHooks); 92 }; 93 94 class JSDebugInterface { 95 public: 96 JSDebugInterface() = default; 97 98 /** 99 * \brief Register debug hooks in the ecmavm 100 * @param hooks Pointer to object that implements PtHooks interface 101 */ 102 virtual void RegisterHooks(PtHooks *hooks) = 0; 103 104 /** 105 * \brief Unregister debug hooks in the ecmavm 106 */ 107 virtual void UnregisterHooks() = 0; 108 109 /** 110 * \brief Set breakpoint to \param location with an optional \param condition 111 * @param location Breakpoint location 112 * @param condition Optional condition 113 * @return Error if any errors occur 114 */ 115 virtual bool SetBreakpoint(const JSPtLocation &location, Local<FunctionRef> condFuncRef) = 0; 116 117 /** 118 * \brief Remove breakpoint from \param location 119 * @param location Breakpoint location 120 * @return Error if any errors occur 121 */ 122 virtual bool RemoveBreakpoint(const JSPtLocation &location) = 0; 123 124 /** 125 * \brief Remove all breakpoints from \param location 126 * @param location Breakpoint location 127 */ 128 virtual void RemoveAllBreakpoints() = 0; 129 130 virtual ~JSDebugInterface() = default; 131 132 NO_COPY_SEMANTIC(JSDebugInterface); 133 NO_MOVE_SEMANTIC(JSDebugInterface); 134 }; 135 } // namespace panda::ecmascript::tooling 136 137 #endif // ECMASCRIPT_TOOLING_INTERFACE_JS_DEBUG_INTERFACE_H 138