diff options
Diffstat (limited to 'lldb/source/API')
-rw-r--r-- | lldb/source/API/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/source/API/SBDebugger.cpp | 2 | ||||
-rw-r--r-- | lldb/source/API/SBProcess.cpp | 31 | ||||
-rw-r--r-- | lldb/source/API/SBStructuredData.cpp | 165 | ||||
-rw-r--r-- | lldb/source/API/SystemInitializerFull.cpp | 8 |
5 files changed, 203 insertions, 4 deletions
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index 8e9e1fb2278..3dba1b08703 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -47,6 +47,7 @@ add_lldb_library(liblldb SHARED SBSourceManager.cpp SBStream.cpp SBStringList.cpp + SBStructuredData.cpp SBSymbol.cpp SBSymbolContext.cpp SBSymbolContextList.cpp diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index 3493ad507a7..cc55230d8b3 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -491,7 +491,7 @@ SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, if (err != nullptr) ::fwrite (stdio_buffer, 1, len, err); } - + if (event_type & Process::eBroadcastBitStateChanged) { StateType event_state = SBProcess::GetStateFromEvent (event); diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 50211bfde32..9b8ac8461ac 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -39,6 +39,7 @@ #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBMemoryRegionInfo.h" #include "lldb/API/SBMemoryRegionInfoList.h" +#include "lldb/API/SBStructuredData.h" #include "lldb/API/SBThread.h" #include "lldb/API/SBThreadCollection.h" #include "lldb/API/SBStream.h" @@ -1029,8 +1030,16 @@ SBProcess::GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_ SBProcess SBProcess::GetProcessFromEvent (const SBEvent &event) { - SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get())); - return process; + ProcessSP process_sp = + Process::ProcessEventData::GetProcessFromEvent (event.get()); + if (!process_sp) + { + // StructuredData events also know the process they come from. + // Try that. + process_sp = EventDataStructuredData::GetProcessFromEvent(event.get()); + } + + return SBProcess(process_sp); } bool @@ -1039,10 +1048,26 @@ SBProcess::GetInterruptedFromEvent (const SBEvent &event) return Process::ProcessEventData::GetInterruptedFromEvent(event.get()); } +lldb::SBStructuredData +SBProcess::GetStructuredDataFromEvent (const lldb::SBEvent &event) +{ + return SBStructuredData(event.GetSP()); +} + bool SBProcess::EventIsProcessEvent (const SBEvent &event) { - return event.GetBroadcasterClass() == SBProcess::GetBroadcasterClass(); + return (event.GetBroadcasterClass() == SBProcess::GetBroadcasterClass()) && + !EventIsStructuredDataEvent (event); +} + +bool +SBProcess::EventIsStructuredDataEvent (const lldb::SBEvent &event) +{ + EventSP event_sp = event.GetSP(); + EventData *event_data = event_sp ? event_sp->GetData() : nullptr; + return event_data && + (event_data->GetFlavor() == EventDataStructuredData::GetFlavorString()); } SBBroadcaster diff --git a/lldb/source/API/SBStructuredData.cpp b/lldb/source/API/SBStructuredData.cpp new file mode 100644 index 00000000000..5e4417484f0 --- /dev/null +++ b/lldb/source/API/SBStructuredData.cpp @@ -0,0 +1,165 @@ +//===-- SBStructuredData.cpp ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/API/SBStructuredData.h" + +#include "lldb/API/SBStream.h" +#include "lldb/Core/Error.h" +#include "lldb/Core/Event.h" +#include "lldb/Core/Stream.h" +#include "lldb/Core/StructuredData.h" +#include "lldb/Target/StructuredDataPlugin.h" + +using namespace lldb; +using namespace lldb_private; + +#pragma mark -- +#pragma mark Impl + +class SBStructuredData::Impl +{ +public: + + Impl() : + m_plugin_wp(), + m_data_sp() + { + } + + Impl(const Impl &rhs) = default; + + Impl(const EventSP &event_sp) : + m_plugin_wp(EventDataStructuredData::GetPluginFromEvent(event_sp.get())), + m_data_sp(EventDataStructuredData::GetObjectFromEvent(event_sp.get())) + { + } + + ~Impl() = default; + + Impl& + operator =(const Impl &rhs) = default; + + bool + IsValid() const + { + return m_data_sp.get() != nullptr; + } + + void + Clear() + { + m_plugin_wp.reset(); + m_data_sp.reset(); + } + + SBError + GetAsJSON(lldb::SBStream &stream) const + { + SBError sb_error; + + if (!m_data_sp) + { + sb_error.SetErrorString("No structured data."); + return sb_error; + } + + m_data_sp->Dump(stream.ref()); + return sb_error; + } + + lldb::SBError + GetDescription(lldb::SBStream &stream) const + { + SBError sb_error; + + if (!m_data_sp) + { + sb_error.SetErrorString("Cannot pretty print structured data: " + "no data to print."); + return sb_error; + } + + // Grab the plugin. + auto plugin_sp = StructuredDataPluginSP(m_plugin_wp); + if (!plugin_sp) + { + sb_error.SetErrorString("Cannot pretty print structured data: " + "plugin doesn't exist."); + return sb_error; + } + + // Get the data's description. + auto error = plugin_sp->GetDescription(m_data_sp, stream.ref()); + if (!error.Success()) + sb_error.SetError(error); + + return sb_error; + } + +private: + + StructuredDataPluginWP m_plugin_wp; + StructuredData::ObjectSP m_data_sp; + +}; + +#pragma mark -- +#pragma mark SBStructuredData + + +SBStructuredData::SBStructuredData() : + m_impl_up(new Impl()) +{ +} + +SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs) : + m_impl_up(new Impl(*rhs.m_impl_up.get())) +{ +} + +SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp) : + m_impl_up(new Impl(event_sp)) +{ +} + +SBStructuredData::~SBStructuredData() +{ +} + +SBStructuredData & +SBStructuredData::operator =(const lldb::SBStructuredData &rhs) +{ + *m_impl_up = *rhs.m_impl_up; + return *this; +} + +bool +SBStructuredData::IsValid() const +{ + return m_impl_up->IsValid(); +} + +void +SBStructuredData::Clear() +{ + m_impl_up->Clear(); +} + +SBError +SBStructuredData::GetAsJSON(lldb::SBStream &stream) const +{ + return m_impl_up->GetAsJSON(stream); +} + +lldb::SBError +SBStructuredData::GetDescription(lldb::SBStream &stream) const +{ + return m_impl_up->GetDescription(stream); +} + diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp index 8644757229c..00cbb5dee75 100644 --- a/lldb/source/API/SystemInitializerFull.cpp +++ b/lldb/source/API/SystemInitializerFull.cpp @@ -100,6 +100,7 @@ #include "Plugins/Process/mach-core/ProcessMachCore.h" #include "Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.h" #endif +#include "Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h" #if defined(__FreeBSD__) #include "Plugins/Process/FreeBSD/ProcessFreeBSD.h" @@ -381,6 +382,11 @@ SystemInitializerFull::Initialize() PlatformRemoteAppleWatch::Initialize(); DynamicLoaderDarwinKernel::Initialize(); #endif + + // This plugin is valid on any host that talks to a Darwin remote. + // It shouldn't be limited to __APPLE__. + StructuredDataDarwinLog::Initialize(); + //---------------------------------------------------------------------- // Platform agnostic plugins //---------------------------------------------------------------------- @@ -513,6 +519,8 @@ SystemInitializerFull::Terminate() platform_gdb_server::PlatformRemoteGDBServer::Terminate(); process_gdb_remote::ProcessGDBRemote::Terminate(); + StructuredDataDarwinLog::Terminate(); + DynamicLoaderMacOSXDYLD::Terminate(); DynamicLoaderMacOS::Terminate(); DynamicLoaderPOSIXDYLD::Terminate(); |