• 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/dynamic/client/manager/breakpoint_manager.h"
17 
18 #include "tooling/dynamic/client/session/session.h"
19 
20 using PtJson = panda::ecmascript::tooling::PtJson;
21 using Result = panda::ecmascript::tooling::Result;
22 namespace OHOS::ArkCompiler::Toolchain {
Createbreaklocation(const std::unique_ptr<PtJson> json)23 void BreakPointManager::Createbreaklocation(const std::unique_ptr<PtJson> json)
24 {
25     if (json == nullptr) {
26         LOGE("arkdb: json parse error");
27         return;
28     }
29 
30     if (!json->IsObject()) {
31         LOGE("arkdb: json parse format error");
32         json->ReleaseRoot();
33         return;
34     }
35     Result ret;
36     std::unique_ptr<PtJson> result;
37     ret = json->GetObject("result", &result);
38     if (ret != Result::SUCCESS) {
39         LOGE("arkdb: find result error");
40         return;
41     }
42     std::string breakpointId;
43     ret = result->GetString("breakpointId", &breakpointId);
44     if (ret == Result::SUCCESS) {
45         Breaklocation breaklocation;
46         breaklocation.breakpointId = breakpointId;
47         std::vector<std::string> breaksplitstring;
48         breaksplitstring = Utils::SplitString(breakpointId, ":");
49         breaklocation.lineNumber = breaksplitstring[1]; // 1: linenumber
50         breaklocation.columnNumber = breaksplitstring[2]; // 2: columnnumber
51         breaklocation.url = breaksplitstring[3]; // 3: url
52         breaklist_.push_back(breaklocation);
53     } else {
54         LOGE("arkdb: find breakpointId error");
55         return;
56     }
57 }
58 
Show()59 void BreakPointManager::Show()
60 {
61     size_t size = breaklist_.size();
62     for (size_t i = 0; i < size; i++) {
63         std::cout << (i + 1) << ':' << " url:" << breaklist_[i].url;
64         std::cout << " lineNumber:" << (std::atoi(breaklist_[i].lineNumber.c_str()) + 1)
65             << " columnNumber:" << breaklist_[i].columnNumber << std::endl;
66     }
67 }
68 
Deletebreaklist(unsigned int num)69 void BreakPointManager::Deletebreaklist(unsigned int num)
70 {
71     std::vector<Breaklocation>::iterator it = breaklist_.begin() + num - 1;
72     breaklist_.erase(it);
73 }
74 
Getbreaklist() const75 std::vector<Breaklocation> BreakPointManager::Getbreaklist() const
76 {
77     return breaklist_;
78 }
79 }