Skip to content
Open
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
118 changes: 115 additions & 3 deletions examples/main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,127 @@
#include <QByteArray>
#include <QDate>
#include <QHash>
#include <QLine>
#include <QLinkedList>
#include <QList>
#include <QMap>
#include <QPoint>
#include <QRect>
#include <QSet>
#include <QSize>
#include <QString>
#include <QStringList>
#include <QTime>
#include <QUuid>
#include <QVariant>
#include <QVector>
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonArray>
#include <QPair>
#include <QVarLengthArray>

int main() {
// Existing
auto hello = QString("Hello World");
auto demosthenes = QString("Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι");
auto demosthenes = QString("Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι");

auto map = QMap<QString , uint32_t>{
auto map = QMap<QString, uint32_t>{
{"one", 1},
{"forty-two", 42},
{"1.21 gigawatts", 1210000}
};

// QByteArray
auto byteArray = QByteArray("Hello Bytes");

// Geometry
auto point = QPoint(10, 20);
auto pointF = QPointF(1.5, 2.5);
auto size = QSize(800, 600);
auto sizeF = QSizeF(12.5, 34.75);
auto rect = QRect(0, 0, 99, 49);
auto rectF = QRectF(1.0, 2.0, 100.5, 50.25);
auto line = QLine(QPoint(0, 0), QPoint(10, 20));
auto lineF = QLineF(QPointF(0.0, 0.0), QPointF(10.5, 20.5));

// Date/Time
auto date = QDate(2024, 1, 15);
auto time = QTime(14, 30, 25, 123);

// QVector
auto vec = QVector<int>{1, 2, 3, 4, 5};

// QList
auto list = QList<QString>{"alpha", "beta", "gamma"};
auto stringList = QStringList{"one", "two", "three"};

// QHash
auto hash = QHash<QString, int>{{"one", 1}, {"two", 2}, {"three", 3}};

// QSet
auto set = QSet<int>{10, 20, 30};

// QLinkedList
auto linkedList = QLinkedList<int>{100, 200, 300};

// QVariant
auto variantInt = QVariant(42);
auto variantStr = QVariant(QString("variant string"));
auto variantBool = QVariant(true);
auto variantDouble = QVariant(3.14);

// QPair
auto pair = QPair<int, QString>(1, "hello");

// QUuid
auto uuid = QUuid("{67c8770b-44f1-410a-ab9a-f9b5446f13ee}");

// QVarLengthArray
auto varArray = QVarLengthArray<int, 16>{7, 8, 9};

// QChar
auto ch = QChar('A');

// QJsonValue
auto jsonNull = QJsonValue();
auto jsonBool = QJsonValue(true);
auto jsonDouble = QJsonValue(3.14);
auto jsonString = QJsonValue(QString("hello json"));

// QJsonObject
auto jsonObj = QJsonObject{{"name", "test"}, {"value", 42}};

// QJsonArray
auto jsonArr = QJsonArray{1, 2, 3};

// Nested: QJsonObject containing QJsonArray and QJsonObject
auto jsonNested = QJsonObject{
{"title", "nested test"},
{"tags", QJsonArray{"alpha", "beta", "gamma"}},
{"metadata", QJsonObject{{"version", 2}, {"draft", true}}},
{"score", 9.5}
};

// Nested: QJsonArray containing mixed types including objects and arrays
auto jsonMixed = QJsonArray{
42,
"hello",
true,
QJsonValue(),
QJsonObject{{"x", 1}, {"y", 2}},
QJsonArray{10, 20, 30}
};

// Deep nesting: 3 levels
auto jsonDeep = QJsonObject{
{"level1", QJsonObject{
{"level2", QJsonObject{
{"level3", "deep value"}
}}
}}
};

return 0;
}
}

85 changes: 84 additions & 1 deletion lldb_qt_formatters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,97 @@
# We need to import the formatters like this - no other method will work
from .qstring import *
from .qmap import *
from .qbytearray import *
from .geometry import *
from .datetime import *
from .qvector import *
from .qlist import *
from .qhash import *
from .qlinkedlist import *
from .qvariant import *
from .misc import *
from .qjson import *


