Skip to content

Commit d821797

Browse files
authored
Merge pull request #4080 from apple/πŸ’/austria/d230848a85a922260b7ad6984f2dd19222c125a6+5e65e79bace6127da493de1445161f1179e4e47f+2fc38b2b7bf9896806749655124ea5f13cc6d383
πŸ’/austria/d230848a85a922260b7ad6984f2dd19222c125a6+5e65e79bace6127da493de1445161f1179e4e47f+2fc38b2b7bf9896806749655124ea5f13cc6d383
2 parents 7967957 + cd4af34 commit d821797

File tree

16 files changed

+580
-136
lines changed

16 files changed

+580
-136
lines changed

β€Žlldb/include/lldb/Core/Debugger.h

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <memory>
1515
#include <vector>
1616

17+
#include "lldb/Core/DebuggerEvents.h"
1718
#include "lldb/Core/FormatEntity.h"
1819
#include "lldb/Core/IOHandler.h"
1920
#include "lldb/Core/SourceManager.h"
@@ -76,6 +77,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
7677
/// Broadcaster event bits definitions.
7778
enum {
7879
eBroadcastBitProgress = (1 << 0),
80+
eBroadcastBitWarning = (1 << 1),
81+
eBroadcastBitError = (1 << 2),
7982
};
8083

8184
static ConstString GetStaticBroadcasterClass();
@@ -84,39 +87,6 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
8487
Broadcaster &GetBroadcaster() { return m_broadcaster; }
8588
const Broadcaster &GetBroadcaster() const { return m_broadcaster; }
8689

87-
class ProgressEventData : public EventData {
88-
89-
public:
90-
ProgressEventData(uint64_t progress_id, const std::string &message,
91-
uint64_t completed, uint64_t total,
92-
bool debugger_specific)
93-
: m_message(message), m_id(progress_id), m_completed(completed),
94-
m_total(total), m_debugger_specific(debugger_specific) {}
95-
96-
static ConstString GetFlavorString();
97-
98-
ConstString GetFlavor() const override;
99-
100-
void Dump(Stream *s) const override;
101-
102-
static const ProgressEventData *
103-
GetEventDataFromEvent(const Event *event_ptr);
104-
uint64_t GetID() const { return m_id; }
105-
uint64_t GetCompleted() const { return m_completed; }
106-
uint64_t GetTotal() const { return m_total; }
107-
const std::string &GetMessage() const { return m_message; }
108-
bool IsDebuggerSpecific() const { return m_debugger_specific; }
109-
110-
private:
111-
std::string m_message;
112-
const uint64_t m_id;
113-
uint64_t m_completed;
114-
const uint64_t m_total;
115-
const bool m_debugger_specific;
116-
ProgressEventData(const ProgressEventData &) = delete;
117-
const ProgressEventData &operator=(const ProgressEventData &) = delete;
118-
};
119-
12090
~Debugger() override;
12191

12292
static lldb::DebuggerSP
@@ -415,6 +385,50 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
415385
return m_broadcaster_manager_sp;
416386
}
417387

388+
/// Report warning events.
389+
///
390+
/// Progress events will be delivered to any debuggers that have listeners
391+
/// for the eBroadcastBitError.
392+
///
393+
/// \param[in] message
394+
/// The warning message to be reported.
395+
///
396+
/// \param [in] debugger_id
397+
/// If this optional parameter has a value, it indicates the unique
398+
/// debugger identifier that this progress should be delivered to. If this
399+
/// optional parameter does not have a value, the progress will be
400+
/// delivered to all debuggers.
401+
///
402+
/// \param [in] once
403+
/// If a pointer is passed to a std::once_flag, then it will be used to
404+
/// ensure the given warning is only broadcast once.
405+
static void
406+
ReportWarning(std::string messsage,
407+
llvm::Optional<lldb::user_id_t> debugger_id = llvm::None,
408+
std::once_flag *once = nullptr);
409+
410+
/// Report error events.
411+
///
412+
/// Progress events will be delivered to any debuggers that have listeners
413+
/// for the eBroadcastBitError.
414+
///
415+
/// \param[in] message
416+
/// The error message to be reported.
417+
///
418+
/// \param [in] debugger_id
419+
/// If this optional parameter has a value, it indicates the unique
420+
/// debugger identifier that this progress should be delivered to. If this
421+
/// optional parameter does not have a value, the progress will be
422+
/// delivered to all debuggers.
423+
///
424+
/// \param [in] once
425+
/// If a pointer is passed to a std::once_flag, then it will be used to
426+
/// ensure the given error is only broadcast once.
427+
static void
428+
ReportError(std::string messsage,
429+
llvm::Optional<lldb::user_id_t> debugger_id = llvm::None,
430+
std::once_flag *once = nullptr);
431+
418432
protected:
419433
friend class CommandInterpreter;
420434
friend class SwiftREPL;
@@ -454,7 +468,12 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
454468
uint64_t completed, uint64_t total,
455469
llvm::Optional<lldb::user_id_t> debugger_id);
456470

