[Lldb-commits] [lldb] r249503 - Introduce a variant of GetSummaryAsCString() that takes a LanguageType argument, and use it when crafting summaries by running selectors

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 6 18:41:23 PDT 2015


Author: enrico
Date: Tue Oct  6 20:41:23 2015
New Revision: 249503

URL: http://llvm.org/viewvc/llvm-project?rev=249503&view=rev
Log:
Introduce a variant of GetSummaryAsCString() that takes a LanguageType argument, and use it when crafting summaries by running selectors

This is the first in a series of commits that are meant to teach LLDB how to properly handle multi-language formatting of values


Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/DataFormatters/FormattersHelpers.cpp
    lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=249503&r1=249502&r2=249503&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Tue Oct  6 20:41:23 2015
@@ -610,11 +610,12 @@ public:
     GetLocationAsCString ();
 
     const char *
-    GetSummaryAsCString ();
+    GetSummaryAsCString (lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
     
     bool
     GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
-                         std::string& destination);
+                         std::string& destination,
+                         lldb::LanguageType lang = lldb::eLanguageTypeUnknown);
     
     bool
     GetSummaryAsCString (std::string& destination,

Modified: lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h?rev=249503&r1=249502&r2=249503&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h Tue Oct  6 20:41:23 2015
@@ -89,7 +89,8 @@ namespace lldb_private {
         ExtractSummaryFromObjCExpression (ValueObject &valobj,
                                           const char* target_type,
                                           const char* selector,
-                                          Stream &stream);
+                                          Stream &stream,
+                                          lldb::LanguageType lang_type);
         
         lldb::ValueObjectSP
         CallSelectorOnObject (ValueObject &valobj,

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=249503&r1=249502&r2=249503&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Tue Oct  6 20:41:23 2015
@@ -874,9 +874,10 @@ ValueObject::CreateChildAtIndex (size_t
 
 bool
 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
-                                  std::string& destination)
+                                  std::string& destination,
+                                  lldb::LanguageType lang)
 {
-    return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
+    return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
 }
 
 bool
@@ -885,7 +886,7 @@ ValueObject::GetSummaryAsCString (TypeSu
                                   const TypeSummaryOptions& options)
 {
     destination.clear();
-
+    
     // ideally we would like to bail out if passing NULL, but if we do so
     // we end up not providing the summary for function pointers anymore
     if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
@@ -893,31 +894,38 @@ ValueObject::GetSummaryAsCString (TypeSu
     
     m_is_getting_summary = true;
     
+    TypeSummaryOptions actual_options(options);
+    
+    if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
+        actual_options.SetLanguage(GetPreferredDisplayLanguage());
+    
     // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
     // information that we might care to see in a crash log. might be useful in very specific situations though.
     /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
-                                        GetTypeName().GetCString(),
-                                        GetName().GetCString(),
-                                        summary_ptr->GetDescription().c_str());*/
+     GetTypeName().GetCString(),
+     GetName().GetCString(),
+     summary_ptr->GetDescription().c_str());*/
     
     if (UpdateValueIfNeeded (false) && summary_ptr)
     {
         if (HasSyntheticValue())
             m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
-        summary_ptr->FormatObject(this, destination, options);
+        summary_ptr->FormatObject(this, destination, actual_options);
     }
     m_is_getting_summary = false;
     return !destination.empty();
 }
 
 const char *
-ValueObject::GetSummaryAsCString ()
+ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
 {
     if (UpdateValueIfNeeded(true) && m_summary_str.empty())
     {
+        TypeSummaryOptions summary_options;
+        summary_options.SetLanguage(lang);
         GetSummaryAsCString(GetSummaryFormat().get(),
                             m_summary_str,
-                            TypeSummaryOptions());
+                            summary_options);
     }
     if (m_summary_str.empty())
         return NULL;
@@ -929,8 +937,8 @@ ValueObject::GetSummaryAsCString (std::s
                                   const TypeSummaryOptions& options)
 {
     return GetSummaryAsCString(GetSummaryFormat().get(),
-                        destination,
-                        options);
+                               destination,
+                               options);
 }
 
 bool

Modified: lldb/trunk/source/DataFormatters/FormattersHelpers.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormattersHelpers.cpp?rev=249503&r1=249502&r2=249503&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormattersHelpers.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormattersHelpers.cpp Tue Oct  6 20:41:23 2015
@@ -187,7 +187,8 @@ bool
 lldb_private::formatters::ExtractSummaryFromObjCExpression (ValueObject &valobj,
                                                             const char* target_type,
                                                             const char* selector,
-                                                            Stream &stream)
+                                                            Stream &stream,
+                                                            lldb::LanguageType lang_type)
 {
     if (!target_type || !*target_type)
         return false;
@@ -206,6 +207,8 @@ lldb_private::formatters::ExtractSummary
     options.SetCoerceToId(false);
     options.SetUnwindOnError(true);
     options.SetKeepInMemory(true);
+    options.SetLanguage(lldb::eLanguageTypeObjC_plus_plus);
+    options.SetResultIsInternal(true);
     options.SetUseDynamic(lldb::eDynamicCanRunTarget);
     
     target->EvaluateExpression(expr.GetData(),
@@ -214,7 +217,7 @@ lldb_private::formatters::ExtractSummary
                                options);
     if (!result_sp)
         return false;
-    stream.Printf("%s",result_sp->GetSummaryAsCString());
+    stream.Printf("%s",result_sp->GetSummaryAsCString(lang_type));
     return true;
 }
 

Modified: lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp?rev=249503&r1=249502&r2=249503&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp Tue Oct  6 20:41:23 2015
@@ -75,7 +75,7 @@ lldb_private::formatters::NSBundleSummar
     }
     // this is either an unknown subclass or an NSBundle that comes from [NSBundle mainBundle]
     // which is encoded differently and needs to be handled by running code
-    return ExtractSummaryFromObjCExpression(valobj, "NSString*", "bundlePath", stream);
+    return ExtractSummaryFromObjCExpression(valobj, "NSString*", "bundlePath", stream, options.GetLanguage());
 }
 
 bool
@@ -119,7 +119,7 @@ lldb_private::formatters::NSTimeZoneSumm
             return true;
         }
     }
-    return ExtractSummaryFromObjCExpression(valobj, "NSString*", "name", stream);
+    return ExtractSummaryFromObjCExpression(valobj, "NSString*", "name", stream, options.GetLanguage());
 }
 
 bool
@@ -165,7 +165,7 @@ lldb_private::formatters::NSNotification
     }
     // this is either an unknown subclass or an NSBundle that comes from [NSBundle mainBundle]
     // which is encoded differently and needs to be handled by running code
-    return ExtractSummaryFromObjCExpression(valobj, "NSString*", "name", stream);
+    return ExtractSummaryFromObjCExpression(valobj, "NSString*", "name", stream, options.GetLanguage());
 }
 
 bool
@@ -414,7 +414,7 @@ lldb_private::formatters::NSNumberSummar
     }
     else
     {
-        return ExtractSummaryFromObjCExpression(valobj, "NSString*", "stringValue", stream);
+        return ExtractSummaryFromObjCExpression(valobj, "NSString*", "stringValue", stream, options.GetLanguage());
     }
 }
 
@@ -478,7 +478,7 @@ lldb_private::formatters::NSURLSummaryPr
     }
     else
     {
-        return ExtractSummaryFromObjCExpression(valobj, "NSString*", "description", stream);
+        return ExtractSummaryFromObjCExpression(valobj, "NSString*", "description", stream, options.GetLanguage());
     }
     return false;
 }




More information about the lldb-commits mailing list