Home | History | Annotate | Download | only in DataFormatters
      1 //===-- DataVisualization.cpp ---------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include "lldb/lldb-python.h"
     11 
     12 #include "lldb/DataFormatters/DataVisualization.h"
     13 
     14 // C Includes
     15 // C++ Includes
     16 // Other libraries and framework includes
     17 // Project includes
     18 
     19 #include "lldb/Core/Debugger.h"
     20 
     21 using namespace lldb;
     22 using namespace lldb_private;
     23 
     24 static FormatManager&
     25 GetFormatManager()
     26 {
     27     static FormatManager g_format_manager;
     28     return g_format_manager;
     29 }
     30 
     31 void
     32 DataVisualization::ForceUpdate ()
     33 {
     34     GetFormatManager().Changed();
     35 }
     36 
     37 uint32_t
     38 DataVisualization::GetCurrentRevision ()
     39 {
     40     return GetFormatManager().GetCurrentRevision();
     41 }
     42 
     43 lldb::TypeFormatImplSP
     44 DataVisualization::ValueFormats::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic)
     45 {
     46     lldb::TypeFormatImplSP entry;
     47     GetFormatManager().GetValueNavigator().Get(valobj, entry, use_dynamic);
     48     return entry;
     49 }
     50 
     51 lldb::TypeFormatImplSP
     52 DataVisualization::ValueFormats::GetFormat (const ConstString &type)
     53 {
     54     lldb::TypeFormatImplSP entry;
     55     GetFormatManager().GetValueNavigator().Get(type, entry);
     56     return entry;
     57 }
     58 
     59 void
     60 DataVisualization::ValueFormats::Add (const ConstString &type, const lldb::TypeFormatImplSP &entry)
     61 {
     62     GetFormatManager().GetValueNavigator().Add(FormatManager::GetValidTypeName(type),entry);
     63 }
     64 
     65 bool
     66 DataVisualization::ValueFormats::Delete (const ConstString &type)
     67 {
     68     return GetFormatManager().GetValueNavigator().Delete(type);
     69 }
     70 
     71 void
     72 DataVisualization::ValueFormats::Clear ()
     73 {
     74     GetFormatManager().GetValueNavigator().Clear();
     75 }
     76 
     77 void
     78 DataVisualization::ValueFormats::LoopThrough (TypeFormatImpl::ValueCallback callback, void* callback_baton)
     79 {
     80     GetFormatManager().GetValueNavigator().LoopThrough(callback, callback_baton);
     81 }
     82 
     83 size_t
     84 DataVisualization::ValueFormats::GetCount ()
     85 {
     86     return GetFormatManager().GetValueNavigator().GetCount();
     87 }
     88 
     89 lldb::TypeNameSpecifierImplSP
     90 DataVisualization::ValueFormats::GetTypeNameSpecifierForFormatAtIndex (size_t index)
     91 {
     92     return GetFormatManager().GetValueNavigator().GetTypeNameSpecifierAtIndex(index);
     93 }
     94 
     95 lldb::TypeFormatImplSP
     96 DataVisualization::ValueFormats::GetFormatAtIndex (size_t index)
     97 {
     98     return GetFormatManager().GetValueNavigator().GetAtIndex(index);
     99 }
    100 
    101 lldb::TypeSummaryImplSP
    102 DataVisualization::GetSummaryFormat (ValueObject& valobj,
    103                                      lldb::DynamicValueType use_dynamic)
    104 {
    105     return GetFormatManager().GetSummaryFormat(valobj, use_dynamic);
    106 }
    107 
    108 lldb::TypeSummaryImplSP
    109 DataVisualization::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp)
    110 {
    111     return GetFormatManager().GetSummaryForType(type_sp);
    112 }
    113 
    114 #ifndef LLDB_DISABLE_PYTHON
    115 lldb::SyntheticChildrenSP
    116 DataVisualization::GetSyntheticChildren (ValueObject& valobj,
    117                                          lldb::DynamicValueType use_dynamic)
    118 {
    119     return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic);
    120 }
    121 #endif
    122 
    123 #ifndef LLDB_DISABLE_PYTHON
    124 lldb::SyntheticChildrenSP
    125 DataVisualization::GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp)
    126 {
    127     return GetFormatManager().GetSyntheticChildrenForType(type_sp);
    128 }
    129 #endif
    130 
    131 lldb::TypeFilterImplSP
    132 DataVisualization::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp)
    133 {
    134     return GetFormatManager().GetFilterForType(type_sp);
    135 }
    136 
    137 #ifndef LLDB_DISABLE_PYTHON
    138 lldb::ScriptedSyntheticChildrenSP
    139 DataVisualization::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp)
    140 {
    141     return GetFormatManager().GetSyntheticForType(type_sp);
    142 }
    143 #endif
    144 
    145 bool
    146 DataVisualization::AnyMatches (ConstString type_name,
    147                                TypeCategoryImpl::FormatCategoryItems items,
    148                                bool only_enabled,
    149                                const char** matching_category,
    150                                TypeCategoryImpl::FormatCategoryItems* matching_type)
    151 {
    152     return GetFormatManager().AnyMatches(type_name,
    153                                          items,
    154                                          only_enabled,
    155                                          matching_category,
    156                                          matching_type);
    157 }
    158 
    159 bool
    160 DataVisualization::Categories::GetCategory (const ConstString &category, lldb::TypeCategoryImplSP &entry,
    161                                             bool allow_create)
    162 {
    163     entry = GetFormatManager().GetCategory(category, allow_create);
    164     return (entry.get() != NULL);
    165 }
    166 
    167 void
    168 DataVisualization::Categories::Add (const ConstString &category)
    169 {
    170     GetFormatManager().GetCategory(category);
    171 }
    172 
    173 bool
    174 DataVisualization::Categories::Delete (const ConstString &category)
    175 {
    176     GetFormatManager().DisableCategory(category);
    177     return GetFormatManager().DeleteCategory(category);
    178 }
    179 
    180 void
    181 DataVisualization::Categories::Clear ()
    182 {
    183     GetFormatManager().ClearCategories();
    184 }
    185 
    186 void
    187 DataVisualization::Categories::Clear (const ConstString &category)
    188 {
    189     GetFormatManager().GetCategory(category)->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
    190 }
    191 
    192 void
    193 DataVisualization::Categories::Enable (const ConstString& category,
    194                                        TypeCategoryMap::Position pos)
    195 {
    196     if (GetFormatManager().GetCategory(category)->IsEnabled())
    197         GetFormatManager().DisableCategory(category);
    198     GetFormatManager().EnableCategory(category, pos);
    199 }
    200 
    201 void
    202 DataVisualization::Categories::Disable (const ConstString& category)
    203 {
    204     if (GetFormatManager().GetCategory(category)->IsEnabled() == true)
    205         GetFormatManager().DisableCategory(category);
    206 }
    207 
    208 void
    209 DataVisualization::Categories::Enable (const lldb::TypeCategoryImplSP& category,
    210                                        TypeCategoryMap::Position pos)
    211 {
    212     if (category.get())
    213     {
    214         if (category->IsEnabled())
    215             GetFormatManager().DisableCategory(category);
    216         GetFormatManager().EnableCategory(category, pos);
    217     }
    218 }
    219 
    220 void
    221 DataVisualization::Categories::Disable (const lldb::TypeCategoryImplSP& category)
    222 {
    223     if (category.get() && category->IsEnabled() == true)
    224         GetFormatManager().DisableCategory(category);
    225 }
    226 
    227 void
    228 DataVisualization::Categories::LoopThrough (FormatManager::CategoryCallback callback, void* callback_baton)
    229 {
    230     GetFormatManager().LoopThroughCategories(callback, callback_baton);
    231 }
    232 
    233 uint32_t
    234 DataVisualization::Categories::GetCount ()
    235 {
    236     return GetFormatManager().GetCategoriesCount();
    237 }
    238 
    239 lldb::TypeCategoryImplSP
    240 DataVisualization::Categories::GetCategoryAtIndex (size_t index)
    241 {
    242     return GetFormatManager().GetCategoryAtIndex(index);
    243 }
    244 
    245 bool
    246 DataVisualization::NamedSummaryFormats::GetSummaryFormat (const ConstString &type, lldb::TypeSummaryImplSP &entry)
    247 {
    248     return GetFormatManager().GetNamedSummaryNavigator().Get(type,entry);
    249 }
    250 
    251 void
    252 DataVisualization::NamedSummaryFormats::Add (const ConstString &type, const lldb::TypeSummaryImplSP &entry)
    253 {
    254     GetFormatManager().GetNamedSummaryNavigator().Add(FormatManager::GetValidTypeName(type),entry);
    255 }
    256 
    257 bool
    258 DataVisualization::NamedSummaryFormats::Delete (const ConstString &type)
    259 {
    260     return GetFormatManager().GetNamedSummaryNavigator().Delete(type);
    261 }
    262 
    263 void
    264 DataVisualization::NamedSummaryFormats::Clear ()
    265 {
    266     GetFormatManager().GetNamedSummaryNavigator().Clear();
    267 }
    268 
    269 void
    270 DataVisualization::NamedSummaryFormats::LoopThrough (TypeSummaryImpl::SummaryCallback callback, void* callback_baton)
    271 {
    272     GetFormatManager().GetNamedSummaryNavigator().LoopThrough(callback, callback_baton);
    273 }
    274 
    275 uint32_t
    276 DataVisualization::NamedSummaryFormats::GetCount ()
    277 {
    278     return GetFormatManager().GetNamedSummaryNavigator().GetCount();
    279 }
    280