|
13 | 13 | #include <sstream> |
14 | 14 |
|
15 | 15 | #include "DAP.h" |
| 16 | +#include "JSONUtils.h" |
16 | 17 | #include "LLDBUtils.h" |
17 | 18 | #include "lldb/API/SBCommandInterpreter.h" |
18 | 19 | #include "llvm/ADT/StringExtras.h" |
@@ -687,26 +688,45 @@ bool DAP::HandleObject(const llvm::json::Object &object) { |
687 | 688 | if (packet_type == "request") { |
688 | 689 | const auto command = GetString(object, "command"); |
689 | 690 | auto handler_pos = request_handlers.find(std::string(command)); |
690 | | - llvm::json::Object telemetry_entry; |
691 | | - telemetry_entry.insert({"request_name", std::string(command)}); |
692 | | - telemetry_entry.insert( |
693 | | - {"start_time", start_time.time_since_epoch().count()}); |
| 691 | + lldb::SBStructuredData telemetry_entry; |
| 692 | + |
| 693 | + // There does not seem to be a direct way to construct an SBStructuredData. |
| 694 | + // So we first create a json::Array object, |
| 695 | + // then we serialize it to a string, |
| 696 | + // and finally call SBStructuredData::SetFromJSON(string). |
| 697 | + // |
| 698 | + // TODO: This seems unnecessarily complex. Ideally, we should be able to |
| 699 | + // just send a json::Object directly? Does the SB API allow json? |
| 700 | + // |
| 701 | + llvm::json::Array telemetry_array({ |
| 702 | + {"request_name", std::string(command)}, |
| 703 | + {"start_time", start_time.time_since_epoch().count()}, |
| 704 | + }); |
694 | 705 |
|
695 | 706 | if (handler_pos != request_handlers.end()) { |
696 | 707 | handler_pos->second(object); |
697 | 708 | auto end_time = std::chrono::steady_clock::now(); |
698 | | - telemetry_entry.insert({"end_time", end_time.time_since_epoch().count()}); |
| 709 | + telemetry_array.push_back( |
| 710 | + llvm::json::Value{"end_time", end_time.time_since_epoch().count()}); |
| 711 | + |
| 712 | + llvm::json::Value val(std::move(telemetry_array)); |
| 713 | + std::string string_rep = lldb_dap::JSONToString(val); |
| 714 | + telemetry_entry.SetFromJSON(string_rep.c_str()); |
699 | 715 | debugger.SendTelemetry(telemetry_entry); |
700 | 716 | return true; // Success |
701 | 717 | } else { |
702 | 718 | if (log) |
703 | 719 | *log << "error: unhandled command \"" << command.data() << "\"" |
704 | 720 | << std::endl; |
705 | 721 | auto end_time = std::chrono::steady_clock::now(); |
706 | | - telemetry_entry.insert({"end_time", end_time.time_since_epoch().count()}); |
707 | | - telemetry_entry.insert( |
708 | | - {"error", "unhandled-command:" + std::string(command)}); |
709 | | - debugger.SendTelemetry(telemetry_entry); |
| 722 | + telemetry_array.push_back( |
| 723 | + llvm::json::Value{"end_time", end_time.time_since_epoch().count()}); |
| 724 | + telemetry_array.push_back(llvm::json::Value{ |
| 725 | + "error", llvm::Twine("unhandled-command:" + command).str()}); |
| 726 | + |
| 727 | + llvm::json::Value val(std::move(telemetry_array)); |
| 728 | + std::string string_rep = lldb_dap::JSONToString(val); |
| 729 | + telemetry_entry.SetFromJSON(string_rep.c_str()); |
710 | 730 | debugger.SendTelemetry(telemetry_entry); |
711 | 731 | return false; // Fail |
712 | 732 | } |
|
0 commit comments