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

llvm-svn: 249503
This commit is contained in:
Enrico Granata 2015-10-07 01:41:23 +00:00
parent 4bc013e18c
commit 31fda9336c
5 changed files with 34 additions and 21 deletions

View File

@ -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,

View File

@ -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,

View File

@ -874,9 +874,10 @@ ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_
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 (TypeSummaryImpl* summary_ptr,
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 (TypeSummaryImpl* summary_ptr,
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::string& destination,
const TypeSummaryOptions& options)
{
return GetSummaryAsCString(GetSummaryFormat().get(),
destination,
options);
destination,
options);
}
bool

View File

@ -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::ExtractSummaryFromObjCExpression (ValueObject &valobj,
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::ExtractSummaryFromObjCExpression (ValueObject &valobj,
options);
if (!result_sp)
return false;
stream.Printf("%s",result_sp->GetSummaryAsCString());
stream.Printf("%s",result_sp->GetSummaryAsCString(lang_type));
return true;
}

View File

@ -75,7 +75,7 @@ lldb_private::formatters::NSBundleSummaryProvider (ValueObject& valobj, Stream&
}
// 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::NSTimeZoneSummaryProvider (ValueObject& valobj, Stream
return true;
}
}
return ExtractSummaryFromObjCExpression(valobj, "NSString*", "name", stream);
return ExtractSummaryFromObjCExpression(valobj, "NSString*", "name", stream, options.GetLanguage());
}
bool
@ -165,7 +165,7 @@ lldb_private::formatters::NSNotificationSummaryProvider (ValueObject& valobj, St
}
// 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::NSNumberSummaryProvider (ValueObject& valobj, Stream&
}
else
{
return ExtractSummaryFromObjCExpression(valobj, "NSString*", "stringValue", stream);
return ExtractSummaryFromObjCExpression(valobj, "NSString*", "stringValue", stream, options.GetLanguage());
}
}
@ -478,7 +478,7 @@ lldb_private::formatters::NSURLSummaryProvider (ValueObject& valobj, Stream& str
}
else
{
return ExtractSummaryFromObjCExpression(valobj, "NSString*", "description", stream);
return ExtractSummaryFromObjCExpression(valobj, "NSString*", "description", stream, options.GetLanguage());
}
return false;
}