Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Interpreter/CommandReturnObject.h
Line
Count
Source (jump to first uncovered line)
1
//===-- CommandReturnObject.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_INTERPRETER_COMMANDRETURNOBJECT_H
10
#define LLDB_INTERPRETER_COMMANDRETURNOBJECT_H
11
12
#include "lldb/Core/StreamFile.h"
13
#include "lldb/Utility/StreamString.h"
14
#include "lldb/Utility/StreamTee.h"
15
#include "lldb/lldb-private.h"
16
17
#include "llvm/ADT/StringRef.h"
18
#include "llvm/Support/FormatVariadic.h"
19
#include "llvm/Support/WithColor.h"
20
21
#include <memory>
22
23
namespace lldb_private {
24
25
class CommandReturnObject {
26
public:
27
  CommandReturnObject(bool colors);
28
29
91.7k
  ~CommandReturnObject() = default;
30
31
334k
  llvm::StringRef GetOutputData() {
32
334k
    lldb::StreamSP stream_sp(m_out_stream.GetStreamAtIndex(eStreamStringIndex));
33
334k
    if (stream_sp)
34
231k
      return std::static_pointer_cast<StreamString>(stream_sp)->GetString();
35
102k
    return llvm::StringRef();
36
334k
  }
37
38
184k
  llvm::StringRef GetErrorData() {
39
184k
    lldb::StreamSP stream_sp(m_err_stream.GetStreamAtIndex(eStreamStringIndex));
40
184k
    if (stream_sp)
41
86.1k
      return std::static_pointer_cast<StreamString>(stream_sp)->GetString();
42
97.9k
    return llvm::StringRef();
43
184k
  }
44
45
2.18M
  Stream &GetOutputStream() {
46
    // Make sure we at least have our normal string stream output stream
47
2.18M
    lldb::StreamSP stream_sp(m_out_stream.GetStreamAtIndex(eStreamStringIndex));
48
2.18M
    if (!stream_sp) {
49
3.00k
      stream_sp = std::make_shared<StreamString>();
50
3.00k
      m_out_stream.SetStreamAtIndex(eStreamStringIndex, stream_sp);
51
3.00k
    }
52
2.18M
    return m_out_stream;
53
2.18M
  }
54
55
23.6k
  Stream &GetErrorStream() {
56
    // Make sure we at least have our normal string stream output stream
57
23.6k
    lldb::StreamSP stream_sp(m_err_stream.GetStreamAtIndex(eStreamStringIndex));
58
23.6k
    if (!stream_sp) {
59
1.39k
      stream_sp = std::make_shared<StreamString>();
60
1.39k
      m_err_stream.SetStreamAtIndex(eStreamStringIndex, stream_sp);
61
1.39k
    }
62
23.6k
    return m_err_stream;
63
23.6k
  }
64
65
93
  void SetImmediateOutputFile(lldb::FileSP file_sp) {
66
93
    if (m_suppress_immediate_output)
67
1
      return;
68
92
    lldb::StreamSP stream_sp(new StreamFile(file_sp));
69
92
    m_out_stream.SetStreamAtIndex(eImmediateStreamIndex, stream_sp);
70
92
  }
71
72
82
  void SetImmediateErrorFile(lldb::FileSP file_sp) {
73
82
    if (m_suppress_immediate_output)
74
1
      return;
75
81
    lldb::StreamSP stream_sp(new StreamFile(file_sp));
76
81
    m_err_stream.SetStreamAtIndex(eImmediateStreamIndex, stream_sp);
77
81
  }
78
79
18
  void SetImmediateOutputStream(const lldb::StreamSP &stream_sp) {
80
18
    if (m_suppress_immediate_output)
81
0
      return;
82
18
    m_out_stream.SetStreamAtIndex(eImmediateStreamIndex, stream_sp);
83
18
  }
84
85
7
  void SetImmediateErrorStream(const lldb::StreamSP &stream_sp) {
86
7
    if (m_suppress_immediate_output)
87
0
      return;
88
7
    m_err_stream.SetStreamAtIndex(eImmediateStreamIndex, stream_sp);
89
7
  }
90
91
6.10k
  lldb::StreamSP GetImmediateOutputStream() {
92
6.10k
    return m_out_stream.GetStreamAtIndex(eImmediateStreamIndex);
93
6.10k
  }
94
95
6.09k
  lldb::StreamSP GetImmediateErrorStream() {
96
6.09k
    return m_err_stream.GetStreamAtIndex(eImmediateStreamIndex);
97
6.09k
  }
98
99
  void Clear();
100
101
  void AppendMessage(llvm::StringRef in_string);
102
103
  void AppendMessageWithFormat(const char *format, ...)
104
      __attribute__((format(printf, 2, 3)));
105
106
  void AppendWarning(llvm::StringRef in_string);
107
108
  void AppendWarningWithFormat(const char *format, ...)
109
      __attribute__((format(printf, 2, 3)));
110
111
  void AppendError(llvm::StringRef in_string);
112
113
  void AppendRawError(llvm::StringRef in_string);
114
115
  void AppendErrorWithFormat(const char *format, ...)
116
      __attribute__((format(printf, 2, 3)));
117
118
  template <typename... Args>
119
283
  void AppendMessageWithFormatv(const char *format, Args &&... args) {
120
283
    AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
121
283
  }
void lldb_private::CommandReturnObject::AppendMessageWithFormatv<unsigned long long, unsigned long long, lldb_private::MemoryRegionInfo::OptionalBool, lldb_private::MemoryRegionInfo::OptionalBool, lldb_private::MemoryRegionInfo::OptionalBool, char const*, lldb_private::ConstString&, char const*, lldb_private::ConstString&>(char const*, unsigned long long&&, unsigned long long&&, lldb_private::MemoryRegionInfo::OptionalBool&&, lldb_private::MemoryRegionInfo::OptionalBool&&, lldb_private::MemoryRegionInfo::OptionalBool&&, char const*&&, lldb_private::ConstString&, char const*&&, lldb_private::ConstString&)
Line
Count
Source
119
182
  void AppendMessageWithFormatv(const char *format, Args &&... args) {
120
182
    AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
121
182
  }
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendMessageWithFormatv<unsigned long long&>(char const*, unsigned long long&)
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendMessageWithFormatv<unsigned long long&, unsigned long long&, unsigned long long&, char const*>(char const*, unsigned long long&, unsigned long long&, unsigned long long&, char const*&&)
void lldb_private::CommandReturnObject::AppendMessageWithFormatv<llvm::json::Value>(char const*, llvm::json::Value&&)
Line
Count
Source
119
13
  void AppendMessageWithFormatv(const char *format, Args &&... args) {
120
13
    AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
121
13
  }
void lldb_private::CommandReturnObject::AppendMessageWithFormatv<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, char const*>(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&, char const*&&)
Line
Count
Source
119
83
  void AppendMessageWithFormatv(const char *format, Args &&... args) {
120
83
    AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
121
83
  }
void lldb_private::CommandReturnObject::AppendMessageWithFormatv<llvm::StringRef>(char const*, llvm::StringRef&&)
Line
Count
Source
119
5
  void AppendMessageWithFormatv(const char *format, Args &&... args) {
120
5
    AppendMessage(llvm::formatv(format, std::forward<Args>(args)...).str());
121
5
  }
122
123
  template <typename... Args>
124
  void AppendWarningWithFormatv(const char *format, Args &&... args) {
125
    AppendWarning(llvm::formatv(format, std::forward<Args>(args)...).str());
126
  }
127
128
  template <typename... Args>
129
13
  void AppendErrorWithFormatv(const char *format, Args &&... args) {
130
13
    AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
131
13
  }
void lldb_private::CommandReturnObject::AppendErrorWithFormatv<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&>(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)
Line
Count
Source
129
4
  void AppendErrorWithFormatv(const char *format, Args &&... args) {
130
4
    AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
131
4
  }
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendErrorWithFormatv<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, llvm::detail::ErrorAdapter>(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, llvm::detail::ErrorAdapter&&)
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendErrorWithFormatv<int&>(char const*, int&)
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendErrorWithFormatv<char const*>(char const*, char const*&&)
void lldb_private::CommandReturnObject::AppendErrorWithFormatv<llvm::StringRef>(char const*, llvm::StringRef&&)
Line
Count
Source
129
1
  void AppendErrorWithFormatv(const char *format, Args &&... args) {
130
1
    AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
131
1
  }
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendErrorWithFormatv<char const*&, char const*&, llvm::StringRef>(char const*, char const*&, char const*&, llvm::StringRef&&)
void lldb_private::CommandReturnObject::AppendErrorWithFormatv<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&)
Line
Count
Source
129
1
  void AppendErrorWithFormatv(const char *format, Args &&... args) {
130
1
    AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
131
1
  }
void lldb_private::CommandReturnObject::AppendErrorWithFormatv<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&)
Line
Count
Source
129
4
  void AppendErrorWithFormatv(const char *format, Args &&... args) {
130
4
    AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
131
4
  }
