Skip to content

[lldb/API] Add Breakpoint::SerializeToStructuredData to SBAPI #1787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/bindings/interface/SBBreakpoint.i
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public:
SBError
AddLocation(SBAddress &address);

SBStructuredData SBBreakpoint::SerializeToStructuredData();

static bool
EventIsBreakpointEvent (const lldb::SBEvent &event);

Expand Down
4 changes: 3 additions & 1 deletion lldb/include/lldb/API/SBBreakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ class LLDB_API SBBreakpoint {
// Can only be called from a ScriptedBreakpointResolver...
SBError
AddLocation(SBAddress &address);


SBStructuredData SerializeToStructuredData();

private:
friend class SBBreakpointList;
friend class SBBreakpointLocation;
Expand Down
19 changes: 18 additions & 1 deletion lldb/source/API/SBBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,22 @@ SBError SBBreakpoint::AddLocation(SBAddress &address) {
return LLDB_RECORD_RESULT(error);
}

void SBBreakpoint ::SetCallback(SBBreakpointHitCallback callback, void *baton) {
SBStructuredData SBBreakpoint::SerializeToStructuredData() {
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBStructuredData, SBBreakpoint,
SerializeToStructuredData);

SBStructuredData data;
BreakpointSP bkpt_sp = GetSP();

if (!bkpt_sp)
return LLDB_RECORD_RESULT(data);

StructuredData::ObjectSP bkpt_dict = bkpt_sp->SerializeToStructuredData();
data.m_impl_up->SetObjectSP(bkpt_dict);
return LLDB_RECORD_RESULT(data);
}

void SBBreakpoint::SetCallback(SBBreakpointHitCallback callback, void *baton) {
LLDB_RECORD_DUMMY(void, SBBreakpoint, SetCallback,
(lldb::SBBreakpointHitCallback, void *), callback, baton);

Expand Down Expand Up @@ -1017,6 +1032,8 @@ void RegisterMethods<SBBreakpoint>(Registry &R) {
(lldb::SBStream &, bool));
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, AddLocation,
(lldb::SBAddress &));
LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBBreakpoint,
SerializeToStructuredData, ());
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
(const char *));
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackFunction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import json
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
Expand Down Expand Up @@ -56,6 +57,41 @@ def test_scripted_extra_args(self):
self.setup_targets_and_cleanup()
self.do_check_extra_args()

def test_structured_data_serialization(self):
target = self.dbg.GetDummyTarget()
self.assertTrue(target.IsValid(), VALID_TARGET)

interpreter = self.dbg.GetCommandInterpreter()
result = lldb.SBCommandReturnObject()
interpreter.HandleCommand("br set -f foo -l 42", result)
result = lldb.SBCommandReturnObject()
interpreter.HandleCommand("br set -c 'argc == 1' -n main", result)

bkp1 = target.GetBreakpointAtIndex(0)
self.assertTrue(bkp1.IsValid(), VALID_BREAKPOINT)
stream = lldb.SBStream()
sd = bkp1.SerializeToStructuredData()
sd.GetAsJSON(stream)
serialized_data = json.loads(stream.GetData())
self.assertEqual(serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["FileName"], "foo")
self.assertEqual(serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["LineNumber"], 42)

bkp2 = target.GetBreakpointAtIndex(1)
self.assertTrue(bkp2.IsValid(), VALID_BREAKPOINT)
stream = lldb.SBStream()
sd = bkp2.SerializeToStructuredData()
sd.GetAsJSON(stream)
serialized_data = json.loads(stream.GetData())
self.assertIn("main", serialized_data["Breakpoint"]["BKPTResolver"]["Options"]["SymbolNames"])
self.assertEqual(serialized_data["Breakpoint"]["BKPTOptions"]["ConditionText"],"argc == 1")

invalid_bkp = lldb.SBBreakpoint()
self.assertFalse(invalid_bkp.IsValid(), "Breakpoint should not be valid.")
stream = lldb.SBStream()
sd = invalid_bkp.SerializeToStructuredData()
sd.GetAsJSON(stream)
self.assertFalse(stream.GetData(), "Invalid breakpoint should have an empty structured data")

def setup_targets_and_cleanup(self):
def cleanup ():
self.RemoveTempFile(self.bkpts_file_path)
Expand Down