[Lldb-commits] [lldb] 25159ee - Fix libstdc++ data formatter for reference/pointer to std::string

Jeffrey Tan via lldb-commits lldb-commits at lists.llvm.org
Fri May 12 10:10:13 PDT 2023


Author: Jeffrey Tan
Date: 2023-05-12T10:09:58-07:00
New Revision: 25159ee3af5cd1c05c010ea195b4b359df3fe820

URL: https://github.com/llvm/llvm-project/commit/25159ee3af5cd1c05c010ea195b4b359df3fe820
DIFF: https://github.com/llvm/llvm-project/commit/25159ee3af5cd1c05c010ea195b4b359df3fe820.diff

LOG: Fix libstdc++ data formatter for reference/pointer to std::string

This patch fixes libstdc++ data formatter for reference/pointer to std::string.
The failure testcases are added which succeed with the patch.

Differential Revision: https://reviews.llvm.org/D150313

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
index 90976fa053b8a..c7f1c79422246 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -233,8 +233,15 @@ bool lldb_private::formatters::LibStdcppStringSummaryProvider(
     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: {

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
index 6ce7235ff015d..34d39ee3e6b09 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
@@ -57,6 +57,11 @@ def cleanup():
         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 @@ def cleanup():
             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")
 

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
index 73519197d8c1a..930f8c2afef21 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
@@ -10,6 +10,8 @@ int main()
     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;
 }


        


More information about the lldb-commits mailing list