LLDB  mainline
DiagnosticManager.cpp
Go to the documentation of this file.
1 //===-- DiagnosticManager.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 
11 #include "llvm/Support/ErrorHandling.h"
12 
13 #include "lldb/Utility/Log.h"
15 
16 using namespace lldb_private;
17 
19  if (!log)
20  return;
21 
22  std::string str = GetString();
23 
24  // GetString() puts a separator after each diagnostic. We want to remove the
25  // last '\n' because log->PutCString will add one for us.
26 
27  if (str.size() && str.back() == '\n') {
28  str.pop_back();
29  }
30 
31  log->PutCString(str.c_str());
32 }
33 
34 static const char *StringForSeverity(DiagnosticSeverity severity) {
35  switch (severity) {
36  // this should be exhaustive
38  return "error: ";
40  return "warning: ";
42  return "";
43  }
44  llvm_unreachable("switch needs another case for DiagnosticSeverity enum");
45 }
46 
48  std::string ret;
49 
50  for (const auto &diagnostic : Diagnostics()) {
51  ret.append(StringForSeverity(diagnostic->GetSeverity()));
52  ret.append(std::string(diagnostic->GetMessage()));
53  ret.push_back(separator);
54  }
55 
56  return ret;
57 }
58 
60  const char *format, ...) {
61  StreamString ss;
62 
63  va_list args;
64  va_start(args, format);
65  size_t result = ss.PrintfVarArg(format, args);
66  va_end(args);
67 
69 
70  return result;
71 }
72 
74  llvm::StringRef str) {
75  if (str.empty())
76  return;
77  AddDiagnostic(str, severity, eDiagnosticOriginLLDB);
78 }
lldb_private::DiagnosticManager::Dump
void Dump(Log *log)
Definition: DiagnosticManager.cpp:18
lldb_private::eDiagnosticSeverityWarning
@ eDiagnosticSeverityWarning
Definition: DiagnosticManager.h:33
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::DiagnosticManager::GetString
std::string GetString(char separator='\n')
Definition: DiagnosticManager.cpp:47
lldb_private::eDiagnosticSeverityError
@ eDiagnosticSeverityError
Definition: DiagnosticManager.h:32
Log.h
lldb_private::eDiagnosticOriginLLDB
@ eDiagnosticOriginLLDB
Definition: DiagnosticManager.h:25
StreamString.h
StringForSeverity
static const char * StringForSeverity(DiagnosticSeverity severity)
Definition: DiagnosticManager.cpp:34
lldb_private::eDiagnosticSeverityRemark
@ eDiagnosticSeverityRemark
Definition: DiagnosticManager.h:34
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::Stream::PrintfVarArg
size_t size_t PrintfVarArg(const char *format, va_list args)
Definition: Stream.cpp:116
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::DiagnosticManager::Diagnostics
const DiagnosticList & Diagnostics()
Definition: DiagnosticManager.h:100
lldb_private::DiagnosticManager::PutString
size_t void PutString(DiagnosticSeverity severity, llvm::StringRef str)
Definition: DiagnosticManager.cpp:73
DiagnosticManager.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
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
lldb_private::Log::PutCString
void PutCString(const char *cstr)
Definition: Log.cpp:118