Path: blob/main/contrib/llvm-project/lldb/source/Core/DebuggerEvents.cpp
39587 views
//===-- DebuggerEvents.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Core/DebuggerEvents.h"9#include "lldb/Core/Debugger.h"10#include "lldb/Core/Module.h"11#include "lldb/Core/Progress.h"12#include "llvm/Support/WithColor.h"1314using namespace lldb_private;15using namespace lldb;1617template <typename T>18static const T *GetEventDataFromEventImpl(const Event *event_ptr) {19if (event_ptr)20if (const EventData *event_data = event_ptr->GetData())21if (event_data->GetFlavor() == T::GetFlavorString())22return static_cast<const T *>(event_ptr->GetData());23return nullptr;24}2526llvm::StringRef ProgressEventData::GetFlavorString() {27return "ProgressEventData";28}2930llvm::StringRef ProgressEventData::GetFlavor() const {31return ProgressEventData::GetFlavorString();32}3334void ProgressEventData::Dump(Stream *s) const {35s->Printf(" id = %" PRIu64 ", title = \"%s\"", m_id, m_title.c_str());36if (!m_details.empty())37s->Printf(", details = \"%s\"", m_details.c_str());38if (m_completed == 0 || m_completed == m_total)39s->Printf(", type = %s", m_completed == 0 ? "start" : "end");40else41s->PutCString(", type = update");42// If m_total is UINT64_MAX, there is no progress to report, just "start"43// and "end". If it isn't we will show the completed and total amounts.44if (m_total != Progress::kNonDeterministicTotal)45s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);46}4748const ProgressEventData *49ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) {50return GetEventDataFromEventImpl<ProgressEventData>(event_ptr);51}5253StructuredData::DictionarySP54ProgressEventData::GetAsStructuredData(const Event *event_ptr) {55const ProgressEventData *progress_data =56ProgressEventData::GetEventDataFromEvent(event_ptr);5758if (!progress_data)59return {};6061auto dictionary_sp = std::make_shared<StructuredData::Dictionary>();62dictionary_sp->AddStringItem("title", progress_data->GetTitle());63dictionary_sp->AddStringItem("details", progress_data->GetDetails());64dictionary_sp->AddStringItem("message", progress_data->GetMessage());65dictionary_sp->AddIntegerItem("progress_id", progress_data->GetID());66dictionary_sp->AddIntegerItem("completed", progress_data->GetCompleted());67dictionary_sp->AddIntegerItem("total", progress_data->GetTotal());68dictionary_sp->AddBooleanItem("debugger_specific",69progress_data->IsDebuggerSpecific());7071return dictionary_sp;72}7374llvm::StringRef DiagnosticEventData::GetPrefix() const {75switch (m_severity) {76case Severity::eSeverityInfo:77return "info";78case Severity::eSeverityWarning:79return "warning";80case Severity::eSeverityError:81return "error";82}83llvm_unreachable("Fully covered switch above!");84}8586void DiagnosticEventData::Dump(Stream *s) const {87llvm::HighlightColor color = m_severity == lldb::eSeverityWarning88? llvm::HighlightColor::Warning89: llvm::HighlightColor::Error;90llvm::WithColor(s->AsRawOstream(), color, llvm::ColorMode::Enable)91<< GetPrefix();92*s << ": " << GetMessage() << '\n';93s->Flush();94}9596llvm::StringRef DiagnosticEventData::GetFlavorString() {97return "DiagnosticEventData";98}99100llvm::StringRef DiagnosticEventData::GetFlavor() const {101return DiagnosticEventData::GetFlavorString();102}103104const DiagnosticEventData *105DiagnosticEventData::GetEventDataFromEvent(const Event *event_ptr) {106return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr);107}108109StructuredData::DictionarySP110DiagnosticEventData::GetAsStructuredData(const Event *event_ptr) {111const DiagnosticEventData *diagnostic_data =112DiagnosticEventData::GetEventDataFromEvent(event_ptr);113114if (!diagnostic_data)115return {};116117auto dictionary_sp = std::make_shared<StructuredData::Dictionary>();118dictionary_sp->AddStringItem("message", diagnostic_data->GetMessage());119dictionary_sp->AddStringItem("type", diagnostic_data->GetPrefix());120dictionary_sp->AddBooleanItem("debugger_specific",121diagnostic_data->IsDebuggerSpecific());122return dictionary_sp;123}124125llvm::StringRef SymbolChangeEventData::GetFlavorString() {126return "SymbolChangeEventData";127}128129llvm::StringRef SymbolChangeEventData::GetFlavor() const {130return SymbolChangeEventData::GetFlavorString();131}132133const SymbolChangeEventData *134SymbolChangeEventData::GetEventDataFromEvent(const Event *event_ptr) {135return GetEventDataFromEventImpl<SymbolChangeEventData>(event_ptr);136}137138void SymbolChangeEventData::DoOnRemoval(Event *event_ptr) {139DebuggerSP debugger_sp(m_debugger_wp.lock());140if (!debugger_sp)141return;142143for (TargetSP target_sp : debugger_sp->GetTargetList().Targets()) {144if (ModuleSP module_sp =145target_sp->GetImages().FindModule(m_module_spec.GetUUID())) {146{147std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());148if (!module_sp->GetSymbolFileFileSpec())149module_sp->SetSymbolFileFileSpec(m_module_spec.GetSymbolFileSpec());150}151ModuleList module_list;152module_list.Append(module_sp);153target_sp->SymbolsDidLoad(module_list);154}155}156}157158159