/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "tooling/client/manager/stack_manager.h" #include "common/log_wrapper.h" #include "tooling/client/session/session.h" namespace OHOS::ArkCompiler::Toolchain { void StackManager::SetCallFrames(std::map> callFrames) { for (auto &callFrame : callFrames) { callFrames_[callFrame.first] = std::move(callFrame.second); } } void StackManager::ShowCallFrames() { std::cout << std::endl; for (const auto &callFrame : callFrames_) { if (callFrame.second->GetFunctionName().empty()) { callFrame.second->SetFunctionName(""); } std::cout << callFrame.first << ". " << callFrame.second->GetFunctionName() << "(), " << callFrame.second->GetUrl() << ": " << callFrame.second->GetLocation()->GetLine() << std::endl; } } std::map> StackManager::GetScopeChainInfo() { std::map> scopeInfos; for (const auto &callFram : callFrames_) { int32_t callFramId = callFram.second->GetCallFrameId(); for (const auto &scope : *(callFram.second->GetScopeChain())) { scopeInfos[callFramId][scope->GetObject()->GetObjectId()] = scope->GetType(); } } return scopeInfos; } void StackManager::ClearCallFrame() { callFrames_.clear(); } void StackManager::PrintScopeChainInfo(const std::map>& scopeInfos) { for (const auto& [callFrameId, scopes] : scopeInfos) { std::cout << "CallFrame ID: " << callFrameId << std::endl; for (const auto& [objectId, type] : scopes) { std::cout << " Object ID: " << objectId << ", Type: " << type << std::endl; } std::cout << "-----------------------" << std::endl; } } }