[Lldb-commits] [PATCH] D150313: Fix libstdc++ data formatter for reference/pointer to std::string

jeffrey tan via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri May 12 10:10:24 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG25159ee3af5c: Fix libstdc++ data formatter for reference/pointer to std::string (authored by yinghuitan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150313

Files:
  lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
  lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
  lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp


Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
@@ -10,6 +10,8 @@
     std::string q("hello world");
     std::string Q("quite a long std::strin with lots of info inside it");
     std::basic_string<unsigned char> uchar(5, 'a');
+    auto &rq = q, &rQ = Q;
+    std::string *pq = &q, *pQ = &Q;
     S.assign(L"!!!!!"); // Set break point at this line.
     return 0;
 }
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
@@ -57,6 +57,11 @@
         var_empty = self.frame().FindVariable('empty')
         var_q = self.frame().FindVariable('q')
         var_Q = self.frame().FindVariable('Q')
+        var_rq = self.frame().FindVariable('rq')
+        var_rQ = self.frame().FindVariable('rQ')
+        var_pq = self.frame().FindVariable('pq')
+        var_pQ = self.frame().FindVariable('pQ')
+
         var_uchar = self.frame().FindVariable('uchar')
 
         self.assertEqual(var_wempty.GetSummary(), 'L""', "wempty summary wrong")
@@ -75,6 +80,18 @@
             var_Q.GetSummary(), '"quite a long std::strin with lots of info inside it"',
             "Q summary wrong")
         self.assertEqual(var_uchar.GetSummary(), '"aaaaa"', "u summary wrong")
+        self.assertEqual(
+            var_rq.GetSummary(), '"hello world"',
+            "rq summary wrong")
+        self.assertEqual(
+            var_rQ.GetSummary(), '"quite a long std::strin with lots of info inside it"',
+            "rQ summary wrong")
+        self.assertEqual(
+            var_pq.GetSummary(), '"hello world"',
+            "pq summary wrong")
+        self.assertEqual(
+            var_pQ.GetSummary(), '"quite a long std::strin with lots of info inside it"',
+            "pQ summary wrong")
 
         self.runCmd("next")
 
Index: lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -233,8 +233,15 @@
     ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
   const bool scalar_is_load_addr = true;
   AddressType addr_type;
-  lldb::addr_t addr_of_string =
-      valobj.GetAddressOf(scalar_is_load_addr, &addr_type);
+  lldb::addr_t addr_of_string = LLDB_INVALID_ADDRESS;
+  if (valobj.IsPointerOrReferenceType()) {
+    Status error;
+    ValueObjectSP pointee_sp = valobj.Dereference(error);
+    if (pointee_sp && error.Success())
+      addr_of_string = pointee_sp->GetAddressOf(scalar_is_load_addr, &addr_type);
+  } else
+    addr_of_string =
+        valobj.GetAddressOf(scalar_is_load_addr, &addr_type);
   if (addr_of_string != LLDB_INVALID_ADDRESS) {
     switch (addr_type) {
     case eAddressTypeLoad: {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150313.521701.patch
Type: text/x-patch
Size: 3386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230512/8ca693e5/attachment.bin>


More information about the lldb-commits mailing list