1 //===-- DebuggerEvents.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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Core/DebuggerEvents.h" 10 11 using namespace lldb_private; 12 13 template <typename T> 14 static const T *GetEventDataFromEventImpl(const Event *event_ptr) { 15 if (event_ptr) 16 if (const EventData *event_data = event_ptr->GetData()) 17 if (event_data->GetFlavor() == T::GetFlavorString()) 18 return static_cast<const T *>(event_ptr->GetData()); 19 return nullptr; 20 } 21 22 ConstString ProgressEventData::GetFlavorString() { 23 static ConstString g_flavor("ProgressEventData"); 24 return g_flavor; 25 } 26 27 ConstString ProgressEventData::GetFlavor() const { 28 return ProgressEventData::GetFlavorString(); 29 } 30 31 void ProgressEventData::Dump(Stream *s) const { 32 s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str()); 33 if (m_completed == 0 || m_completed == m_total) 34 s->Printf(", type = %s", m_completed == 0 ? "start" : "end"); 35 else 36 s->PutCString(", type = update"); 37 // If m_total is UINT64_MAX, there is no progress to report, just "start" 38 // and "end". If it isn't we will show the completed and total amounts. 39 if (m_total != UINT64_MAX) 40 s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total); 41 } 42 43 const ProgressEventData * 44 ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) { 45 return GetEventDataFromEventImpl<ProgressEventData>(event_ptr); 46 } 47 48 llvm::StringRef DiagnosticEventData::GetPrefix() const { 49 switch (m_type) { 50 case Type::Warning: 51 return "warning"; 52 case Type::Error: 53 return "error"; 54 } 55 llvm_unreachable("Fully covered switch above!"); 56 } 57 58 void DiagnosticEventData::Dump(Stream *s) const { 59 *s << GetPrefix() << ": " << GetMessage() << '\n'; 60 s->Flush(); 61 } 62 63 ConstString DiagnosticEventData::GetFlavorString() { 64 static ConstString g_flavor("DiagnosticEventData"); 65 return g_flavor; 66 } 67 68 ConstString DiagnosticEventData::GetFlavor() const { 69 return DiagnosticEventData::GetFlavorString(); 70 } 71 72 const DiagnosticEventData * 73 DiagnosticEventData::GetEventDataFromEvent(const Event *event_ptr) { 74 return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr); 75 } 76