diff --git a/tooling/client/domain/debugger_client.cpp b/tooling/client/domain/debugger_client.cpp index 642109d1514318e2457feadd8cb76655d39b05b7..18b91f795603b2fc0fe7c4a4704f308fb41bcf2d 100644 --- a/tooling/client/domain/debugger_client.cpp +++ b/tooling/client/domain/debugger_client.cpp @@ -23,47 +23,48 @@ using PtJson = panda::ecmascript::tooling::PtJson; namespace OHOS::ArkCompiler::Toolchain { -bool DebuggerClient::DispatcherCmd(int id, const std::string &cmd, std::string* reqStr) +bool DebugerClient::DispatcherCmd(int id, const std::string &cmd, std::string* reqStr) { std::map> dispatcherTable { - { "break", std::bind(&DebuggerClient::BreakCommand, this, id)}, - { "backtrack", std::bind(&DebuggerClient::BacktrackCommand, this, id)}, - { "continue", std::bind(&DebuggerClient::ContinueCommand, this, id)}, - { "delete", std::bind(&DebuggerClient::DeleteCommand, this, id)}, - { "jump", std::bind(&DebuggerClient::JumpCommand, this, id)}, - { "disable", std::bind(&DebuggerClient::DisableCommand, this, id)}, - { "display", std::bind(&DebuggerClient::DisplayCommand, this, id)}, - { "enable", std::bind(&DebuggerClient::EnableCommand, this, id)}, - { "finish", std::bind(&DebuggerClient::FinishCommand, this, id)}, - { "frame", std::bind(&DebuggerClient::FrameCommand, this, id)}, - { "ignore", std::bind(&DebuggerClient::IgnoreCommand, this, id)}, - { "infobreakpoints", std::bind(&DebuggerClient::InfobreakpointsCommand, this, id)}, - { "infosource", std::bind(&DebuggerClient::InfosourceCommand, this, id)}, - { "list", std::bind(&DebuggerClient::NextCommand, this, id)}, - { "next", std::bind(&DebuggerClient::ListCommand, this, id)}, - { "print", std::bind(&DebuggerClient::PrintCommand, this, id)}, - { "ptype", std::bind(&DebuggerClient::PtypeCommand, this, id)}, - { "run", std::bind(&DebuggerClient::RunCommand, this, id)}, - { "setvar", std::bind(&DebuggerClient::SetvarCommand, this, id)}, - { "step", std::bind(&DebuggerClient::StepCommand, this, id)}, - { "undisplay", std::bind(&DebuggerClient::UndisplayCommand, this, id)}, - { "watch", std::bind(&DebuggerClient::WatchCommand, this, id)}, - { "resume", std::bind(&DebuggerClient::ResumeCommand, this, id)} + { "break", std::bind(&DebugerClient::BreakCommand, this, id)}, + { "backtrack", std::bind(&DebugerClient::BacktrackCommand, this, id)}, + { "continue", std::bind(&DebugerClient::ContinueCommand, this, id)}, + { "delete", std::bind(&DebugerClient::DeleteCommand, this, id)}, + { "jump", std::bind(&DebugerClient::JumpCommand, this, id)}, + { "disable", std::bind(&DebugerClient::DisableCommand, this, id)}, + { "display", std::bind(&DebugerClient::DisplayCommand, this, id)}, + { "enable", std::bind(&DebugerClient::EnableCommand, this, id)}, + { "finish", std::bind(&DebugerClient::FinishCommand, this, id)}, + { "frame", std::bind(&DebugerClient::FrameCommand, this, id)}, + { "ignore", std::bind(&DebugerClient::IgnoreCommand, this, id)}, + { "infobreakpoints", std::bind(&DebugerClient::InfobreakpointsCommand, this, id)}, + { "infosource", std::bind(&DebugerClient::InfosourceCommand, this, id)}, + { "list", std::bind(&DebugerClient::NextCommand, this, id)}, + { "next", std::bind(&DebugerClient::ListCommand, this, id)}, + { "print", std::bind(&DebugerClient::PrintCommand, this, id)}, + { "ptype", std::bind(&DebugerClient::PtypeCommand, this, id)}, + { "run", std::bind(&DebugerClient::RunCommand, this, id)}, + { "setvar", std::bind(&DebugerClient::SetvarCommand, this, id)}, + { "step", std::bind(&DebugerClient::StepCommand, this, id)}, + { "undisplay", std::bind(&DebugerClient::UndisplayCommand, this, id)}, + { "watch", std::bind(&DebugerClient::WatchCommand, this, id)}, + { "resume", std::bind(&DebugerClient::ResumeCommand, this, id)} }; auto entry = dispatcherTable.find(cmd); + if (entry != dispatcherTable.end()) { *reqStr = entry->second(); - LOGE("DebuggerClient DispatcherCmd reqStr1: %{public}s", reqStr->c_str()); + LOGE("DebugerClient DispatcherCmd reqStr1: %{public}s", reqStr->c_str()); return true; } else { *reqStr = "Unknown commond: " + cmd; - LOGE("DebuggerClient DispatcherCmd reqStr2: %{public}s", reqStr->c_str()); + LOGE("DebugerClient DispatcherCmd reqStr2: %{public}s", reqStr->c_str()); return false; } } -std::string DebuggerClient::BreakCommand(int id) +std::string DebugerClient::BreakCommand(int id) { std::unique_ptr request = PtJson::CreateObject(); request->Add("id", id); @@ -77,28 +78,30 @@ std::string DebuggerClient::BreakCommand(int id) return request->Stringify(); } -std::string DebuggerClient::BacktrackCommand([[maybe_unused]] int id) +std::string DebugerClient::BacktrackCommand([[maybe_unused]] int id) { return "backtrack"; } -std::string DebuggerClient::ContinueCommand([[maybe_unused]] int id) +std::string DebugerClient::ContinueCommand([[maybe_unused]] int id) { return "continue"; } -std::string DebuggerClient::DeleteCommand(int id) +std::string DebugerClient::DeleteCommand(int id) { std::unique_ptr request = PtJson::CreateObject(); request->Add("id", id); request->Add("method", "Debugger.removeBreakpoint"); - std::unique_ptr params = PtJson::CreateObject(); + std::string breakpointId; + breakpointId=breakPointInfoList_.back().url; + params->Add("breakpointId",breakpointId.c_str()); request->Add("params", params); return request->Stringify(); } -std::string DebuggerClient::DisableCommand(int id) +std::string DebugerClient::DisableCommand(int id) { std::unique_ptr request = PtJson::CreateObject(); request->Add("id", id); @@ -109,98 +112,105 @@ std::string DebuggerClient::DisableCommand(int id) return request->Stringify(); } -std::string DebuggerClient::DisplayCommand([[maybe_unused]] int id) +std::string DebugerClient::DisplayCommand(int id) { - return "display"; + std::unique_ptr request = PtJson::CreateObject(); + request->Add("id", id); + request->Add("method", "Debugger.displayBreakpoint"); + + std::unique_ptr params = PtJson::CreateObject(); + request->Add("params", params); + return request->Stringify(); } -std::string DebuggerClient::EnableCommand(int id) +std::string DebugerClient::EnableCommand(int id) { std::unique_ptr request = PtJson::CreateObject(); request->Add("id", id); request->Add("method", "Debugger.enable"); std::unique_ptr params = PtJson::CreateObject(); + // params->Add("maxScriptsCacheSize", 1.0E7); request->Add("params", params); return request->Stringify(); } -std::string DebuggerClient::FinishCommand([[maybe_unused]] int id) +std::string DebugerClient::FinishCommand([[maybe_unused]] int id) { return "finish"; } -std::string DebuggerClient::FrameCommand([[maybe_unused]] int id) +std::string DebugerClient::FrameCommand([[maybe_unused]] int id) { return "frame"; } -std::string DebuggerClient::IgnoreCommand([[maybe_unused]] int id) +std::string DebugerClient::IgnoreCommand([[maybe_unused]] int id) { return "ignore"; } -std::string DebuggerClient::InfobreakpointsCommand([[maybe_unused]] int id) +std::string DebugerClient::InfobreakpointsCommand([[maybe_unused]] int id) { return "infobreakpoint"; } -std::string DebuggerClient::InfosourceCommand([[maybe_unused]] int id) +std::string DebugerClient::InfosourceCommand([[maybe_unused]] int id) { return "infosource"; } -std::string DebuggerClient::JumpCommand([[maybe_unused]] int id) +std::string DebugerClient::JumpCommand([[maybe_unused]] int id) { return "jump"; } -std::string DebuggerClient::NextCommand([[maybe_unused]] int id) +std::string DebugerClient::NextCommand([[maybe_unused]] int id) { return "next"; } -std::string DebuggerClient::ListCommand([[maybe_unused]] int id) +std::string DebugerClient::ListCommand([[maybe_unused]] int id) { return "list"; } -std::string DebuggerClient::PrintCommand([[maybe_unused]] int id) +std::string DebugerClient::PrintCommand([[maybe_unused]] int id) { return "print"; } -std::string DebuggerClient::PtypeCommand([[maybe_unused]] int id) +std::string DebugerClient::PtypeCommand([[maybe_unused]] int id) { return "ptype"; } -std::string DebuggerClient::RunCommand([[maybe_unused]] int id) +std::string DebugerClient::RunCommand([[maybe_unused]] int id) { return "run"; } -std::string DebuggerClient::SetvarCommand([[maybe_unused]] int id) +std::string DebugerClient::SetvarCommand([[maybe_unused]] int id) { return "Debugger.setVariableValue"; } -std::string DebuggerClient::StepCommand([[maybe_unused]] int id) +std::string DebugerClient::StepCommand([[maybe_unused]] int id) { return "step"; } -std::string DebuggerClient::UndisplayCommand([[maybe_unused]] int id) +std::string DebugerClient::UndisplayCommand([[maybe_unused]] int id) { return "undisplay"; } -std::string DebuggerClient::WatchCommand([[maybe_unused]] int id) +std::string DebugerClient::WatchCommand([[maybe_unused]] int id) { return "Debugger.evaluateOnCallFrame"; } -std::string DebuggerClient::ResumeCommand(int id) +std::string DebugerClient::ResumeCommand(int id) { std::unique_ptr request = PtJson::CreateObject(); request->Add("id", id); @@ -211,11 +221,11 @@ std::string DebuggerClient::ResumeCommand(int id) return request->Stringify(); } -void DebuggerClient::AddBreakPointInfo(std::string url, std::string lineNumber) +void DebugerClient::AddBreakPointInfo(std::string url, std::string lineNumber) { BreakPointInfo breakPointInfo; breakPointInfo.url = url; breakPointInfo.lineNumber = lineNumber; breakPointInfoList_.emplace_back(breakPointInfo); } -} // OHOS::ArkCompiler::Toolchain \ No newline at end of file +} //OHOS::ArkCompiler::Toolchain \ No newline at end of file diff --git a/tooling/client/manager/breakpoint_manager.cpp b/tooling/client/manager/breakpoint_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93e641652abc48aa70f2c1b2d15a6d2f4d67aed5 --- /dev/null +++ b/tooling/client/manager/breakpoint_manager.cpp @@ -0,0 +1,79 @@ +/* + * 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 + +#include "log_wrapper.h" +#include "manager/breakpoint_manager.h" +#include "toolchain_cli/cli_command.h" +using PtJson = panda::ecmascript::tooling::PtJson; +using Result = panda::ecmascript::tooling::Result; +namespace OHOS::ArkCompiler::Toolchain { + void Breakpoint::HandleMessage(const std::unique_ptr json){ + if (json == nullptr) { + LOGE("toolchain_client: json parse error"); + return; + } + + if (!json->IsObject()) { + LOGE("toolchain_client: json parse format error"); + json->ReleaseRoot(); + return; + } + Result ret; + std::unique_ptr result; + ret = json->GetObject("result", &result); + if (ret != Result::SUCCESS) { + LOGE("toolchain_client: find result error"); + return; + } + std::string breakpointId; + Breaklocation breaklocation; + ret = result->GetString("breakpointId", &breakpointId); + int flag=0; + if(ret == Result::SUCCESS) { + breaklocation.breakpointId=breakpointId; + int length=breakpointId.size(); + for(int i=0;i::iterator it=breaklist.begin()+num-1; + breaklist.erase(it); + } +} \ No newline at end of file diff --git a/tooling/client/manager/breakpoint_manager.h b/tooling/client/manager/breakpoint_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..2568cbf8fed8d6d8a95a974c41e8c92a5e385bd5 --- /dev/null +++ b/tooling/client/manager/breakpoint_manager.h @@ -0,0 +1,53 @@ +/* + * 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. + */ +#ifndef ECMASCRIPT_TOOLING_CLIENT_MANAGER_BREAKPOINT_MANAGER_H +#define ECMASCRIPT_TOOLING_CLIENT_MANAGER_BREAKPOINT_MANAGER_H + +#include +#include +#include +#include +#include +#include "pt_json.h" +#include "pt_types.h" +namespace OHOS::ArkCompiler::Toolchain { +using PtJson = panda::ecmascript::tooling::PtJson; +using Result = panda::ecmascript::tooling::Result; +struct Breaklocation{ + std::string breakpointId; + std::string url; + std::string lineNumber; + std::string columnNumber; +}; +class Breakpoint{ +public: + Breakpoint(const Breakpoint&) = delete; + Breakpoint& operator=(const Breakpoint&) = delete; + + static Breakpoint& getInstance() { + static Breakpoint instance; + return instance; + } + + std::vector breaklist; + void HandleMessage(const std::unique_ptr json); + void show(); + void deletebreaklocation(unsigned int num); +private: + Breakpoint() = default; + ~Breakpoint() = default; +}; +} +#endif \ No newline at end of file diff --git a/tooling/client/manager/domain_manager.cpp b/tooling/client/manager/domain_manager.cpp index 8f84887b117928ba8204a170cf8f2aaf9e842099..5da193410d4bf419893b1e50ee5978536321cd46 100644 --- a/tooling/client/manager/domain_manager.cpp +++ b/tooling/client/manager/domain_manager.cpp @@ -13,11 +13,14 @@ * limitations under the License. */ +#include + +#include "domain_manager.h" #include "log_wrapper.h" #include "pt_json.h" #include "manager/variable_manager.h" #include "domain/runtime_client.h" -#include "domain_manager.h" +#include "manager/breakpoint_manager.h" using PtJson = panda::ecmascript::tooling::PtJson; using Result = panda::ecmascript::tooling::Result; @@ -50,7 +53,7 @@ void DomainManager::DispatcherReply(char* msg) ret = json->GetString("method", &wholeMethod); if (ret == Result::SUCCESS) { std::string::size_type length = wholeMethod.length(); - std::string::size_type indexPoint = 0; + std::string::size_type indexPoint; indexPoint = wholeMethod.find_first_of('.', 0); if (indexPoint == std::string::npos || indexPoint == 0 || indexPoint == length - 1) { return; @@ -60,8 +63,8 @@ void DomainManager::DispatcherReply(char* msg) if (domain == "HeapProfiler") { heapProfilerClient_.RecvReply(std::move(json)); - } else if (domain == "Profiler") { - profilerClient_.RecvProfilerResult(std::move(json)); + }else if (domain == "Profiler") { + } else if (domain == "Runtime") { RuntimeClient &runtimeClient = RuntimeClient::getInstance(); if (id == static_cast(runtimeClient.GetIdByMethod("getProperties"))) { @@ -72,7 +75,8 @@ void DomainManager::DispatcherReply(char* msg) LOGI("Runtime replay message is %{public}s", json->Stringify().c_str()); } } else if (domain == "Debugger") { - LOGI("Debugger replay message is %{public}s", json->Stringify().c_str()); + Breakpoint &breakpoint = Breakpoint::getInstance(); + breakpoint.HandleMessage(std::move(json)); } } } \ No newline at end of file diff --git a/tooling/client/toolchain_cli/cli_command.cpp b/tooling/client/toolchain_cli/cli_command.cpp index ee0efa4adcddef4882c719646c74c46023ff5592..1ae93953e89cca53ad03ae32682ee5d1c96b11b9 100644 --- a/tooling/client/toolchain_cli/cli_command.cpp +++ b/tooling/client/toolchain_cli/cli_command.cpp @@ -19,58 +19,56 @@ #include #include +#include "cli_command.h" #include "log_wrapper.h" #include "manager/domain_manager.h" #include "domain/debugger_client.h" #include "manager/variable_manager.h" #include "domain/runtime_client.h" -#include "cli_command.h" -namespace OHOS::ArkCompiler::Toolchain { -DomainManager g_domainManager; -WebsocketClient g_cliSocket; +namespace OHOS::ArkCompiler::Toolchain{ +extern ToolchainWebsocket g_cliSocket; +extern DomainManager g_domainManager; const std::string HELP_MSG = "usage: \n" " These are common commands list:\n" - " allocationtrack(at) allocation-track-start with options\n" - " allocationtrack-stop(at-stop) allocation-track-stop\n" - " heapdump(hd) heapdump with options\n" - " heapprofiler-enable(hp-enable) heapdump enable\n" - " heapprofiler-disable(hp-disable) heapdump disable\n" - " sampling(sampling) heapprofiler sampling\n" - " sampling-stop(sampling-stop) heapprofiler sampling stop\n" - " collectgarbage(gc) heapprofiler collectgarbage\n" - " cpuprofile(cp) cpuprofile start\n" - " cpuprofile-stop(cp-stop) cpuprofile stop\n" - " cpuprofile-enable(cp-enable) cpuprofile enable\n" - " cpuprofile-disable(cp-disable) cpuprofile disable\n" - " cpuprofile-show(cp-show) cpuprofile show\n" - " cpuprofile-setSamplingInterval(cp-ssi) cpuprofile setSamplingInterval\n" - " runtime-enable(rt-enable) runtime enable\n" - " heapusage(hu) runtime getHeapUsage\n" - " break(b) break with options\n" - " backtrack(bt) backtrace\n" - " continue(c) continue\n" - " delete(d) delete with options\n" - " disable disable\n" - " display display\n" - " enable enable\n" - " finish(fin) finish\n" - " frame(f) frame\n" - " help(h) list available commands\n" - " ignore(ig) ignore\n" - " infobreakpoints(infob) info-breakpoints\n" - " infosource(infos) info-source\n" - " jump(j) jump\n" - " list(l) list\n" - " next(n) next\n" - " print(p) print with options\n" - " ptype ptype\n" - " quit(q) quit\n" - " run(r) run\n" - " setvar(sv) set value with options\n" - " step(s) step\n" - " undisplay undisplay\n" - " watch(wa) watch\n"; + " allocationtrack(at) allocation-track-start with options\n" + " allocationtrack-stop(at-stop) allocation-track-stop\n" + " heapdump(hd) heapdump with options\n" + " heapprofiler-enable(hp-enable) heapdump enable\n" + " heapprofiler-disable(hp-disable) heapdump disable\n" + " sampling(sampling) heapprofiler sampling\n" + " sampling-stop(sampling-stop) heapprofiler sampling stop\n" + " collectgarbage(gc) heapprofiler collectgarbage\n" + " cpuprofile(cp) cpuprofile start\n" + " cpuprofile-stop(cp-stop) cpuprofile stop\n" + " cpuprofile-enable(cp-enable) cpuprofile enable\n" + " cpuprofile-disable(cp-disable) cpuprofile disable\n" + " runtime-enable(rt-enable) runtime enable\n" + " heapusage(hu) runtime getHeapUsage\n" + " break(b) break with options\n" + " backtrack(bt) backtrace\n" + " continue(c) continue\n" + " delete(d) delete with options\n" + " disable disable\n" + " display display\n" + " enable enable\n" + " finish(fin) finish\n" + " frame(f) frame\n" + " help(h) list available commands\n" + " ignore(ig) ignore\n" + " infobreakpoints(infob) info-breakpoints\n" + " infosource(infos) info-source\n" + " jump(j) jump\n" + " list(l) list\n" + " next(n) next\n" + " print(p) print with options\n" + " ptype ptype\n" + " quit(q) quit\n" + " run(r) run\n" + " setvar(sv) set value with options\n" + " step(s) step\n" + " undisplay undisplay\n" + " watch(wa) watch\n"; const std::vector cmdList = { "allocationtrack", @@ -85,8 +83,6 @@ const std::vector cmdList = { "cpuprofile-stop", "cpuprofile-enable", "cpuprofile-disable", - "cpuprofile-show", - "cpuprofile-setSamplingInterval", "runtime-enable", "heapusage", "break", @@ -117,67 +113,63 @@ ErrCode CliCommand::ExecCommand() { CreateCommandMap(); - ErrCode result = OnCommand(); + int result = OnCommand(); return result; } void CliCommand::CreateCommandMap() { commandMap_ = { - {std::make_pair("allocationtrack", "at"), std::bind(&CliCommand::HeapProfilerCommand, this, "allocationtrack")}, - {std::make_pair("allocationtrack-stop", "at-stop"), + {std::make_pair("allocationtrack","at"), std::bind(&CliCommand::HeapProfilerCommand, this, "allocationtrack")}, + {std::make_pair("allocationtrack-stop","at-stop"), std::bind(&CliCommand::HeapProfilerCommand, this, "allocationtrack-stop")}, - {std::make_pair("heapdump", "hd"), std::bind(&CliCommand::HeapProfilerCommand, this, "heapdump")}, - {std::make_pair("heapprofiler-enable", "hp-enable"), + {std::make_pair("heapdump","hd"), std::bind(&CliCommand::HeapProfilerCommand, this, "heapdump")}, + {std::make_pair("heapprofiler-enable","hp-enable"), std::bind(&CliCommand::HeapProfilerCommand, this, "heapprofiler-enable")}, - {std::make_pair("heapprofiler-disable", "hp-disable"), + {std::make_pair("heapprofiler-disable","hp-disable"), std::bind(&CliCommand::HeapProfilerCommand, this, "heapprofiler-disable")}, - {std::make_pair("sampling", "sampling"), std::bind(&CliCommand::HeapProfilerCommand, this, "sampling")}, - {std::make_pair("sampling-stop", "sampling-stop"), + {std::make_pair("sampling","sampling"), std::bind(&CliCommand::HeapProfilerCommand, this, "sampling")}, + {std::make_pair("sampling-stop","sampling-stop"), std::bind(&CliCommand::HeapProfilerCommand, this, "sampling-stop")}, - {std::make_pair("collectgarbage", "gc"), std::bind(&CliCommand::HeapProfilerCommand, this, "collectgarbage")}, - {std::make_pair("cpuprofile", "cp"), std::bind(&CliCommand::CpuProfileCommand, this, "cpuprofile")}, - {std::make_pair("cpuprofile-stop", "cp-stop"), + {std::make_pair("collectgarbage","gc"), std::bind(&CliCommand::HeapProfilerCommand, this, "collectgarbage")}, + {std::make_pair("cpuprofile","cp"), std::bind(&CliCommand::CpuProfileCommand, this, "cpuprofile")}, + {std::make_pair("cpuprofile-stop","cp-stop"), std::bind(&CliCommand::CpuProfileCommand, this, "cpuprofile-stop")}, - {std::make_pair("cpuprofile-enable", "cp-enable"), + {std::make_pair("cpuprofile-enable","cp-enable"), std::bind(&CliCommand::CpuProfileCommand, this, "cpuprofile-enable")}, - {std::make_pair("cpuprofile-disable", "cp-disable"), + {std::make_pair("cpuprofile-disable","cp-disable"), std::bind(&CliCommand::CpuProfileCommand, this, "cpuprofile-disable")}, - {std::make_pair("cpuprofile-show", "cp-show"), - std::bind(&CliCommand::CpuProfileCommand, this, "cpuprofile-show")}, - {std::make_pair("cpuprofile-setSamplingInterval", "cp-ssi"), - std::bind(&CliCommand::CpuProfileCommand, this, "cpuprofile-setSamplingInterval")}, - {std::make_pair("runtime-enable", "rt-enable"), std::bind(&CliCommand::RuntimeCommand, this, "runtime-enable")}, - {std::make_pair("heapusage", "hu"), std::bind(&CliCommand::RuntimeCommand, this, "heapusage")}, - {std::make_pair("break", "b"), std::bind(&CliCommand::DebuggerCommand, this, "break")}, - {std::make_pair("backtrack", "bt"), std::bind(&CliCommand::DebuggerCommand, this, "backtrack")}, - {std::make_pair("continue", "c"), std::bind(&CliCommand::DebuggerCommand, this, "continue")}, - {std::make_pair("delete", "d"), std::bind(&CliCommand::DebuggerCommand, this, "delete")}, - {std::make_pair("disable", "disable"), std::bind(&CliCommand::DebuggerCommand, this, "disable")}, - {std::make_pair("display", "display"), std::bind(&CliCommand::DebuggerCommand, this, "display")}, - {std::make_pair("enable", "enable"), std::bind(&CliCommand::DebuggerCommand, this, "enable")}, - {std::make_pair("finish", "fin"), std::bind(&CliCommand::DebuggerCommand, this, "finish")}, - {std::make_pair("frame", "f"), std::bind(&CliCommand::DebuggerCommand, this, "frame")}, - {std::make_pair("help", "h"), std::bind(&CliCommand::ExecHelpCommand, this)}, - {std::make_pair("ignore", "ig"), std::bind(&CliCommand::DebuggerCommand, this, "ignore")}, - {std::make_pair("infobreakpoints", "infob"), std::bind(&CliCommand::DebuggerCommand, this, "infobreakpoints")}, - {std::make_pair("infosource", "infos"), std::bind(&CliCommand::DebuggerCommand, this, "infosource")}, - {std::make_pair("jump", "j"), std::bind(&CliCommand::DebuggerCommand, this, "jump")}, - {std::make_pair("list", "l"), std::bind(&CliCommand::DebuggerCommand, this, "list")}, - {std::make_pair("next", "n"), std::bind(&CliCommand::DebuggerCommand, this, "next")}, - {std::make_pair("print", "p"), std::bind(&CliCommand::RuntimeCommand, this, "print")}, - {std::make_pair("print2", "p2"), std::bind(&CliCommand::RuntimeCommand, this, "print2")}, - {std::make_pair("ptype", "ptype"), std::bind(&CliCommand::DebuggerCommand, this, "ptype")}, - {std::make_pair("run", "r"), std::bind(&CliCommand::DebuggerCommand, this, "run")}, - {std::make_pair("setvar", "sv"), std::bind(&CliCommand::DebuggerCommand, this, "setvar")}, - {std::make_pair("step", "s"), std::bind(&CliCommand::DebuggerCommand, this, "step")}, - {std::make_pair("undisplay", "undisplay"), std::bind(&CliCommand::DebuggerCommand, this, "undisplay")}, - {std::make_pair("watch", "wa"), std::bind(&CliCommand::DebuggerCommand, this, "watch")}, - {std::make_pair("resume", "resume"), std::bind(&CliCommand::DebuggerCommand, this, "resume")}, + {std::make_pair("runtime-enable","rt-enable"), std::bind(&CliCommand::RuntimeCommand, this, "runtime-enable")}, + {std::make_pair("heapusage","hu"), std::bind(&CliCommand::RuntimeCommand, this, "heapusage")}, + {std::make_pair("break","b"), std::bind(&CliCommand::DebuggerCommand, this, "break")}, + {std::make_pair("backtrack","bt"), std::bind(&CliCommand::DebuggerCommand, this, "backtrack")}, + {std::make_pair("continue","c"), std::bind(&CliCommand::DebuggerCommand, this, "continue")}, + {std::make_pair("delete","d"), std::bind(&CliCommand::DebuggerCommand, this, "delete")}, + {std::make_pair("disable","disable"), std::bind(&CliCommand::DebuggerCommand, this, "disable")}, + {std::make_pair("display","display"), std::bind(&CliCommand::DebuggerCommand, this, "display")}, + {std::make_pair("enable","enable"), std::bind(&CliCommand::DebuggerCommand, this, "enable")}, + {std::make_pair("finish","fin"), std::bind(&CliCommand::DebuggerCommand, this, "finish")}, + {std::make_pair("frame","f"), std::bind(&CliCommand::DebuggerCommand, this, "frame")}, + {std::make_pair("help","h"), std::bind(&CliCommand::ExecHelpCommand, this)}, + {std::make_pair("ignore","ig"), std::bind(&CliCommand::DebuggerCommand, this, "ignore")}, + {std::make_pair("infobreakpoints","infob"), std::bind(&CliCommand::DebuggerCommand, this, "infobreakpoints")}, + {std::make_pair("infosource","infos"), std::bind(&CliCommand::DebuggerCommand, this, "infosource")}, + {std::make_pair("jump","j"), std::bind(&CliCommand::DebuggerCommand, this, "jump")}, + {std::make_pair("list","l"), std::bind(&CliCommand::DebuggerCommand, this, "list")}, + {std::make_pair("next","n"), std::bind(&CliCommand::DebuggerCommand, this, "next")}, + {std::make_pair("print","p"), std::bind(&CliCommand::RuntimeCommand, this, "print")}, + {std::make_pair("print2","p2"), std::bind(&CliCommand::RuntimeCommand, this, "print2")}, + {std::make_pair("ptype","ptype"), std::bind(&CliCommand::DebuggerCommand, this, "ptype")}, + {std::make_pair("run","r"), std::bind(&CliCommand::DebuggerCommand, this, "run")}, + {std::make_pair("setvar","sv"), std::bind(&CliCommand::DebuggerCommand, this, "setvar")}, + {std::make_pair("step","s"), std::bind(&CliCommand::DebuggerCommand, this, "step")}, + {std::make_pair("undisplay","undisplay"), std::bind(&CliCommand::DebuggerCommand, this, "undisplay")}, + {std::make_pair("watch","wa"), std::bind(&CliCommand::DebuggerCommand, this, "watch")}, + {std::make_pair("resume","resume"), std::bind(&CliCommand::DebuggerCommand, this, "resume")}, }; } -ErrCode CliCommand::HeapProfilerCommand(const std::string &cmd) +ErrCode CliCommand::HeapProfilerCommand(const std::string cmd) { std::cout << "exe success, cmd is " << cmd << std::endl; std::string request; @@ -188,54 +180,46 @@ ErrCode CliCommand::HeapProfilerCommand(const std::string &cmd) argList.push_back("/data/"); } result = heapProfilerClient->DispatcherCmd(id_, cmd, argList[0], &request); - if (result) { + if(result) { g_cliSocket.ClientSendReq(request); - if (g_domainManager.GetDomainById(id_).empty()) { + if(g_domainManager.GetDomainById(id_).empty()) { g_domainManager.SetDomainById(id_, "HeapProfiler"); } } else { - return ErrCode::ERR_FAIL; + return ERR_FAIL; } - return ErrCode::ERR_OK; + return ERR_OK; } -ErrCode CliCommand::CpuProfileCommand(const std::string &cmd) +ErrCode CliCommand::CpuProfileCommand(const std::string cmd) { std::cout << "exe success, cmd is " << cmd << std::endl; - std::string request; - bool result = false; - ProfilerClient* profilerClient = g_domainManager.GetProfilerClient(); - ProfilerSingleton& pro = ProfilerSingleton::getInstance(); - if (cmd == "cpuprofile-show") { - pro.ShowCpuFile(); - return ErrCode::ERR_OK; - } - if (cmd == "cpuprofile-setSamplingInterval") { - profilerClient->SetSamplingInterval(std::atoi(GetArgList()[0].c_str())); - } - if (cmd == "cpuprofile-stop" && GetArgList().size() == 1) { - pro.SetAddress(GetArgList()[0]); - } - result = profilerClient->DispatcherCmd(id_, cmd, &request); - if (result) { - g_cliSocket.ClientSendReq(request); - if (g_domainManager.GetDomainById(id_) == "") { - g_domainManager.SetDomainById(id_, "Profiler"); - } - } else { - return ErrCode::ERR_FAIL; - } - return ErrCode::ERR_OK; + return ERR_OK; } -ErrCode CliCommand::DebuggerCommand(const std::string &cmd) +ErrCode CliCommand::DebuggerCommand(const std::string cmd) { std::cout << "exe success, cmd is " << cmd << std::endl; std::string request; + DebugerClient debuggerCli; + Breakpoint &breakpoint=Breakpoint::getInstance(); + if(cmd=="display"){ + breakpoint.show(); + return ERR_OK; + } + if(cmd=="delete"){ + std::string bnumber=GetArgList()[0]; + unsigned int num=std::stoi(bnumber); + if(num<=breakpoint.breaklist.size()&&num>0){ + debuggerCli.AddBreakPointInfo(breakpoint.breaklist[num-1].breakpointId,"0"); + breakpoint.deletebreaklocation(num); + } + else + return ERR_FAIL; + } bool result = false; LOGE("DebuggerCommand: %{public}d", id_); - DebuggerClient debuggerCli; - if (GetArgList().size() == 2) { // 2: two parameters + if (GetArgList().size() == 2) { debuggerCli.AddBreakPointInfo(GetArgList()[0], GetArgList()[1]); } result = debuggerCli.DispatcherCmd(id_, cmd, &request); @@ -245,12 +229,12 @@ ErrCode CliCommand::DebuggerCommand(const std::string &cmd) g_domainManager.SetDomainById(id_, "Debugger"); } } else { - return ErrCode::ERR_FAIL; + return ERR_FAIL; } - return ErrCode::ERR_OK; + return ERR_OK; } -ErrCode CliCommand::RuntimeCommand(const std::string &cmd) +ErrCode CliCommand::RuntimeCommand(const std::string cmd) { std::cout << "exe success, cmd is " << cmd << std::endl; std::string request; @@ -269,20 +253,20 @@ ErrCode CliCommand::RuntimeCommand(const std::string &cmd) g_domainManager.SetDomainById(id_, "Runtime"); } } else { - return ErrCode::ERR_FAIL; + return ERR_FAIL; } - return ErrCode::ERR_OK; + return ERR_OK; } ErrCode CliCommand::ExecHelpCommand() { std::cout << HELP_MSG; - return ErrCode::ERR_OK; + return ERR_OK; } ErrCode CliCommand::OnCommand() { - std::map>::iterator it; + std::map>::iterator it; StrPair cmdPair; bool haveCmdFlag = false; @@ -295,7 +279,7 @@ ErrCode CliCommand::OnCommand() } } - for (unsigned int i = 0; i < cmdList.size(); i++) { + for(unsigned int i = 0; i < cmdList.size(); i++) { if (!strncmp(cmdList[i].c_str(), cmd_.c_str(), std::strlen(cmd_.c_str()))) { haveCmdFlag = true; std::cout << cmdList[i] << " "; @@ -308,6 +292,6 @@ ErrCode CliCommand::OnCommand() ExecHelpCommand(); } - return ErrCode::ERR_FAIL; + return ERR_FAIL; } } // namespace OHOS::ArkCompiler::Toolchain