diff options
author | Enrico Granata <granata.enrico@gmail.com> | 2011-08-17 22:13:59 +0000 |
---|---|---|
committer | Enrico Granata <granata.enrico@gmail.com> | 2011-08-17 22:13:59 +0000 |
commit | c482a1929490ca2bcba5060d99a06b06bf3edac9 (patch) | |
tree | b8a3e3d862f8cd3c068c386449e2fb032bd3ae0e /lldb/source/Core/FormatManager.cpp | |
parent | 1a87fcb9ba5189dc1702140eb3e152d6aa1d66e5 (diff) | |
download | bcm5719-llvm-c482a1929490ca2bcba5060d99a06b06bf3edac9.tar.gz bcm5719-llvm-c482a1929490ca2bcba5060d99a06b06bf3edac9.zip |
First round of code cleanups:
- all instances of "vobj" have been renamed to "valobj"
- class Debugger::Formatting has been renamed to DataVisualization (defined in FormatManager.h/cpp)
The interface to this class has not changed
- FormatCategory now uses ConstString's as keys to the navigators instead of repeatedly casting
from ConstString to const char* and back all the time
Next step is making the same happen for categories themselves
- category gnu-libstdc++ is defined in the constructor for a FormatManager
The source code for it is defined in gnu_libstdcpp.py, drawn from examples/synthetic at compile time
All references to previous 'osxcpp' name have been removed from both code and file names
Functional changes:
- the name of the option to use a summary string for 'type summary add' has changed from the previous --format-string
to the new --summary-string. It is expected that the short option will change from -f to -s, and -s for --python-script
will become -o
llvm-svn: 137886
Diffstat (limited to 'lldb/source/Core/FormatManager.cpp')
-rw-r--r-- | lldb/source/Core/FormatManager.cpp | 307 |
1 files changed, 295 insertions, 12 deletions
diff --git a/lldb/source/Core/FormatManager.cpp b/lldb/source/Core/FormatManager.cpp index 2210e37f111..9cb15c77ee0 100644 --- a/lldb/source/Core/FormatManager.cpp +++ b/lldb/source/Core/FormatManager.cpp @@ -156,14 +156,14 @@ FormatManager::GetFormatAsCString (Format format) template<> bool -FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Get(const char* key, SummaryFormat::SharedPointer& value) +FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Get(ConstString key, SummaryFormat::SharedPointer& value) { Mutex::Locker(m_format_map.mutex()); MapIterator pos, end = m_format_map.map().end(); for (pos = m_format_map.map().begin(); pos != end; pos++) { lldb::RegularExpressionSP regex = pos->first; - if (regex->Execute(key)) + if (regex->Execute(key.AsCString())) { value = pos->second; return true; @@ -174,14 +174,14 @@ FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Get(const char* key, template<> bool -FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Delete(const char* type) +FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Delete(ConstString type) { Mutex::Locker(m_format_map.mutex()); MapIterator pos, end = m_format_map.map().end(); for (pos = m_format_map.map().begin(); pos != end; pos++) { lldb::RegularExpressionSP regex = pos->first; - if ( ::strcmp(type,regex->GetText()) == 0) + if ( ::strcmp(type.AsCString(),regex->GetText()) == 0) { m_format_map.map().erase(pos); if (m_format_map.listener) @@ -194,14 +194,14 @@ FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Delete(const char* ty template<> bool -FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Get(const char* key, SyntheticFilter::SharedPointer& value) +FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Get(ConstString key, SyntheticFilter::SharedPointer& value) { Mutex::Locker(m_format_map.mutex()); MapIterator pos, end = m_format_map.map().end(); for (pos = m_format_map.map().begin(); pos != end; pos++) { lldb::RegularExpressionSP regex = pos->first; - if (regex->Execute(key)) + if (regex->Execute(key.AsCString())) { value = pos->second; return true; @@ -212,14 +212,14 @@ FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Get(const char* key template<> bool -FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Delete(const char* type) +FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Delete(ConstString type) { Mutex::Locker(m_format_map.mutex()); MapIterator pos, end = m_format_map.map().end(); for (pos = m_format_map.map().begin(); pos != end; pos++) { lldb::RegularExpressionSP regex = pos->first; - if ( ::strcmp(type,regex->GetText()) == 0) + if ( ::strcmp(type.AsCString(),regex->GetText()) == 0) { m_format_map.map().erase(pos); if (m_format_map.listener) @@ -232,14 +232,14 @@ FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Delete(const char* template<> bool -FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Get(const char* key, SyntheticFilter::SharedPointer& value) +FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Get(ConstString key, SyntheticFilter::SharedPointer& value) { Mutex::Locker(m_format_map.mutex()); MapIterator pos, end = m_format_map.map().end(); for (pos = m_format_map.map().begin(); pos != end; pos++) { lldb::RegularExpressionSP regex = pos->first; - if (regex->Execute(key)) + if (regex->Execute(key.AsCString())) { value = pos->second; return true; @@ -250,14 +250,14 @@ FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Get(const c template<> bool -FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Delete(const char* type) +FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Delete(ConstString type) { Mutex::Locker(m_format_map.mutex()); MapIterator pos, end = m_format_map.map().end(); for (pos = m_format_map.map().begin(); pos != end; pos++) { lldb::RegularExpressionSP regex = pos->first; - if ( ::strcmp(type,regex->GetText()) == 0) + if ( ::strcmp(type.AsCString(),regex->GetText()) == 0) { m_format_map.map().erase(pos); if (m_format_map.listener) @@ -297,3 +297,286 @@ FormatManager::GetSingleItemFormat(lldb::Format vector_format) return lldb::eFormatInvalid; } } + +FormatManager::FormatManager() : + m_value_nav("format",this), + m_named_summaries_map(this), + m_last_revision(0), + m_categories_map(this), + m_default_cs(ConstString("default")), + m_system_cs(ConstString("system")), + m_gnu_stdcpp_cs(ConstString("gnu-libstdc++")) +{ + + // build default categories + + m_default_category_name = m_default_cs.GetCString(); + m_system_category_name = m_system_cs.GetCString(); + m_gnu_cpp_category_name = m_gnu_stdcpp_cs.AsCString(); + + // add some default stuff + // most formats, summaries, ... actually belong to the users' lldbinit file rather than here + SummaryFormat::SharedPointer string_format(new StringSummaryFormat(false, + true, + false, + true, + false, + false, + "${var%s}")); + + + SummaryFormat::SharedPointer string_array_format(new StringSummaryFormat(false, + true, + false, + false, + false, + false, + "${var%s}")); + + lldb::RegularExpressionSP any_size_char_arr(new RegularExpression("char \\[[0-9]+\\]")); + + + Category(m_system_category_name)->Summary()->Add(ConstString("char *"), string_format); + Category(m_system_category_name)->Summary()->Add(ConstString("const char *"), string_format); + Category(m_system_category_name)->RegexSummary()->Add(any_size_char_arr, string_array_format); + + Category(m_default_category_name); // this call is there to force LLDB into creating an empty "default" category + + // WARNING: temporary code!! + // The platform should be responsible for initializing its own formatters + // (e.g. to handle versioning, different runtime libraries, ...) + // Currently, basic formatters for std:: objects as implemented by + // the GNU libstdc++ are defined regardless, and enabled by default + // This is going to be moved to some platform-dependent location + // (in the meanwhile, these formatters should work for Mac OS X & Linux) + lldb::SummaryFormatSP std_string_summary_sp(new StringSummaryFormat(true, + false, + false, + true, + true, + false, + "${var._M_dataplus._M_p}")); + Category(m_gnu_cpp_category_name)->Summary()->Add(ConstString("std::string"), + std_string_summary_sp); + Category(m_gnu_cpp_category_name)->Summary()->Add(ConstString("std::basic_string<char>"), + std_string_summary_sp); + Category(m_gnu_cpp_category_name)->Summary()->Add(ConstString("std::basic_string<char,std::char_traits<char>,std::allocator<char> >"), + std_string_summary_sp); + + Category(m_gnu_cpp_category_name)->RegexSynth()->Add(RegularExpressionSP(new RegularExpression("std::vector<")), + SyntheticChildrenSP(new SyntheticScriptProvider(true, + false, + false, + "StdVectorSynthProvider"))); + Category(m_gnu_cpp_category_name)->RegexSynth()->Add(RegularExpressionSP(new RegularExpression("std::map<")), + SyntheticChildrenSP(new SyntheticScriptProvider(true, + false, + false, + "StdMapSynthProvider"))); + Category(m_gnu_cpp_category_name)->RegexSynth()->Add(RegularExpressionSP(new RegularExpression("std::list<")), + SyntheticChildrenSP(new SyntheticScriptProvider(true, + false, + false, + "StdListSynthProvider"))); + + // DO NOT change the order of these calls, unless you WANT a change in the priority of these categories + EnableCategory(m_system_category_name); + EnableCategory(m_gnu_cpp_category_name); + EnableCategory(m_default_category_name); + +} + + +static FormatManager& +GetFormatManager() { + static FormatManager g_format_manager; + return g_format_manager; +} + +void +DataVisualization::ForceUpdate() +{ + GetFormatManager().Changed(); +} + +bool +DataVisualization::ValueFormats::Get(ValueObject& valobj, lldb::DynamicValueType use_dynamic, ValueFormat::SharedPointer &entry) +{ + return GetFormatManager().Value().Get(valobj,entry, use_dynamic); +} + +void +DataVisualization::ValueFormats::Add(const ConstString &type, const ValueFormat::SharedPointer &entry) +{ + GetFormatManager().Value().Add(type,entry); +} + +bool +DataVisualization::ValueFormats::Delete(const ConstString &type) +{ + return GetFormatManager().Value().Delete(type); +} + +void +DataVisualization::ValueFormats::Clear() +{ + GetFormatManager().Value().Clear(); +} + +void +DataVisualization::ValueFormats::LoopThrough(ValueFormat::ValueCallback callback, void* callback_baton) +{ + GetFormatManager().Value().LoopThrough(callback, callback_baton); +} + +uint32_t +DataVisualization::ValueFormats::GetCurrentRevision() +{ + return GetFormatManager().GetCurrentRevision(); +} + +uint32_t +DataVisualization::ValueFormats::GetCount() +{ + return GetFormatManager().Value().GetCount(); +} + +bool +DataVisualization::GetSummaryFormat(ValueObject& valobj, + lldb::DynamicValueType use_dynamic, + lldb::SummaryFormatSP& entry) +{ + return GetFormatManager().Get(valobj, entry, use_dynamic); +} +bool +DataVisualization::GetSyntheticChildren(ValueObject& valobj, + lldb::DynamicValueType use_dynamic, + lldb::SyntheticChildrenSP& entry) +{ + return GetFormatManager().Get(valobj, entry, use_dynamic); +} + +bool +DataVisualization::AnyMatches(ConstString type_name, + FormatCategory::FormatCategoryItems items, + bool only_enabled, + const char** matching_category, + FormatCategory::FormatCategoryItems* matching_type) +{ + return GetFormatManager().AnyMatches(type_name, + items, + only_enabled, + matching_category, + matching_type); +} + +bool +DataVisualization::Categories::Get(const ConstString &category, lldb::FormatCategorySP &entry) +{ + entry = GetFormatManager().Category(category.GetCString()); + return true; +} + +void +DataVisualization::Categories::Add(const ConstString &category) +{ + GetFormatManager().Category(category.GetCString()); +} + +bool +DataVisualization::Categories::Delete(const ConstString &category) +{ + GetFormatManager().DisableCategory(category.GetCString()); + return GetFormatManager().Categories().Delete(category.GetCString()); +} + +void +DataVisualization::Categories::Clear() +{ + GetFormatManager().Categories().Clear(); +} + +void +DataVisualization::Categories::Clear(ConstString &category) +{ + GetFormatManager().Category(category.GetCString())->ClearSummaries(); +} + +void +DataVisualization::Categories::Enable(ConstString& category) +{ + if (GetFormatManager().Category(category.GetCString())->IsEnabled() == false) + GetFormatManager().EnableCategory(category.GetCString()); + else + { + GetFormatManager().DisableCategory(category.GetCString()); + GetFormatManager().EnableCategory(category.GetCString()); + } +} + +void +DataVisualization::Categories::Disable(ConstString& category) +{ + if (GetFormatManager().Category(category.GetCString())->IsEnabled() == true) + GetFormatManager().DisableCategory(category.GetCString()); +} + +void +DataVisualization::Categories::LoopThrough(FormatManager::CategoryCallback callback, void* callback_baton) +{ + GetFormatManager().LoopThroughCategories(callback, callback_baton); +} + +uint32_t +DataVisualization::Categories::GetCurrentRevision() +{ + return GetFormatManager().GetCurrentRevision(); +} + +uint32_t +DataVisualization::Categories::GetCount() +{ + return GetFormatManager().Categories().GetCount(); +} + +bool +DataVisualization::NamedSummaryFormats::Get(const ConstString &type, SummaryFormat::SharedPointer &entry) +{ + return GetFormatManager().NamedSummary().Get(type,entry); +} + +void +DataVisualization::NamedSummaryFormats::Add(const ConstString &type, const SummaryFormat::SharedPointer &entry) +{ + GetFormatManager().NamedSummary().Add(type,entry); +} + +bool +DataVisualization::NamedSummaryFormats::Delete(const ConstString &type) +{ + return GetFormatManager().NamedSummary().Delete(type); +} + +void +DataVisualization::NamedSummaryFormats::Clear() +{ + GetFormatManager().NamedSummary().Clear(); +} + +void +DataVisualization::NamedSummaryFormats::LoopThrough(SummaryFormat::SummaryCallback callback, void* callback_baton) +{ + GetFormatManager().NamedSummary().LoopThrough(callback, callback_baton); +} + +uint32_t +DataVisualization::NamedSummaryFormats::GetCurrentRevision() +{ + return GetFormatManager().GetCurrentRevision(); +} + +uint32_t +DataVisualization::NamedSummaryFormats::GetCount() +{ + return GetFormatManager().NamedSummary().GetCount(); +}
\ No newline at end of file |