def __lldb_init_module(debugger, internal_dict):
init_commands = [
# === Existing: QString, QMap ===
'type summary add --python-function lldb_qt_formatters.qstring.format_summary "QString"',
'type summary add --summary-string "\{${var.key}: ${var.value}\}" -x "QMapNode<.+>$"', # noqa: W605
'type synthetic add --python-class lldb_qt_formatters.qmap.SyntheticChildrenProvider -x "QMap<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qmap.format_summary -x "QMap<.+>$"'
'type summary add --expand --python-function lldb_qt_formatters.qmap.format_summary -x "QMap<.+>$"',

# === QByteArray ===
'type summary add --python-function lldb_qt_formatters.qbytearray.format_summary "QByteArray"',

# === Geometry types ===
'type summary add --python-function lldb_qt_formatters.geometry.format_qpoint_summary "QPoint"',
'type summary add --python-function lldb_qt_formatters.geometry.format_qpoint_summary "QPointF"',
'type summary add --python-function lldb_qt_formatters.geometry.format_qsize_summary "QSize"',
'type summary add --python-function lldb_qt_formatters.geometry.format_qsize_summary "QSizeF"',
'type summary add --python-function lldb_qt_formatters.geometry.format_qrect_summary "QRect"',
'type summary add --python-function lldb_qt_formatters.geometry.format_qrectf_summary "QRectF"',
'type summary add --python-function lldb_qt_formatters.geometry.format_qline_summary "QLine"',
'type summary add --python-function lldb_qt_formatters.geometry.format_qline_summary "QLineF"',

# === Date/Time ===
'type summary add --python-function lldb_qt_formatters.datetime.format_qdate_summary "QDate"',
'type summary add --python-function lldb_qt_formatters.datetime.format_qtime_summary "QTime"',

# === QVector / QStack ===
'type synthetic add --python-class lldb_qt_formatters.qvector.SyntheticChildrenProvider -x "QVector<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qvector.format_summary -x "QVector<.+>$"',
'type synthetic add --python-class lldb_qt_formatters.qvector.SyntheticChildrenProvider -x "QStack<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qvector.format_summary -x "QStack<.+>$"',

# === QList / QQueue / QStringList ===
'type synthetic add --python-class lldb_qt_formatters.qlist.SyntheticChildrenProvider -x "QList<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qlist.format_summary -x "QList<.+>$"',
'type synthetic add --python-class lldb_qt_formatters.qlist.SyntheticChildrenProvider -x "QQueue<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qlist.format_summary -x "QQueue<.+>$"',
'type synthetic add --python-class lldb_qt_formatters.qlist.SyntheticChildrenProvider "QStringList"',
'type summary add --expand --python-function lldb_qt_formatters.qlist.format_summary "QStringList"',

# === QHash / QMultiHash ===
'type summary add --summary-string "\{${var.key}: ${var.value}\}" -x "QHashNode<.+>$"', # noqa: W605
'type synthetic add --python-class lldb_qt_formatters.qhash.SyntheticChildrenProvider -x "QHash<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qhash.format_summary -x "QHash<.+>$"',
'type synthetic add --python-class lldb_qt_formatters.qhash.SyntheticChildrenProvider -x "QMultiHash<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qhash.format_summary -x "QMultiHash<.+>$"',

# === QSet ===
'type synthetic add --python-class lldb_qt_formatters.qhash.QSetSyntheticChildrenProvider -x "QSet<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qhash.format_set_summary -x "QSet<.+>$"',

# === QLinkedList ===
'type synthetic add --python-class lldb_qt_formatters.qlinkedlist.SyntheticChildrenProvider -x "QLinkedList<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.qlinkedlist.format_summary -x "QLinkedList<.+>$"',

# === QVariant ===
'type summary add --python-function lldb_qt_formatters.qvariant.format_summary "QVariant"',

# === Miscellaneous types ===
'type summary add --python-function lldb_qt_formatters.misc.format_qchar_summary "QChar"',
'type summary add --python-function lldb_qt_formatters.misc.format_qpair_summary -x "QPair<.+>$"',
'type summary add --python-function lldb_qt_formatters.misc.format_quuid_summary "QUuid"',

# === QVarLengthArray ===
'type synthetic add --python-class lldb_qt_formatters.misc.QVarLengthArraySyntheticProvider -x "QVarLengthArray<.+>$"',
'type summary add --expand --python-function lldb_qt_formatters.misc.format_qvarlengtharray_summary -x "QVarLengthArray<.+>$"',

# === Smart pointers ===
'type summary add --python-function lldb_qt_formatters.misc.format_qsharedpointer_summary -x "QSharedPointer<.+>$"',
'type summary add --python-function lldb_qt_formatters.misc.format_qweakpointer_summary -x "QWeakPointer<.+>$"',
'type summary add --python-function lldb_qt_formatters.misc.format_qscopedpointer_summary -x "QScopedPointer<.+>$"',
'type summary add --python-function lldb_qt_formatters.misc.format_qpointer_summary -x "QPointer<.+>$"',

# === QJson types ===
'type synthetic add --python-class lldb_qt_formatters.qjson.QJsonValueSyntheticProvider "QJsonValue"',
'type summary add --expand --python-function lldb_qt_formatters.qjson.format_jsonvalue_summary "QJsonValue"',
'type synthetic add --python-class lldb_qt_formatters.qjson.QJsonObjectSyntheticProvider "QJsonObject"',
'type summary add --expand --python-function lldb_qt_formatters.qjson.format_jsonobject_summary "QJsonObject"',
'type synthetic add --python-class lldb_qt_formatters.qjson.QJsonArraySyntheticProvider "QJsonArray"',
'type summary add --expand --python-function lldb_qt_formatters.qjson.format_jsonarray_summary "QJsonArray"',
]
for command in init_commands:
debugger.HandleCommand(command)
31 changes: 31 additions & 0 deletions lldb_qt_formatters/datetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from lldb import SBValue


