@@ -266,40 +266,47 @@ void DAP::SendJSON(const llvm::json::Value &json) {
266266  Send (message);
267267}
268268
269- void  DAP::Send (const  Message &message) {
270-   if  (const  protocol::Event *event = std::get_if<protocol::Event>(&message)) {
271-     if  (llvm::Error err = transport.Send (*event))
269+ Id DAP::Send (const  Message &message) {
270+   std::lock_guard<std::mutex> guard (call_mutex);
271+   if  (const  protocol::Event *e = std::get_if<protocol::Event>(&message)) {
272+     protocol::Event event = *e;
273+     event.seq  = seq++;
274+     if  (llvm::Error err = transport.Send (event))
272275      DAP_LOG_ERROR (log, std::move (err), " ({0}) sending event failed"  ,
273276                    m_client_name);
274-     return ;
277+     return  event. seq ;
275278  }
276279
277-   if  (const  Request *req = std::get_if<Request>(&message)) {
278-     if  (llvm::Error err = transport.Send (*req))
280+   if  (const  Request *r = std::get_if<Request>(&message)) {
281+     Request req = *r;
282+     req.seq  = seq++;
283+     if  (llvm::Error err = transport.Send (req))
279284      DAP_LOG_ERROR (log, std::move (err), " ({0}) sending request failed"  ,
280285                    m_client_name);
281-     return ;
286+     return  req. seq ;
282287  }
283288
284-   if  (const  Response *resp = std::get_if<Response>(&message)) {
289+   if  (const  Response *r = std::get_if<Response>(&message)) {
290+     Response resp = *r;
291+     resp.seq  = seq++;
285292    //  FIXME: After all the requests have migrated from LegacyRequestHandler >
286293    //  RequestHandler<> this should be handled in RequestHandler<>::operator().
287294    //  If the debugger was interrupted, convert this response into a
288295    //  'cancelled' response because we might have a partial result.
289-     llvm::Error err =
290-         (debugger.InterruptRequested ())
291-             ? transport.Send ({/* request_seq=*/  resp->request_seq ,
292-                               /* command=*/  resp->command ,
293-                               /* success=*/ false ,
294-                               /* message=*/  eResponseMessageCancelled,
295-                               /* body=*/  std::nullopt })
296-             : transport.Send (*resp);
297-     if  (err) {
296+     llvm::Error err = (debugger.InterruptRequested ())
297+                           ? transport.Send ({
298+                                 /* seq=*/  resp.seq ,
299+                                 /* request_seq=*/  resp.request_seq ,
300+                                 /* command=*/  resp.command ,
301+                                 /* success=*/ false ,
302+                                 /* message=*/  eResponseMessageCancelled,
303+                                 /* body=*/  std::nullopt ,
304+                             })
305+                           : transport.Send (resp);
306+     if  (err)
298307      DAP_LOG_ERROR (log, std::move (err), " ({0}) sending response failed"  ,
299308                    m_client_name);
300-       return ;
301-     }
302-     return ;
309+     return  resp.seq ;
303310  }
304311
305312  llvm_unreachable (" Unexpected message type"  );
@@ -1453,17 +1460,20 @@ void DAP::EventThread() {
14531460            if  (remove_module && module_exists) {
14541461              modules.erase (module_id);
14551462              Send (protocol::Event{
1456-                   " module"  , ModuleEventBody{std::move (p_module).value (),
1457-                                             ModuleEventBody::eReasonRemoved}});
1463+                   0 , " module"  ,
1464+                   ModuleEventBody{std::move (p_module).value (),
1465+                                   ModuleEventBody::eReasonRemoved}});
14581466            } else  if  (module_exists) {
14591467              Send (protocol::Event{
1460-                   " module"  , ModuleEventBody{std::move (p_module).value (),
1461-                                             ModuleEventBody::eReasonChanged}});
1468+                   0 , " module"  ,
1469+                   ModuleEventBody{std::move (p_module).value (),
1470+                                   ModuleEventBody::eReasonChanged}});
14621471            } else  if  (!remove_module) {
14631472              modules.insert (module_id);
14641473              Send (protocol::Event{
1465-                   " module"  , ModuleEventBody{std::move (p_module).value (),
1466-                                             ModuleEventBody::eReasonNew}});
1474+                   0 , " module"  ,
1475+                   ModuleEventBody{std::move (p_module).value (),
1476+                                   ModuleEventBody::eReasonNew}});
14671477            }
14681478          }
14691479        }
0 commit comments