summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/API/SBStructuredData.h1
-rw-r--r--lldb/include/lldb/API/SBTarget.h2
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/stats_api/Makefile3
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/stats_api/TestStatisticsAPI.py28
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/stats_api/main.c3
-rw-r--r--lldb/scripts/interface/SBTarget.i2
-rw-r--r--lldb/source/API/SBTarget.cpp21
7 files changed, 60 insertions, 0 deletions
diff --git a/lldb/include/lldb/API/SBStructuredData.h b/lldb/include/lldb/API/SBStructuredData.h
index f3baaf7c480..ca8229a574d 100644
--- a/lldb/include/lldb/API/SBStructuredData.h
+++ b/lldb/include/lldb/API/SBStructuredData.h
@@ -99,6 +99,7 @@ public:
protected:
friend class SBTraceOptions;
friend class SBDebugger;
+ friend class SBTarget;
StructuredDataImplUP m_impl_up;
};
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 4085a16b43f..961a49bf7d6 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -75,6 +75,8 @@ public:
lldb::SBProcess GetProcess();
+ lldb::SBStructuredData GetStatistics();
+
//------------------------------------------------------------------
/// Return the platform object associated with the target.
///
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/Makefile
new file mode 100644
index 00000000000..f5a47fcc46c
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/Makefile
@@ -0,0 +1,3 @@
+LEVEL = ../../make
+C_SOURCES := main.c
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/TestStatisticsAPI.py b/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/TestStatisticsAPI.py
new file mode 100644
index 00000000000..e3e1cba3aec
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/TestStatisticsAPI.py
@@ -0,0 +1,28 @@
+# Test the SBAPI for GetStatistics()
+
+import json
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestStatsAPI(TestBase):
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ TestBase.setUp(self)
+
+ def test_stats_api(self):
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ target = self.dbg.CreateTarget(exe)
+ stats = target.GetStatistics()
+ stream = lldb.SBStream()
+ res = stats.GetAsJSON(stream)
+ stats_json = sorted(json.loads(stream.GetData()))
+ self.assertEqual(len(stats_json), 4)
+ self.assertEqual(stats_json[0], "Number of expr evaluation failures")
+ self.assertEqual(stats_json[1], "Number of expr evaluation successes")
+ self.assertEqual(stats_json[2], "Number of frame var failures")
+ self.assertEqual(stats_json[3], "Number of frame var successes")
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/main.c
new file mode 100644
index 00000000000..03b2213bb9a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/stats_api/main.c
@@ -0,0 +1,3 @@
+int main(void) {
+ return 0;
+}
diff --git a/lldb/scripts/interface/SBTarget.i b/lldb/scripts/interface/SBTarget.i
index bcec606005f..9ca5c10ecca 100644
--- a/lldb/scripts/interface/SBTarget.i
+++ b/lldb/scripts/interface/SBTarget.i
@@ -915,6 +915,8 @@ public:
void
SetLaunchInfo (const lldb::SBLaunchInfo &launch_info);
+ lldb::SBStructuredData GetStatistics();
+
bool
operator == (const lldb::SBTarget &rhs) const;
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 878f6edd5ca..e1cc6538bdf 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -23,6 +23,7 @@
#include "lldb/API/SBSourceManager.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
+#include "lldb/API/SBStructuredData.h"
#include "lldb/API/SBSymbolContextList.h"
#include "lldb/Breakpoint/BreakpointID.h"
#include "lldb/Breakpoint/BreakpointIDList.h"
@@ -38,6 +39,7 @@
#include "lldb/Core/STLUtils.h"
#include "lldb/Core/SearchFilter.h"
#include "lldb/Core/Section.h"
+#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Core/ValueObjectConstResult.h"
#include "lldb/Core/ValueObjectList.h"
#include "lldb/Core/ValueObjectVariable.h"
@@ -181,6 +183,25 @@ SBDebugger SBTarget::GetDebugger() const {
return debugger;
}
+SBStructuredData SBTarget::GetStatistics() {
+ SBStructuredData data;
+ TargetSP target_sp(GetSP());
+ if (!target_sp)
+ return data;
+
+ auto stats_up = llvm::make_unique<StructuredData::Dictionary>();
+ int i = 0;
+ for (auto &Entry : target_sp->GetStatistics()) {
+ std::string Desc = lldb_private::GetStatDescription(
+ static_cast<lldb_private::StatisticKind>(i));
+ stats_up->AddIntegerItem(Desc, Entry);
+ i += 1;
+ }
+
+ data.m_impl_up->SetObjectSP(std::move(stats_up));
+ return data;
+}
+
SBProcess SBTarget::LoadCore(const char *core_file) {
SBProcess sb_process;
TargetSP target_sp(GetSP());
OpenPOWER on IntegriCloud