def format_qdate_summary(valobj: SBValue, internal_dict, options):
jd = valobj.GetChildMemberWithName("jd").GetValueAsSigned()
if jd < 0:
return "Invalid"

# Julian Day Number to Gregorian calendar conversion
a = jd + 32044
b = (4 * a + 3) // 146097
c = a - (146097 * b) // 4
d = (4 * c + 3) // 1461
e = c - (1461 * d) // 4
m = (5 * e + 2) // 153
day = e - (153 * m + 2) // 5 + 1
month = m + 3 - 12 * (m // 10)
year = 100 * b + d - 4800 + m // 10
return f"{year:04d}-{month:02d}-{day:02d}"


def format_qtime_summary(valobj: SBValue, internal_dict, options):
mds = valobj.GetChildMemberWithName("mds").GetValueAsSigned()
if mds < 0:
return "Invalid"

hours = mds // 3600000
minutes = (mds % 3600000) // 60000
seconds = (mds // 1000) % 60
ms = mds % 1000
return f"{hours:02d}:{minutes:02d}:{seconds:02d}.{ms:03d}"
43 changes: 43 additions & 0 deletions lldb_qt_formatters/geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from lldb import SBValue


def format_qpoint_summary(valobj: SBValue, internal_dict, options):
x = valobj.GetChildMemberWithName("xp")
y = valobj.GetChildMemberWithName("yp")
return f"{{ x = {x.GetValue()}, y = {y.GetValue()} }}"


def format_qsize_summary(valobj: SBValue, internal_dict, options):
w = valobj.GetChildMemberWithName("wd")
h = valobj.GetChildMemberWithName("ht")
return f"{{ width = {w.GetValue()}, height = {h.GetValue()} }}"


def format_qrect_summary(valobj: SBValue, internal_dict, options):
x1 = valobj.GetChildMemberWithName("x1").GetValueAsSigned()
y1 = valobj.GetChildMemberWithName("y1").GetValueAsSigned()
x2 = valobj.GetChildMemberWithName("x2").GetValueAsSigned()
y2 = valobj.GetChildMemberWithName("y2").GetValueAsSigned()
width = x2 - x1 + 1
height = y2 - y1 + 1
return f"{{ x = {x1}, y = {y1}, width = {width}, height = {height} }}"


def format_qrectf_summary(valobj: SBValue, internal_dict, options):
x = valobj.GetChildMemberWithName("xp")
y = valobj.GetChildMemberWithName("yp")
w = valobj.GetChildMemberWithName("w")
h = valobj.GetChildMemberWithName("h")
return f"{{ x = {x.GetValue()}, y = {y.GetValue()}, width = {w.GetValue()}, height = {h.GetValue()} }}"


def _format_point(pt: SBValue):
x = pt.GetChildMemberWithName("xp")
y = pt.GetChildMemberWithName("yp")
return f"({x.GetValue()}, {y.GetValue()})"


def format_qline_summary(valobj: SBValue, internal_dict, options):
pt1 = valobj.GetChildMemberWithName("pt1")
pt2 = valobj.GetChildMemberWithName("pt2")
return f"{{ start = {_format_point(pt1)}, end = {_format_point(pt2)} }}"
Loading