diff --git a/tooling/client/BUILD.gn b/tooling/client/BUILD.gn index 45e6acc2008e1fb7968c842e1f785bba9143dbab..cf815bf79f0ed21c7299652116693e8e04e3edb3 100644 --- a/tooling/client/BUILD.gn +++ b/tooling/client/BUILD.gn @@ -43,10 +43,10 @@ ohos_source_set("libark_client_set") { deps += hiviewdfx_deps include_dirs = [ - "//arkcompiler/toolchain/inspector", - "//arkcompiler/toolchain/websocket", - "//arkcompiler/toolchain/tooling/base", - "//arkcompiler/toolchain/tooling/client", + "./", + "../base", + "../../inspector", + "../../websocket", "//third_party/cJSON", ] @@ -57,13 +57,14 @@ ohos_source_set("libark_client_set") { "domain/runtime_client.cpp", "manager/domain_manager.cpp", "manager/variable_manager.cpp", + "manager/breakpoint_manager.cpp", "utils/utils.cpp", "websocket/websocket_client.cpp", ] deps += [ + "../:libark_ecma_debugger_set", "$ark_third_party_root/openssl:libcrypto_shared", - "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", "//third_party/libuv:uv", sdk_libc_secshared_dep, ] diff --git a/tooling/client/ark_cli/BUILD.gn b/tooling/client/ark_cli/BUILD.gn index 286eef7d9ac057a42e12426166c5f668262b5433..0cc992b7f301d0946e0c82ba140dfb4260ce9b59 100644 --- a/tooling/client/ark_cli/BUILD.gn +++ b/tooling/client/ark_cli/BUILD.gn @@ -84,17 +84,17 @@ ohos_executable("arkdb") { ] include_dirs = [ - "//arkcompiler/toolchain/tooling", - "//arkcompiler/toolchain/inspector", - "//arkcompiler/toolchain/websocket", - "//arkcompiler/toolchain/tooling/base", - "//arkcompiler/toolchain/tooling/client", - "//arkcompiler/toolchain/tooling/client/ark_cli", + "./", + "../", + "../../base", + "../../../inspector", + "../../../tooling", + "../../../websocket", "//third_party/cJSON", "//third_party/libuv/include", ] - deps = [ "//arkcompiler/toolchain/tooling/client:libark_client_set" ] + deps = [ "../:libark_client_set" ] external_deps = [ "ets_runtime:libark_jsruntime", diff --git a/tooling/client/ark_cli/cli_command.cpp b/tooling/client/ark_cli/cli_command.cpp index 431438d8b82eec9d327f7019fa209e41ed59a54a..01f931d911a9be37e890cdd696ac2558fe9681ae 100644 --- a/tooling/client/ark_cli/cli_command.cpp +++ b/tooling/client/ark_cli/cli_command.cpp @@ -25,6 +25,7 @@ #include "manager/variable_manager.h" #include "domain/runtime_client.h" #include "cli_command.h" +#include "manager/breakpoint_manager.h" namespace OHOS::ArkCompiler::Toolchain { DomainManager g_domainManager; @@ -232,22 +233,37 @@ 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 - debuggerCli.AddBreakPointInfo(GetArgList()[0], std::stoi(GetArgList()[1])); + if (GetArgList().size() == 2) { + debuggerCli.AddBreakPointInfo(GetArgList()[0], GetArgList()[1]); } result = debuggerCli.DispatcherCmd(id_, cmd, &request); if (result) { g_cliSocket.ClientSendReq(request); - if (g_domainManager.GetDomainById(id_).empty()) { + if (g_domainManager.GetDomainById(id_) == "") { 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) diff --git a/tooling/client/domain/debugger_client.cpp b/tooling/client/domain/debugger_client.cpp index 1e9215e0548dd5d3c8465321139055f9bfd3973f..6031af7204d8facdcafa2264e07eb94775e9b2cb 100644 --- a/tooling/client/domain/debugger_client.cpp +++ b/tooling/client/domain/debugger_client.cpp @@ -14,12 +14,11 @@ */ #include "domain/debugger_client.h" -#include "pt_json.h" + #include "log_wrapper.h" +#include "pt_json.h" #include -#include -#include using PtJson = panda::ecmascript::tooling::PtJson; namespace OHOS::ArkCompiler::Toolchain { @@ -92,8 +91,10 @@ std::string DebuggerClient::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(); } 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..57c29e7ceb01b7d94e993a93b1e13a331aebc12a --- /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..3a49d19a61166000fade7eb74711e7ef5ea4751c 100644 --- a/tooling/client/manager/domain_manager.cpp +++ b/tooling/client/manager/domain_manager.cpp @@ -18,6 +18,7 @@ #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; @@ -72,6 +73,8 @@ void DomainManager::DispatcherReply(char* msg) LOGI("Runtime replay message is %{public}s", json->Stringify().c_str()); } } else if (domain == "Debugger") { + Breakpoint &breakpoint = Breakpoint::getInstance(); + breakpoint.HandleMessage(std::move(json)); LOGI("Debugger replay message is %{public}s", json->Stringify().c_str()); } } diff --git a/tooling/client/utils/utils.cpp b/tooling/client/utils/utils.cpp index cb1635f7f6a5bb915018fe263e1ddbadb89313b7..be6572a9edf7f937dab88fbeefce46bf8c6d0173 100644 --- a/tooling/client/utils/utils.cpp +++ b/tooling/client/utils/utils.cpp @@ -17,8 +17,6 @@ #include "log_wrapper.h" #include -#include -#include namespace OHOS::ArkCompiler::Toolchain { bool Utils::GetCurrentTime(char *date, char *tim, size_t size) diff --git a/tooling/client/utils/utils.h b/tooling/client/utils/utils.h index 64b1b6d354ea6986d54d81350bf2f4ca68cf95fb..5ada563ca30d6737f0c006715d5849a2e13c9f0a 100644 --- a/tooling/client/utils/utils.h +++ b/tooling/client/utils/utils.h @@ -22,9 +22,6 @@ namespace OHOS::ArkCompiler::Toolchain { class Utils { public: static bool GetCurrentTime(char *date, char *tim, size_t size); - -private: - }; } // OHOS::ArkCompiler::Toolchain #endif \ No newline at end of file