void lldb_private::CommandReturnObject::AppendErrorWithFormatv<lldb_private::FileSpec const&>(char const*, lldb_private::FileSpec const&)
Line
Count
Source
129
1
  void AppendErrorWithFormatv(const char *format, Args &&... args) {
130
1
    AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
131
1
  }
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendErrorWithFormatv<unsigned long long&>(char const*, unsigned long long&)
void lldb_private::CommandReturnObject::AppendErrorWithFormatv<char const*&>(char const*, char const*&)
Line
Count
Source
129
2
  void AppendErrorWithFormatv(const char *format, Args &&... args) {
130
2
    AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
131
2
  }
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendErrorWithFormatv<unsigned long&, unsigned int const&>(char const*, unsigned long&, unsigned int const&)
Unexecuted instantiation: void lldb_private::CommandReturnObject::AppendErrorWithFormatv<llvm::detail::ErrorAdapter>(char const*, llvm::detail::ErrorAdapter&&)
132
133
  void SetError(const Status &error, const char *fallback_error_cstr = nullptr);
134
135
  lldb::ReturnStatus GetStatus() const;
136
137
  void SetStatus(lldb::ReturnStatus status);
138
139
  bool Succeeded() const;
140
141
  bool HasResult() const;
142
143
  bool GetDidChangeProcessState() const;
144
145
  void SetDidChangeProcessState(bool b);
146
147
  bool GetInteractive() const;
148
149
  void SetInteractive(bool b);
150
151
  bool GetSuppressImmediateOutput() const;
152
153
  void SetSuppressImmediateOutput(bool b);
154
155
private:
156
  enum { eStreamStringIndex = 0, eImmediateStreamIndex = 1 };
157
158
  StreamTee m_out_stream;
159
  StreamTee m_err_stream;
160
161
  lldb::ReturnStatus m_status = lldb::eReturnStatusStarted;
162
163
  bool m_did_change_process_state = false;
164
  bool m_suppress_immediate_output = false;
165
166
  /// If true, then the input handle from the debugger will be hooked up.
167
  bool m_interactive = true;
168
};
169
170
} // namespace lldb_private
171
172
#endif // LLDB_INTERPRETER_COMMANDRETURNOBJECT_H