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); 32 void MethodExit(JSThread *thread, JSHandle<Method> method); 33 void DropLastFrame(JSThread *thread); 34 private: 35 bool IsNewlexenvOpcode(BytecodeInstruction::Opcode op); 36 bool IsStlexvarOpcode(BytecodeInstruction::Opcode op); 37 std::pair<uint16_t, uint16_t> ReadStlexvarParams(const uint8_t *pc, BytecodeInstruction::Opcode op); 38 39 void NewLexModifyRecordLevel(); 40 void EmplaceLexModifyRecord(JSThread *thread, JSTaggedValue env, uint16_t slot, JSTaggedValue value); 41 uint32_t GetLexModifyRecordLevel(); 42 std::vector<std::tuple<JSHandle<JSTaggedValue>, uint16_t, JSHandle<JSTaggedValue>>> GetLexModifyRecordOfTopFrame(); 43 void RemoveLexModifyRecordOfTopFrame(JSThread *thread); 44 void MergeLexModifyRecordOfTopFrame(JSThread *thread); 45 46 std::stack<std::vector<std::tuple<JSHandle<JSTaggedValue>, uint16_t, JSHandle<JSTaggedValue>>>> modifiedLexVar_; 47 }; 48 } 49 50 #endif // ECMASCRIPT_DEBUGGER_DROPFRAME_MANAGER_H