summaryrefslogtreecommitdiffstats
path: root/lldb/source/API
diff options
context:
space:
mode:
authorTodd Fiala <todd.fiala@gmail.com>2016-08-19 04:21:48 +0000
committerTodd Fiala <todd.fiala@gmail.com>2016-08-19 04:21:48 +0000
commit759300192abe8e38e8a40ab95934ba602a78c252 (patch)
treed284c51cf10c23d3023ab8e1308e26ad1ee218a7 /lldb/source/API
parente2ca3b65fcba7c4c5dbd10c1e8925177b7718806 (diff)
downloadbcm5719-llvm-759300192abe8e38e8a40ab95934ba602a78c252.tar.gz
bcm5719-llvm-759300192abe8e38e8a40ab95934ba602a78c252.zip
Add StructuredData plugin type; showcase with new DarwinLog feature
Take 2, with missing cmake line fixed. Build tested on Ubuntu 14.04 with clang-3.6. See docs/structured_data/StructuredDataPlugins.md for details. differential review: https://reviews.llvm.org/D22976 reviewers: clayborg, jingham llvm-svn: 279202
Diffstat (limited to 'lldb/source/API')
-rw-r--r--lldb/source/API/CMakeLists.txt1
-rw-r--r--lldb/source/API/SBDebugger.cpp2
-rw-r--r--lldb/source/API/SBProcess.cpp31
-rw-r--r--lldb/source/API/SBStructuredData.cpp165
-rw-r--r--lldb/source/API/SystemInitializerFull.cpp8
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();
OpenPOWER on IntegriCloud