Skip to content

Commit 8a6f156

Browse files
authored
Merge pull request #1787 from medismailben/apple/stable/20200714
[lldb/API] Add Breakpoint::SerializeToStructuredData to SBAPI
2 parents c1420c4 + 202c0f3 commit 8a6f156

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

lldb/bindings/interface/SBBreakpoint.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public:
234234
SBError
235235
AddLocation(SBAddress &address);
236236

237+
SBStructuredData SBBreakpoint::SerializeToStructuredData();
238+
237239
static bool
238240
EventIsBreakpointEvent (const lldb::SBEvent &event);
239241

lldb/include/lldb/API/SBBreakpoint.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ class LLDB_API SBBreakpoint {
140140
// Can only be called from a ScriptedBreakpointResolver...
141141
SBError
142142
AddLocation(SBAddress &address);
143-
143+
144+
SBStructuredData SerializeToStructuredData();
145+
144146
private:
145147
friend class SBBreakpointList;
146148
friend class SBBreakpointLocation;

lldb/source/API/SBBreakpoint.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,22 @@ SBError SBBreakpoint::AddLocation(SBAddress &address) {
575575
return LLDB_RECORD_RESULT(error);
576576
}
577577

578-
void SBBreakpoint ::SetCallback(SBBreakpointHitCallback callback, void *baton) {
578+
SBStructuredData SBBreakpoint::SerializeToStructuredData() {
579+
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBStructuredData, SBBreakpoint,
580+
SerializeToStructuredData);
581+
582+
SBStructuredData data;
583+
BreakpointSP bkpt_sp = GetSP();
584+
585+
if (!bkpt_sp)
586+
return LLDB_RECORD_RESULT(data);
587+
588+
StructuredData::ObjectSP bkpt_dict = bkpt_sp->SerializeToStructuredData();
589+
data.m_impl_up->SetObjectSP(bkpt_dict);
590+
return LLDB_RECORD_RESULT(data);
591+
}
592+
593+
void SBBreakpoint::SetCallback(SBBreakpointHitCallback callback, void *baton) {
579594
LLDB_RECORD_DUMMY(void, SBBreakpoint, SetCallback,
580595
(lldb::SBBreakpointHitCallback, void *), callback, baton);
581596

@@ -1017,6 +1032,8 @@ void RegisterMethods<SBBreakpoint>(Registry &R) {
10171032
(lldb::SBStream &, bool));
10181033
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, AddLocation,
10191034
(lldb::SBAddress &));
1035+
LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBBreakpoint,
1036+
SerializeToStructuredData, ());
10201037
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
10211038
(const char *));
10221039
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackFunction,

lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import os
6+
import json
67
import lldb
78
from lldbsuite.test.decorators import *
89
from lldbsuite.test.lldbtest import *
@@ -56,6 +57,41 @@ def test_scripted_extra_args(self):
5657
self.setup_targets_and_cleanup()
5758
self.do_check_extra_args()
5859

60+
def test_structured_data_serialization(self):
61+
target = self.dbg.GetDummyTarget()
62+
self.assertTrue(target.IsValid(), VALID_TARGET)
63+
64+
interpreter = self.dbg.GetCommandInterpreter()
65+
result = lldb.SBCommandReturnObject()
66+
interpreter.HandleCommand("br set -f foo -l 42", result)
67+
result = lldb.SBCommandReturnObject()
68+
interpreter.HandleCommand("br set -c 'argc == 1' -n main", result)
69+
70+
bkp1 = target.GetBreakpointAtIndex(0)
71+
self.assertTrue(bkp1.IsValid(), VALID_BREAKPOINT)
72+
stream = lldb.SBStream()
73+
sd = bkp1.SerializeToStructuredData()
74+
sd.GetAsJSON(stream)
75+
serialized_data = json.loads(stream.GetData())
76+
self.assertEqual(serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["FileName"], "foo")
77+
self.assertEqual(serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["LineNumber"], 42)
78+
79+
bkp2 = target.GetBreakpointAtIndex(1)
80+
self.assertTrue(bkp2.IsValid(), VALID_BREAKPOINT)
81+
stream = lldb.SBStream()
82+
sd = bkp2.SerializeToStructuredData()
83+
sd.GetAsJSON(stream)
84+
serialized_data = json.loads(stream.GetData())
85+
self.assertIn("main", serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["SymbolNames"])
86+
self.assertEqual(serialized_data["Breakpoint"]["BKPTOptions"]["ConditionText"],"argc == 1")
87+
88+
invalid_bkp = lldb.SBBreakpoint()
89+
self.assertFalse(invalid_bkp.IsValid(), "Breakpoint should not be valid.")
90+
stream = lldb.SBStream()
91+
sd = invalid_bkp.SerializeToStructuredData()
92+
sd.GetAsJSON(stream)
93+
self.assertFalse(stream.GetData(), "Invalid breakpoint should have an empty structured data")
94+
5995
def setup_targets_and_cleanup(self):
6096
def cleanup ():
6197
self.RemoveTempFile(self.bkpts_file_path)

0 commit comments

Comments
 (0)