457-
void PrintProgress(const Debugger::ProgressEventData &data);
471+
static void ReportDiagnosticImpl(DiagnosticEventData::Type type,
472+
std::string message,
473+
llvm::Optional<lldb::user_id_t> debugger_id,
474+
std::once_flag *once);
475+
476+
void PrintProgress(const ProgressEventData &data);
458477

459478
bool StartEventHandlerThread();
460479

@@ -487,6 +506,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
487506

488507
void HandleProgressEvent(const lldb::EventSP &event_sp);
489508

509+
void HandleDiagnosticEvent(const lldb::EventSP &event_sp);
510+
490511
// Ensures two threads don't attempt to flush process output in parallel.
491512
std::mutex m_output_flush_mutex;
492513
void FlushProcessOutput(Process &process, bool flush_stdout,
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//===-- DebuggerEvents.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+
#include "lldb/Utility/ConstString.h"
10+
#include "lldb/Utility/Event.h"
11+
12+
#include <string>
13+
14+
#ifndef LLDB_CORE_DEBUGGER_EVENTS_H
15+
#define LLDB_CORE_DEBUGGER_EVENTS_H
16+
17+
namespace lldb_private {
18+
class Stream;
19+
20+
class ProgressEventData : public EventData {
21+
public:
22+
ProgressEventData(uint64_t progress_id, const std::string &message,
23+
uint64_t completed, uint64_t total, bool debugger_specific)
24+
: m_message(message), m_id(progress_id), m_completed(completed),
25+
m_total(total), m_debugger_specific(debugger_specific) {}
26+
27+
static ConstString GetFlavorString();
28+
29+
ConstString GetFlavor() const override;
30+
31+
void Dump(Stream *s) const override;
32+
33+
static const ProgressEventData *GetEventDataFromEvent(const Event *event_ptr);
34+
uint64_t GetID() const { return m_id; }
35+
uint64_t GetCompleted() const { return m_completed; }
36+
uint64_t GetTotal() const { return m_total; }
37+
const std::string &GetMessage() const { return m_message; }
38+
bool IsDebuggerSpecific() const { return m_debugger_specific; }
39+
40+
private:
41+
std::string m_message;
42+
const uint64_t m_id;
43+
uint64_t m_completed;
44+
const uint64_t m_total;
45+
const bool m_debugger_specific;
46+
ProgressEventData(const ProgressEventData &) = delete;
47+
const ProgressEventData &operator=(const ProgressEventData &) = delete;
48+
};
49+
50+
class DiagnosticEventData : public EventData {
51+
public:
52+
enum class Type {
53+
Warning,
54+
Error,
55+
};
56+
DiagnosticEventData(Type type, std::string message, bool debugger_specific)
57+
: m_message(std::move(message)), m_type(type),
58+
m_debugger_specific(debugger_specific) {}
59+
~DiagnosticEventData() {}
60+
61+
const std::string &GetMessage() const { return m_message; }
62+
Type GetType() const { return m_type; }
63+
64+
llvm::StringRef GetPrefix() const;
65+
66+
void Dump(Stream *s) const override;
67+
68+
static ConstString GetFlavorString();
69+
ConstString GetFlavor() const override;
70+
71+
static const DiagnosticEventData *
72+
GetEventDataFromEvent(const Event *event_ptr);
73+
74+
protected:
75+
std::string m_message;
76+
Type m_type;
77+
const bool m_debugger_specific;
78+
79+
DiagnosticEventData(const DiagnosticEventData &) = delete;
80+
const DiagnosticEventData &operator=(const DiagnosticEventData &) = delete;
81+
};
82+
83+
} // namespace lldb_private
84+
85+
#endif // LLDB_CORE_DEBUGGER_EVENTS_H

β€Žlldb/source/API/SBDebugger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "lldb/API/SBTypeSynthetic.h"
3636

3737
#include "lldb/Core/Debugger.h"
38+
#include "lldb/Core/DebuggerEvents.h"
3839
#include "lldb/Core/PluginManager.h"
3940
#include "lldb/Core/Progress.h"
4041
#include "lldb/Core/StreamFile.h"
@@ -152,8 +153,8 @@ const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,
152153
uint64_t &total,
153154
bool &is_debugger_specific) {
154155
LLDB_INSTRUMENT_VA(event);
155-
const Debugger::ProgressEventData *progress_data =
156-
Debugger::ProgressEventData::GetEventDataFromEvent(event.get());
156+
const ProgressEventData *progress_data =
157+
ProgressEventData::GetEventDataFromEvent(event.get());
157158
if (progress_data == nullptr)
158159
return nullptr;
159160
progress_id = progress_data->GetID();

β€Žlldb/source/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_lldb_library(lldbCore
2626
AddressResolverFileLine.cpp
2727
Communication.cpp
2828
Debugger.cpp
29+
DebuggerEvents.cpp
2930
Declaration.cpp
3031
Disassembler.cpp
3132
DumpDataExtractor.cpp

0 commit comments

Comments
Β (0)