68 lines · cpp
1//===-- ProtocolEvents.cpp ------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "Protocol/ProtocolEvents.h"10#include "JSONUtils.h"11#include "llvm/Support/JSON.h"12 13using namespace llvm;14 15namespace lldb_dap::protocol {16 17json::Value toJSON(const CapabilitiesEventBody &CEB) {18 return json::Object{{"capabilities", CEB.capabilities}};19}20 21json::Value toJSON(const ModuleEventBody::Reason &MEBR) {22 switch (MEBR) {23 case ModuleEventBody::eReasonNew:24 return "new";25 case ModuleEventBody::eReasonChanged:26 return "changed";27 case ModuleEventBody::eReasonRemoved:28 return "removed";29 }30 llvm_unreachable("unhandled module event reason!.");31}32 33json::Value toJSON(const ModuleEventBody &MEB) {34 return json::Object{{"reason", MEB.reason}, {"module", MEB.module}};35}36 37llvm::json::Value toJSON(const InvalidatedEventBody::Area &IEBA) {38 switch (IEBA) {39 case InvalidatedEventBody::eAreaAll:40 return "all";41 case InvalidatedEventBody::eAreaStacks:42 return "stacks";43 case InvalidatedEventBody::eAreaThreads:44 return "threads";45 case InvalidatedEventBody::eAreaVariables:46 return "variables";47 }48 llvm_unreachable("unhandled invalidated event area!.");49}50 51llvm::json::Value toJSON(const InvalidatedEventBody &IEB) {52 json::Object Result{{"areas", IEB.areas}};53 if (IEB.threadId)54 Result.insert({"threadId", IEB.threadId});55 if (IEB.stackFrameId)56 Result.insert({"stackFrameId", IEB.stackFrameId});57 return Result;58}59 60llvm::json::Value toJSON(const MemoryEventBody &MEB) {61 return json::Object{62 {"memoryReference", EncodeMemoryReference(MEB.memoryReference)},63 {"offset", MEB.offset},64 {"count", MEB.count}};65}66 67} // namespace lldb_dap::protocol68