@@ -43,6 +43,17 @@ bool fromJSON(const json::Value &Params, Source &S, json::Path P) {
4343 O.map (" sourceReference" , S.sourceReference );
4444}
4545
46+ llvm::json::Value toJSON (const Source &S) {
47+ json::Object result{
48+ {" name" , S.name },
49+ {" path" , S.path },
50+ {" sourceReference" , S.sourceReference },
51+ {" presentationHint" , S.presentationHint },
52+ };
53+
54+ return result;
55+ }
56+
4657json::Value toJSON (const ExceptionBreakpointsFilter &EBF) {
4758 json::Object result{{" filter" , EBF.filter }, {" label" , EBF.label }};
4859
@@ -254,4 +265,134 @@ bool fromJSON(const llvm::json::Value &Params, SteppingGranularity &SG,
254265 return true ;
255266}
256267
268+ json::Value toJSON (const Breakpoint &BP) {
269+ json::Object result{{" verified" , BP.verified }};
270+
271+ if (BP.id )
272+ result.insert ({" id" , *BP.id });
273+ if (BP.message )
274+ result.insert ({" message" , *BP.message });
275+ if (BP.source )
276+ result.insert ({" source" , *BP.source });
277+ if (BP.line )
278+ result.insert ({" line" , *BP.line });
279+ if (BP.column )
280+ result.insert ({" column" , *BP.column });
281+ if (BP.endLine )
282+ result.insert ({" endLine" , *BP.endLine });
283+ if (BP.endColumn )
284+ result.insert ({" endColumn" , *BP.endColumn });
285+ if (BP.instructionReference )
286+ result.insert ({" instructionReference" , *BP.instructionReference });
287+ if (BP.offset )
288+ result.insert ({" offset" , *BP.offset });
289+ if (BP.reason ) {
290+ switch (*BP.reason ) {
291+ case Breakpoint::Reason::eBreakpointReasonPending:
292+ result.insert ({" reason" , " pending" });
293+ break ;
294+ case Breakpoint::Reason::eBreakpointReasonFailed:
295+ result.insert ({" reason" , " failed" });
296+ break ;
297+ }
298+ }
299+
300+ return result;
301+ }
302+
303+ bool fromJSON (const llvm::json::Value &Params, ExceptionBreakMode &EBM,
304+ llvm::json::Path P) {
305+ auto rawMode = Params.getAsString ();
306+ if (!rawMode) {
307+ P.report (" expected a string" );
308+ return false ;
309+ }
310+ std::optional<ExceptionBreakMode> mode =
311+ StringSwitch<std::optional<ExceptionBreakMode>>(*rawMode)
312+ .Case (" never" , eExceptionBreakModeNever)
313+ .Case (" always" , eExceptionBreakModeAlways)
314+ .Case (" unhandled" , eExceptionBreakModeUnhandled)
315+ .Case (" userUnhandled" , eExceptionBreakModeUserUnhandled)
316+ .Default (std::nullopt );
317+ if (!mode) {
318+ P.report (" unexpected ExceptionBreakMode value" );
319+ return false ;
320+ }
321+ EBM = *mode;
322+ return true ;
323+ }
324+
325+ bool fromJSON (const llvm::json::Value &Params, ExceptionPathSegment &EPS,
326+ llvm::json::Path P) {
327+ json::ObjectMapper O (Params, P);
328+ return O && O.map (" negate" , EPS.negate ) && O.map (" names" , EPS.names );
329+ }
330+
331+ bool fromJSON (const llvm::json::Value &Params, ExceptionOptions &EO,
332+ llvm::json::Path P) {
333+ json::ObjectMapper O (Params, P);
334+ return O && O.map (" path" , EO.path ) && O.map (" breakMode" , EO.breakMode );
335+ }
336+
337+ bool fromJSON (const llvm::json::Value &Params, ExceptionFilterOptions &EFO,
338+ llvm::json::Path P) {
339+ json::ObjectMapper O (Params, P);
340+ return O && O.map (" filterId" , EFO.filterId ) &&
341+ O.map (" condition" , EFO.condition ) && O.map (" mode" , EFO.mode );
342+ }
343+
344+ bool fromJSON (const llvm::json::Value &Params, SourceBreakpoint &SB,
345+ llvm::json::Path P) {
346+ json::ObjectMapper O (Params, P);
347+ return O && O.map (" line" , SB.line ) && O.map (" column" , SB.column ) &&
348+ O.map (" condition" , SB.condition ) &&
349+ O.map (" hitCondition" , SB.hitCondition ) &&
350+ O.map (" logMessage" , SB.logMessage ) && O.map (" mode" , SB.mode );
351+ }
352+
353+ bool fromJSON (const llvm::json::Value &Params, FunctionBreakpoint &FB,
354+ llvm::json::Path P) {
355+ json::ObjectMapper O (Params, P);
356+ return O && O.map (" name" , FB.name ) && O.map (" condition" , FB.condition ) &&
357+ O.map (" hitCondition" , FB.hitCondition );
358+ }
359+
360+ bool fromJSON (const llvm::json::Value &Params, DataBreakpointAccessType &DBAT,
361+ llvm::json::Path P) {
362+ auto rawAccessType = Params.getAsString ();
363+ if (!rawAccessType) {
364+ P.report (" expected a string" );
365+ return false ;
366+ }
367+ std::optional<DataBreakpointAccessType> accessType =
368+ StringSwitch<std::optional<DataBreakpointAccessType>>(*rawAccessType)
369+ .Case (" read" , eDataBreakpointAccessTypeRead)
370+ .Case (" write" , eDataBreakpointAccessTypeWrite)
371+ .Case (" readWrite" , eDataBreakpointAccessTypeReadWrite)
372+ .Default (std::nullopt );
373+ if (!accessType) {
374+ P.report (" unexpected value, expected 'read', 'write', or 'readWrite'" );
375+ return false ;
376+ }
377+ DBAT = *accessType;
378+ return true ;
379+ }
380+
381+ bool fromJSON (const llvm::json::Value &Params, DataBreakpointInfo &DBI,
382+ llvm::json::Path P) {
383+ json::ObjectMapper O (Params, P);
384+ return O && O.map (" dataId" , DBI.dataId ) &&
385+ O.map (" accessType" , DBI.accessType ) &&
386+ O.map (" condition" , DBI.condition ) &&
387+ O.map (" hitCondition" , DBI.hitCondition );
388+ }
389+
390+ bool fromJSON (const llvm::json::Value &Params, InstructionBreakpoint &IB,
391+ llvm::json::Path P) {
392+ json::ObjectMapper O (Params, P);
393+ return O && O.map (" instructionReference" , IB.instructionReference ) &&
394+ O.map (" offset" , IB.offset ) && O.map (" condition" , IB.condition ) &&
395+ O.map (" hitCondition" , IB.hitCondition ) && O.map (" mode" , IB.mode );
396+ }
397+
257398} // namespace lldb_dap::protocol
0 commit comments