LLDB  mainline
DebuggerEvents.cpp
Go to the documentation of this file.
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 
10 #include "llvm/Support/WithColor.h"
11 
12 using namespace lldb_private;
13 
14 template <typename T>
15 static const T *GetEventDataFromEventImpl(const Event *event_ptr) {
16  if (event_ptr)
17  if (const EventData *event_data = event_ptr->GetData())
18  if (event_data->GetFlavor() == T::GetFlavorString())
19  return static_cast<const T *>(event_ptr->GetData());
20  return nullptr;
21 }
22 
24  static ConstString g_flavor("ProgressEventData");
25  return g_flavor;
26 }
27 
30 }
31 
33  s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str());
34  if (m_completed == 0 || m_completed == m_total)
35  s->Printf(", type = %s", m_completed == 0 ? "start" : "end");
36  else
37  s->PutCString(", type = update");
38  // If m_total is UINT64_MAX, there is no progress to report, just "start"
39  // and "end". If it isn't we will show the completed and total amounts.
40  if (m_total != UINT64_MAX)
41  s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
42 }
43 
44 const ProgressEventData *
46  return GetEventDataFromEventImpl<ProgressEventData>(event_ptr);
47 }
48 
49 llvm::StringRef DiagnosticEventData::GetPrefix() const {
50  switch (m_type) {
51  case Type::Warning:
52  return "warning";
53  case Type::Error:
54  return "error";
55  }
56  llvm_unreachable("Fully covered switch above!");
57 }
58 
60  llvm::HighlightColor color = m_type == Type::Warning
61  ? llvm::HighlightColor::Warning
63  llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)
64  << GetPrefix();
65  *s << ": " << GetMessage() << '\n';
66  s->Flush();
67 }
68 
70  static ConstString g_flavor("DiagnosticEventData");
71  return g_flavor;
72 }
73 
76 }
77 
78 const DiagnosticEventData *
80  return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr);
81 }
lldb_private::DiagnosticEventData::Type::Warning
@ Warning
lldb_private::Event
Definition: Event.h:182
lldb_private::EventData
Definition: Event.h:36
lldb_private::DiagnosticEventData::Dump
void Dump(Stream *s) const override
Definition: DebuggerEvents.cpp:59
lldb_private::Stream::Flush
virtual void Flush()=0
Flush the stream.
lldb_private::ProgressEventData::GetFlavor
ConstString GetFlavor() const override
Definition: DebuggerEvents.cpp:28
lldb_private::ProgressEventData::Dump
void Dump(Stream *s) const override
Definition: DebuggerEvents.cpp:32
lldb_private::DiagnosticEventData::GetEventDataFromEvent
static const DiagnosticEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition: DebuggerEvents.cpp:79
lldb_private::Stream
Definition: Stream.h:28
lldb_private::DiagnosticEventData::m_type
Type m_type
Definition: DebuggerEvents.h:78
GetEventDataFromEventImpl
static const T * GetEventDataFromEventImpl(const Event *event_ptr)
Definition: DebuggerEvents.cpp:15
lldb_private::DiagnosticEventData::GetPrefix
llvm::StringRef GetPrefix() const
Definition: DebuggerEvents.cpp:49
lldb_private::Event::GetData
EventData * GetData()
Definition: Event.h:202
lldb_private::ProgressEventData
Definition: DebuggerEvents.h:20
lldb_private::ProgressEventData::GetEventDataFromEvent
static const ProgressEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition: DebuggerEvents.cpp:45
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ProgressEventData::GetFlavorString
static ConstString GetFlavorString()
Definition: DebuggerEvents.cpp:23
lldb_private::DiagnosticEventData::GetFlavor
ConstString GetFlavor() const override
Definition: DebuggerEvents.cpp:74
lldb_private::DiagnosticEventData::Type::Error
@ Error
lldb_private::ProgressEventData::m_total
const uint64_t m_total
Definition: DebuggerEvents.h:45
lldb_private::DiagnosticEventData
Definition: DebuggerEvents.h:51
lldb_private::ProgressEventData::m_id
const uint64_t m_id
Definition: DebuggerEvents.h:43
DebuggerEvents.h
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb_private::DiagnosticEventData::GetMessage
const std::string & GetMessage() const
Definition: DebuggerEvents.h:62
lldb_private::ProgressEventData::m_completed
uint64_t m_completed
Definition: DebuggerEvents.h:44
lldb_private::ProgressEventData::m_message
std::string m_message
Definition: DebuggerEvents.h:42
lldb_private::DiagnosticEventData::GetFlavorString
static ConstString GetFlavorString()
Definition: DebuggerEvents.cpp:69
UINT64_MAX
#define UINT64_MAX
Definition: lldb-defines.h:23