[Lldb-commits] [PATCH] D127458: [lldb][bindings] Implement __repr__ instead of __str__

Dave Lee via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 10 10:49:48 PDT 2022


kastiglione updated this revision to Diff 435972.
kastiglione added a comment.

add test/API/sanity/TestReprStrEquality.py


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127458/new/

https://reviews.llvm.org/D127458

Files:
  lldb/bindings/macros.swig
  lldb/test/API/sanity/TestReprStrEquality.py


Index: lldb/test/API/sanity/TestReprStrEquality.py
===================================================================
--- /dev/null
+++ lldb/test/API/sanity/TestReprStrEquality.py
@@ -0,0 +1,18 @@
+"""
+This is a sanity check that verifies that `repr(sbobject)` and `str(sbobject)`
+produce the same string.
+"""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+
+class TestCase(TestBase):
+
+  mydir = TestBase.compute_mydir(__file__)
+
+  NO_DEBUG_INFO_TESTCASE = True
+
+  def test(self):
+    self.assertEqual(repr(self.dbg), str(self.dbg))
Index: lldb/bindings/macros.swig
===================================================================
--- lldb/bindings/macros.swig
+++ lldb/bindings/macros.swig
@@ -1,6 +1,6 @@
 %define STRING_EXTENSION_LEVEL(Class, Level)
 %extend {
-  std::string lldb:: ## Class ## ::__str__(){
+  std::string lldb:: ## Class ## ::__repr__(){
     lldb::SBStream stream;
     $self->GetDescription (stream, Level);
     const char *desc = stream.GetData();
@@ -15,7 +15,7 @@
 
 %define STRING_EXTENSION(Class)
 %extend {
-  std::string lldb:: ## Class ## ::__str__(){
+  std::string lldb:: ## Class ## ::__repr__(){
     lldb::SBStream stream;
     $self->GetDescription (stream);
     const char *desc = stream.GetData();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127458.435972.patch
Type: text/x-patch
Size: 1265 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220610/8b8bd87b/attachment.bin>


More information about the lldb-commits mailing list