Skip to content

🍒/austria/d230848a85a922260b7ad6984f2dd19222c125a6+5e65e79bace6127da493de1445161f1179e4e47f+2fc38b2b7bf9896806749655124ea5f13cc6d383 #4080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 55 additions & 34 deletions lldb/include/lldb/Core/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <memory>
#include <vector>

#include "lldb/Core/DebuggerEvents.h"
#include "lldb/Core/FormatEntity.h"
#include "lldb/Core/IOHandler.h"
#include "lldb/Core/SourceManager.h"
Expand Down Expand Up @@ -76,6 +77,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
/// Broadcaster event bits definitions.
enum {
eBroadcastBitProgress = (1 << 0),
eBroadcastBitWarning = (1 << 1),
eBroadcastBitError = (1 << 2),
};

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

class ProgressEventData : public EventData {

public:
ProgressEventData(uint64_t progress_id, const std::string &message,
uint64_t completed, uint64_t total,
bool debugger_specific)
: m_message(message), m_id(progress_id), m_completed(completed),
m_total(total), m_debugger_specific(debugger_specific) {}

static ConstString GetFlavorString();

ConstString GetFlavor() const override;

void Dump(Stream *s) const override;

static const ProgressEventData *
GetEventDataFromEvent(const Event *event_ptr);
uint64_t GetID() const { return m_id; }
uint64_t GetCompleted() const { return m_completed; }
uint64_t GetTotal() const { return m_total; }
const std::string &GetMessage() const { return m_message; }
bool IsDebuggerSpecific() const { return m_debugger_specific; }

private:
std::string m_message;
const uint64_t m_id;
uint64_t m_completed;
const uint64_t m_total;
const bool m_debugger_specific;
ProgressEventData(const ProgressEventData &) = delete;
const ProgressEventData &operator=(const ProgressEventData &) = delete;
};

~Debugger() override;

static lldb::DebuggerSP
Expand Down Expand Up @@ -415,6 +385,50 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
return m_broadcaster_manager_sp;
}

/// Report warning events.
///
/// Progress events will be delivered to any debuggers that have listeners
/// for the eBroadcastBitError.
///
/// \param[in] message
/// The warning message to be reported.
///
/// \param [in] debugger_id
/// If this optional parameter has a value, it indicates the unique
/// debugger identifier that this progress should be delivered to. If this
/// optional parameter does not have a value, the progress will be
/// delivered to all debuggers.
///
/// \param [in] once
/// If a pointer is passed to a std::once_flag, then it will be used to
/// ensure the given warning is only broadcast once.
static void
ReportWarning(std::string messsage,
llvm::Optional<lldb::user_id_t> debugger_id = llvm::None,
std::once_flag *once = nullptr);

/// Report error events.
///
/// Progress events will be delivered to any debuggers that have listeners
/// for the eBroadcastBitError.
///
/// \param[in] message
/// The error message to be reported.
///
/// \param [in] debugger_id
/// If this optional parameter has a value, it indicates the unique
/// debugger identifier that this progress should be delivered to. If this
/// optional parameter does not have a value, the progress will be
/// delivered to all debuggers.
///
/// \param [in] once
/// If a pointer is passed to a std::once_flag, then it will be used to
/// ensure the given error is only broadcast once.
static void
ReportError(std::string messsage,
llvm::Optional<lldb::user_id_t> debugger_id = llvm::None,
std::once_flag *once = nullptr);

protected:
friend class CommandInterpreter;
friend class SwiftREPL;
Expand Down Expand Up @@ -454,7 +468,12 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
uint64_t completed, uint64_t total,
llvm::Optional<lldb::user_id_t> debugger_id);

void PrintProgress(const Debugger::ProgressEventData &data);
static void ReportDiagnosticImpl(DiagnosticEventData::Type type,
std::string message,
llvm::Optional<lldb::user_id_t> debugger_id,
std::once_flag *once);

void PrintProgress(const ProgressEventData &data);

bool StartEventHandlerThread();

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

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

void HandleDiagnosticEvent(const lldb::EventSP &event_sp);

// Ensures two threads don't attempt to flush process output in parallel.
std::mutex m_output_flush_mutex;
void FlushProcessOutput(Process &process, bool flush_stdout,
Expand Down
85 changes: 85 additions & 0 deletions lldb/include/lldb/Core/DebuggerEvents.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//===-- DebuggerEvents.h ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Event.h"

#include <string>

#ifndef LLDB_CORE_DEBUGGER_EVENTS_H
#define LLDB_CORE_DEBUGGER_EVENTS_H

namespace lldb_private {
class Stream;

class ProgressEventData : public EventData {
public:
ProgressEventData(uint64_t progress_id, const std::string &message,
uint64_t completed, uint64_t total, bool debugger_specific)
: m_message(message), m_id(progress_id), m_completed(completed),
m_total(total), m_debugger_specific(debugger_specific) {}

static ConstString GetFlavorString();

ConstString GetFlavor() const override;

void Dump(Stream *s) const override;

static const ProgressEventData *GetEventDataFromEvent(const Event *event_ptr);
uint64_t GetID() const { return m_id; }
uint64_t GetCompleted() const { return m_completed; }
uint64_t GetTotal() const { return m_total; }
const std::string &GetMessage() const { return m_message; }
bool IsDebuggerSpecific() const { return m_debugger_specific; }

private:
std::string m_message;
const uint64_t m_id;
uint64_t m_completed;
const uint64_t m_total;
const bool m_debugger_specific;
ProgressEventData(const ProgressEventData &) = delete;
const ProgressEventData &operator=(const ProgressEventData &) = delete;
};

class DiagnosticEventData : public EventData {
public:
enum class Type {
Warning,
Error,
};
DiagnosticEventData(Type type, std::string message, bool debugger_specific)
: m_message(std::move(message)), m_type(type),
m_debugger_specific(debugger_specific) {}
~DiagnosticEventData() {}

const std::string &GetMessage() const { return m_message; }
Type GetType() const { return m_type; }

llvm::StringRef GetPrefix() const;

void Dump(Stream *s) const override;

static ConstString GetFlavorString();
ConstString GetFlavor() const override;

static const DiagnosticEventData *
GetEventDataFromEvent(const Event *event_ptr);

protected:
std::string m_message;
Type m_type;
const bool m_debugger_specific;

DiagnosticEventData(const DiagnosticEventData &) = delete;
const DiagnosticEventData &operator=(const DiagnosticEventData &) = delete;
};

} // namespace lldb_private

#endif // LLDB_CORE_DEBUGGER_EVENTS_H
5 changes: 3 additions & 2 deletions lldb/source/API/SBDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "lldb/API/SBTypeSynthetic.h"

#include "lldb/Core/Debugger.h"
#include "lldb/Core/DebuggerEvents.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Progress.h"
#include "lldb/Core/StreamFile.h"
Expand Down Expand Up @@ -152,8 +153,8 @@ const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,
uint64_t &total,
bool &is_debugger_specific) {
LLDB_INSTRUMENT_VA(event);
const Debugger::ProgressEventData *progress_data =
Debugger::ProgressEventData::GetEventDataFromEvent(event.get());
const ProgressEventData *progress_data =
ProgressEventData::GetEventDataFromEvent(event.get());
if (progress_data == nullptr)
return nullptr;
progress_id = progress_data->GetID();
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_lldb_library(lldbCore
AddressResolverFileLine.cpp
Communication.cpp
Debugger.cpp
DebuggerEvents.cpp
Declaration.cpp
Disassembler.cpp
DumpDataExtractor.cpp
Expand Down
Loading