• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "tooling/client/manager/stack_manager.h"
17 
18 namespace OHOS::ArkCompiler::Toolchain {
SetCallFrames(std::map<int32_t,std::unique_ptr<CallFrame>> callFrames)19 void StackManager::SetCallFrames(std::map<int32_t, std::unique_ptr<CallFrame>> callFrames)
20 {
21     for (auto &callFrame : callFrames) {
22         callFrames_[callFrame.first] = std::move(callFrame.second);
23     }
24 }
25 
ShowCallFrames()26 void StackManager::ShowCallFrames()
27 {
28     std::cout << std::endl;
29     for (const auto &callFrame : callFrames_) {
30         if (callFrame.second->GetFunctionName().empty()) {
31             callFrame.second->SetFunctionName("<anonymous function>");
32         }
33         std::cout << callFrame.first << ". " << callFrame.second->GetFunctionName() << "(), "
34                   << callFrame.second->GetUrl() << ": " << callFrame.second->GetLocation()->GetLine() << std::endl;
35     }
36 }
37 
GetScopeChainInfo()38 std::map<int32_t, std::map<int32_t, std::string>> StackManager::GetScopeChainInfo()
39 {
40     std::map<int32_t, std::map<int32_t, std::string>> scopeInfos;
41     for (const auto &callFram : callFrames_) {
42         int32_t callFramId = callFram.second->GetCallFrameId();
43         for (const auto &scope : *(callFram.second->GetScopeChain())) {
44             scopeInfos[callFramId][scope->GetObject()->GetObjectId()] = scope->GetType();
45         }
46     }
47     return scopeInfos;
48 }
49 
ClearCallFrame()50 void StackManager::ClearCallFrame()
51 {
52     callFrames_.clear();
53 }
54 
PrintScopeChainInfo(const std::map<int32_t,std::map<int32_t,std::string>> & scopeInfos)55 void StackManager::PrintScopeChainInfo(const std::map<int32_t, std::map<int32_t, std::string>>& scopeInfos)
56 {
57     for (const auto& [callFrameId, scopes] : scopeInfos) {
58         std::cout << "CallFrame ID: " << callFrameId << std::endl;
59         for (const auto& [objectId, type] : scopes) {
60             std::cout << "  Object ID: " << objectId << ", Type: " << type << std::endl;
61         }
62         std::cout << "-----------------------" << std::endl;
63     }
64 }
65 }