Skip to content

Commit dd6340b

Browse files
committed
Adjusting Response.message field to be an enum of supported values.
1 parent 8512820 commit dd6340b

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

lldb/tools/lldb-dap/Protocol.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,43 @@ json::Value toJSON(const Response &R) {
101101
{"request_seq", R.request_seq},
102102
{"success", R.success}};
103103

104-
if (R.message)
105-
Result.insert({"message", R.message});
104+
if (R.message) {
105+
assert(!R.success && "message can only be used if success is false");
106+
switch (*R.message) {
107+
case Response::Message::cancelled:
108+
Result.insert({"message", "cancelled"});
109+
break;
110+
case Response::Message::notStopped:
111+
Result.insert({"message", "notStopped"});
112+
break;
113+
}
114+
}
106115

107116
if (R.rawBody)
108117
Result.insert({"body", R.rawBody});
109118

110119
return std::move(Result);
111120
}
112121

122+
bool fromJSON(json::Value const &Params, Response::Message &M, json::Path P) {
123+
auto rawMessage = Params.getAsString();
124+
if (!rawMessage) {
125+
P.report("expected a string");
126+
return false;
127+
}
128+
std::optional<Response::Message> message =
129+
StringSwitch<std::optional<Response::Message>>(*rawMessage)
130+
.Case("cancelled", Response::Message::cancelled)
131+
.Case("notStopped", Response::Message::notStopped)
132+
.Default(std::nullopt);
133+
if (!message) {
134+
P.report("unexpected value, expected 'cancelled' or 'notStopped'");
135+
return false;
136+
}
137+
M = *message;
138+
return true;
139+
}
140+
113141
bool fromJSON(json::Value const &Params, Response &R, json::Path P) {
114142
json::ObjectMapper O(Params, P);
115143
if (!O)

lldb/tools/lldb-dap/Protocol.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,15 @@ bool fromJSON(const llvm::json::Value &, Event &, llvm::json::Path);
137137
// ]
138138
// }
139139
struct Response {
140+
enum class Message {
141+
cancelled,
142+
notStopped,
143+
};
144+
140145
int64_t request_seq;
141146
std::string command;
142147
bool success;
143-
std::optional<std::string> message;
148+
std::optional<Message> message;
144149
std::optional<llvm::json::Value> rawBody;
145150
};
146151
bool fromJSON(const llvm::json::Value &, Response &, llvm::json::Path);

0 commit comments

Comments
 (0)