1 /* 2 * Copyright (c) 2023 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_DEBUGGER_DROPFRAME_MANAGER_H 17 #define ECMASCRIPT_DEBUGGER_DROPFRAME_MANAGER_H 18 19 #include "ecmascript/js_handle.h" 20 #include "ecmascript/js_thread.h" 21 #include "ecmascript/method.h" 22 23 namespace panda::ecmascript::tooling { 24 class DropframeManager { 25 public: 26 DropframeManager() = default; 27 ~DropframeManager() = default; 28 NO_COPY_SEMANTIC(DropframeManager); 29 NO_MOVE_SEMANTIC(DropframeManager); 30 31 void MethodEntry(JSThread *thread, JSHandle<Method> method, JSHandle<JSTaggedValue> env); 32 void MethodExit(JSThread *thread, JSHandle<Method> method); 33 void DropLastFrame(JSThread *thread); 34 uint32_t GetPromiseQueueSizeRecordOfTopFrame(); 35 private: 36 bool IsNewlexenvOpcode(BytecodeInstruction::Opcode op); 37 bool IsStlexvarOpcode(BytecodeInstruction::Opcode op); 38 std::pair<uint16_t, uint16_t> ReadStlexvarParams(const uint8_t *pc, BytecodeInstruction::Opcode op); 39 40 void NewLexModifyRecordLevel(); 41 void EmplaceLexModifyRecord(JSThread *thread, JSTaggedValue env, uint16_t slot, JSTaggedValue value); 42 uint32_t GetLexModifyRecordLevel(); 43 std::vector<std::tuple<JSHandle<JSTaggedValue>, uint16_t, JSHandle<JSTaggedValue>>> GetLexModifyRecordOfTopFrame(); 44 void RemoveLexModifyRecordOfTopFrame(JSThread *thread); 45 void MergeLexModifyRecordOfTopFrame(JSThread *thread); 46 47 void PushPromiseQueueSizeRecord(JSThread *thread); 48 void PopPromiseQueueSizeRecord(); 49 50 std::stack<std::vector<std::tuple<JSHandle<JSTaggedValue>, uint16_t, JSHandle<JSTaggedValue>>>> modifiedLexVar_; 51 std::stack<uint32_t> promiseQueueSizeRecord_; 52 }; 53 } 54 55 #endif // ECMASCRIPT_DEBUGGER_DROPFRAME_MANAGER_H