LLDB  mainline
DiagnosticManager.h
Go to the documentation of this file.
1 //===-- DiagnosticManager.h -------------------------------------*- C++ -*-===//
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 #ifndef LLDB_EXPRESSION_DIAGNOSTICMANAGER_H
10 #define LLDB_EXPRESSION_DIAGNOSTICMANAGER_H
11 
12 #include "lldb/lldb-defines.h"
13 #include "lldb/lldb-types.h"
14 
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/StringRef.h"
17 
18 #include <string>
19 #include <vector>
20 
21 namespace lldb_private {
22 
29 };
30 
35 };
36 
38 
39 class Diagnostic {
40  friend class DiagnosticManager;
41 
42 public:
43  DiagnosticOrigin getKind() const { return m_origin; }
44 
45  static bool classof(const Diagnostic *diag) {
46  DiagnosticOrigin kind = diag->getKind();
47  switch (kind) {
51  return true;
54  return false;
55  }
56  }
57 
58  Diagnostic(llvm::StringRef message, DiagnosticSeverity severity,
59  DiagnosticOrigin origin, uint32_t compiler_id)
60  : m_message(message), m_severity(severity), m_origin(origin),
61  m_compiler_id(compiler_id) {}
62 
63  Diagnostic(const Diagnostic &rhs)
66 
67  virtual ~Diagnostic() = default;
68 
69  virtual bool HasFixIts() const { return false; }
70 
72 
73  uint32_t GetCompilerID() const { return m_compiler_id; }
74 
75  llvm::StringRef GetMessage() const { return m_message; }
76 
77  void AppendMessage(llvm::StringRef message,
78  bool precede_with_newline = true) {
79  if (precede_with_newline)
80  m_message.push_back('\n');
81  m_message += message;
82  }
83 
84 protected:
88  uint32_t m_compiler_id; // Compiler-specific diagnostic ID
89 };
90 
91 typedef std::vector<std::unique_ptr<Diagnostic>> DiagnosticList;
92 
94 public:
95  void Clear() {
96  m_diagnostics.clear();
97  m_fixed_expression.clear();
98  }
99 
101 
102  bool HasFixIts() const {
103  return llvm::any_of(m_diagnostics,
104  [](const std::unique_ptr<Diagnostic> &diag) {
105  return diag->HasFixIts();
106  });
107  }
108 
109  void AddDiagnostic(llvm::StringRef message, DiagnosticSeverity severity,
110  DiagnosticOrigin origin,
111  uint32_t compiler_id = LLDB_INVALID_COMPILER_ID) {
112  m_diagnostics.emplace_back(
113  std::make_unique<Diagnostic>(message, severity, origin, compiler_id));
114  }
115 
116  void AddDiagnostic(std::unique_ptr<Diagnostic> diagnostic) {
117  m_diagnostics.push_back(std::move(diagnostic));
118  }
119 
120  size_t Printf(DiagnosticSeverity severity, const char *format, ...)
121  __attribute__((format(printf, 3, 4)));
122  void PutString(DiagnosticSeverity severity, llvm::StringRef str);
123 
124  void AppendMessageToDiagnostic(llvm::StringRef str) {
125  if (!m_diagnostics.empty())
126  m_diagnostics.back()->AppendMessage(str);
127  }
128 
129  // Returns a string containing errors in this format:
130  //
131  // "error: error text\n
132  // warning: warning text\n
133  // remark text\n"
134  std::string GetString(char separator = '\n');
135 
136  void Dump(Log *log);
137 
139 
140  // Moves fixed_expression to the internal storage.
141  void SetFixedExpression(std::string fixed_expression) {
142  m_fixed_expression = std::move(fixed_expression);
143  }
144 
145 protected:
148 };
149 }
150 
151 #endif // LLDB_EXPRESSION_DIAGNOSTICMANAGER_H
lldb_private::eDiagnosticOriginSwift
@ eDiagnosticOriginSwift
Definition: DiagnosticManager.h:27
lldb_private::Diagnostic::AppendMessage
void AppendMessage(llvm::StringRef message, bool precede_with_newline=true)
Definition: DiagnosticManager.h:77
lldb_private::Diagnostic::Diagnostic
Diagnostic(llvm::StringRef message, DiagnosticSeverity severity, DiagnosticOrigin origin, uint32_t compiler_id)
Definition: DiagnosticManager.h:58
lldb_private::eDiagnosticOriginLLVM
@ eDiagnosticOriginLLVM
Definition: DiagnosticManager.h:28
llvm
Definition: Debugger.h:49
lldb_private::DiagnosticManager::GetFixedExpression
const std::string & GetFixedExpression()
Definition: DiagnosticManager.h:138
lldb_private::Diagnostic::m_message
std::string m_message
Definition: DiagnosticManager.h:85
lldb_private::DiagnosticManager::Dump
void Dump(Log *log)
Definition: DiagnosticManager.cpp:18
lldb-defines.h
lldb_private::DiagnosticManager::m_fixed_expression
std::string m_fixed_expression
Definition: DiagnosticManager.h:147
lldb_private::DiagnosticManager::m_diagnostics
DiagnosticList m_diagnostics
Definition: DiagnosticManager.h:146
lldb_private::Diagnostic::~Diagnostic
virtual ~Diagnostic()=default
lldb_private::Diagnostic::Diagnostic
Diagnostic(const Diagnostic &rhs)
Definition: DiagnosticManager.h:63
lldb_private::Diagnostic::GetCompilerID
uint32_t GetCompilerID() const
Definition: DiagnosticManager.h:73
lldb_private::eDiagnosticSeverityWarning
@ eDiagnosticSeverityWarning
Definition: DiagnosticManager.h:33
lldb_private::DiagnosticManager::GetString
std::string GetString(char separator='\n')
Definition: DiagnosticManager.cpp:47
lldb_private::eDiagnosticSeverityError
@ eDiagnosticSeverityError
Definition: DiagnosticManager.h:32
lldb_private::DiagnosticManager::AddDiagnostic
void AddDiagnostic(std::unique_ptr< Diagnostic > diagnostic)
Definition: DiagnosticManager.h:116
lldb_private::DiagnosticList
std::vector< std::unique_ptr< Diagnostic > > DiagnosticList
Definition: DiagnosticManager.h:91
lldb_private::DiagnosticManager::HasFixIts
bool HasFixIts() const
Definition: DiagnosticManager.h:102
lldb_private::eDiagnosticOriginLLDB
@ eDiagnosticOriginLLDB
Definition: DiagnosticManager.h:25
lldb_private::DiagnosticManager::SetFixedExpression
void SetFixedExpression(std::string fixed_expression)
Definition: DiagnosticManager.h:141
lldb_private::eDiagnosticSeverityRemark
@ eDiagnosticSeverityRemark
Definition: DiagnosticManager.h:34
lldb_private::Diagnostic::GetSeverity
DiagnosticSeverity GetSeverity() const
Definition: DiagnosticManager.h:71
lldb_private::Diagnostic::GetMessage
llvm::StringRef GetMessage() const
Definition: DiagnosticManager.h:75
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
lldb_private::eDiagnosticOriginClang
@ eDiagnosticOriginClang
Definition: DiagnosticManager.h:26
lldb_private::Diagnostic::m_severity
DiagnosticSeverity m_severity
Definition: DiagnosticManager.h:86
lldb-types.h
lldb_private::DiagnosticManager::Diagnostics
const DiagnosticList & Diagnostics()
Definition: DiagnosticManager.h:100
lldb_private::DiagnosticOrigin
DiagnosticOrigin
Definition: DiagnosticManager.h:23
lldb_private::Diagnostic::getKind
DiagnosticOrigin getKind() const
Definition: DiagnosticManager.h:43
message
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
Definition: Plugins/Trace/intel-pt/CMakeLists.txt:6
uint32_t
lldb_private::DiagnosticManager::AppendMessageToDiagnostic
void AppendMessageToDiagnostic(llvm::StringRef str)
Definition: DiagnosticManager.h:124
lldb_private::DiagnosticManager::PutString
size_t void PutString(DiagnosticSeverity severity, llvm::StringRef str)
Definition: DiagnosticManager.cpp:73
lldb_private::eDiagnosticOriginUnknown
@ eDiagnosticOriginUnknown
Definition: DiagnosticManager.h:24
lldb_private::DiagnosticManager
Definition: DiagnosticManager.h:93
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::LLDB_INVALID_COMPILER_ID
const uint32_t LLDB_INVALID_COMPILER_ID
Definition: DiagnosticManager.h:37
lldb_private::Diagnostic::m_origin
DiagnosticOrigin m_origin
Definition: DiagnosticManager.h:87
lldb_private::Diagnostic::classof
static bool classof(const Diagnostic *diag)
Definition: DiagnosticManager.h:45
lldb_private::Diagnostic::HasFixIts
virtual bool HasFixIts() const
Definition: DiagnosticManager.h:69
lldb_private::DiagnosticManager::Clear
void Clear()
Definition: DiagnosticManager.h:95
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Diagnostic::m_compiler_id
uint32_t m_compiler_id
Definition: DiagnosticManager.h:88
lldb_private::Diagnostic
Definition: DiagnosticManager.h:39
lldb_private::Log
Definition: Log.h:49
lldb_private::DiagnosticManager::AddDiagnostic
void AddDiagnostic(llvm::StringRef message, DiagnosticSeverity severity, DiagnosticOrigin origin, uint32_t compiler_id=LLDB_INVALID_COMPILER_ID)
Definition: DiagnosticManager.h:109
lldb_private::DiagnosticSeverity
DiagnosticSeverity
Definition: DiagnosticManager.h:31
lldb_private::DiagnosticManager::Printf
size_t Printf(DiagnosticSeverity severity, const char *format,...) __attribute__((format(printf
Definition: DiagnosticManager.cpp:59