ValueObjectPrinter.h revision 269024
1//===-- ValueObjectPrinter.h ---------------------------------------*- 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#ifndef lldb_ValueObjectPrinter_h_ 11#define lldb_ValueObjectPrinter_h_ 12 13// C Includes 14// C++ Includes 15 16// Other libraries and framework includes 17// Project includes 18#include "lldb/lldb-private.h" 19#include "lldb/lldb-public.h" 20 21#include "lldb/Core/Stream.h" 22#include "lldb/Core/ValueObject.h" 23#include "lldb/DataFormatters/TypeSummary.h" 24 25namespace lldb_private { 26 27struct DumpValueObjectOptions 28{ 29 uint32_t m_max_ptr_depth; 30 uint32_t m_max_depth; 31 bool m_show_types; 32 bool m_show_location; 33 bool m_use_objc; 34 lldb::DynamicValueType m_use_dynamic; 35 bool m_use_synthetic; 36 bool m_scope_already_checked; 37 bool m_flat_output; 38 uint32_t m_omit_summary_depth; 39 bool m_ignore_cap; 40 lldb::Format m_format; 41 lldb::TypeSummaryImplSP m_summary_sp; 42 std::string m_root_valobj_name; 43 bool m_hide_root_type; 44 bool m_hide_name; 45 bool m_hide_value; 46 bool m_be_raw; 47 48 DumpValueObjectOptions() : 49 m_max_ptr_depth(0), 50 m_max_depth(UINT32_MAX), 51 m_show_types(false), 52 m_show_location(false), 53 m_use_objc(false), 54 m_use_dynamic(lldb::eNoDynamicValues), 55 m_use_synthetic(true), 56 m_scope_already_checked(false), 57 m_flat_output(false), 58 m_omit_summary_depth(0), 59 m_ignore_cap(false), 60 m_format (lldb::eFormatDefault), 61 m_summary_sp(), 62 m_root_valobj_name(), 63 m_hide_root_type(false), // provide a special compact display for "po" 64 m_hide_name(false), // provide a special compact display for "po" 65 m_hide_value(false), // provide a special compact display for "po" 66 m_be_raw(false) 67 {} 68 69 static const DumpValueObjectOptions 70 DefaultOptions() 71 { 72 static DumpValueObjectOptions g_default_options; 73 74 return g_default_options; 75 } 76 77 DumpValueObjectOptions (const DumpValueObjectOptions& rhs) : 78 m_max_ptr_depth(rhs.m_max_ptr_depth), 79 m_max_depth(rhs.m_max_depth), 80 m_show_types(rhs.m_show_types), 81 m_show_location(rhs.m_show_location), 82 m_use_objc(rhs.m_use_objc), 83 m_use_dynamic(rhs.m_use_dynamic), 84 m_use_synthetic(rhs.m_use_synthetic), 85 m_scope_already_checked(rhs.m_scope_already_checked), 86 m_flat_output(rhs.m_flat_output), 87 m_omit_summary_depth(rhs.m_omit_summary_depth), 88 m_ignore_cap(rhs.m_ignore_cap), 89 m_format(rhs.m_format), 90 m_summary_sp(rhs.m_summary_sp), 91 m_root_valobj_name(rhs.m_root_valobj_name), 92 m_hide_root_type(rhs.m_hide_root_type), 93 m_hide_name(rhs.m_hide_name), 94 m_hide_value(rhs.m_hide_value), 95 m_be_raw(rhs.m_be_raw) 96 {} 97 98 DumpValueObjectOptions& 99 SetMaximumPointerDepth(uint32_t depth = 0) 100 { 101 m_max_ptr_depth = depth; 102 return *this; 103 } 104 105 DumpValueObjectOptions& 106 SetMaximumDepth(uint32_t depth = 0) 107 { 108 m_max_depth = depth; 109 return *this; 110 } 111 112 DumpValueObjectOptions& 113 SetShowTypes(bool show = false) 114 { 115 m_show_types = show; 116 return *this; 117 } 118 119 DumpValueObjectOptions& 120 SetShowLocation(bool show = false) 121 { 122 m_show_location = show; 123 return *this; 124 } 125 126 DumpValueObjectOptions& 127 SetUseObjectiveC(bool use = false) 128 { 129 m_use_objc = use; 130 return *this; 131 } 132 133 DumpValueObjectOptions& 134 SetShowSummary(bool show = true) 135 { 136 if (show == false) 137 SetOmitSummaryDepth(UINT32_MAX); 138 else 139 SetOmitSummaryDepth(0); 140 return *this; 141 } 142 143 DumpValueObjectOptions& 144 SetUseDynamicType(lldb::DynamicValueType dyn = lldb::eNoDynamicValues) 145 { 146 m_use_dynamic = dyn; 147 return *this; 148 } 149 150 DumpValueObjectOptions& 151 SetUseSyntheticValue(bool use_synthetic = true) 152 { 153 m_use_synthetic = use_synthetic; 154 return *this; 155 } 156 157 DumpValueObjectOptions& 158 SetScopeChecked(bool check = true) 159 { 160 m_scope_already_checked = check; 161 return *this; 162 } 163 164 DumpValueObjectOptions& 165 SetFlatOutput(bool flat = false) 166 { 167 m_flat_output = flat; 168 return *this; 169 } 170 171 DumpValueObjectOptions& 172 SetOmitSummaryDepth(uint32_t depth = 0) 173 { 174 m_omit_summary_depth = depth; 175 return *this; 176 } 177 178 DumpValueObjectOptions& 179 SetIgnoreCap(bool ignore = false) 180 { 181 m_ignore_cap = ignore; 182 return *this; 183 } 184 185 DumpValueObjectOptions& 186 SetRawDisplay(bool raw = false) 187 { 188 if (raw) 189 { 190 SetUseSyntheticValue(false); 191 SetOmitSummaryDepth(UINT32_MAX); 192 SetIgnoreCap(true); 193 SetHideName(false); 194 SetHideValue(false); 195 m_be_raw = true; 196 } 197 else 198 { 199 SetUseSyntheticValue(true); 200 SetOmitSummaryDepth(0); 201 SetIgnoreCap(false); 202 SetHideName(false); 203 SetHideValue(false); 204 m_be_raw = false; 205 } 206 return *this; 207 } 208 209 DumpValueObjectOptions& 210 SetFormat (lldb::Format format = lldb::eFormatDefault) 211 { 212 m_format = format; 213 return *this; 214 } 215 216 DumpValueObjectOptions& 217 SetSummary (lldb::TypeSummaryImplSP summary = lldb::TypeSummaryImplSP()) 218 { 219 m_summary_sp = summary; 220 return *this; 221 } 222 223 DumpValueObjectOptions& 224 SetRootValueObjectName (const char* name = NULL) 225 { 226 if (name) 227 m_root_valobj_name.assign(name); 228 else 229 m_root_valobj_name.clear(); 230 return *this; 231 } 232 233 DumpValueObjectOptions& 234 SetHideRootType (bool hide_root_type = false) 235 { 236 m_hide_root_type = hide_root_type; 237 return *this; 238 } 239 240 DumpValueObjectOptions& 241 SetHideName (bool hide_name = false) 242 { 243 m_hide_name = hide_name; 244 return *this; 245 } 246 247 DumpValueObjectOptions& 248 SetHideValue (bool hide_value = false) 249 { 250 m_hide_value = hide_value; 251 return *this; 252 } 253}; 254 255class ValueObjectPrinter 256{ 257public: 258 259 ValueObjectPrinter (ValueObject* valobj, 260 Stream* s, 261 const DumpValueObjectOptions& options); 262 263 ~ValueObjectPrinter () {} 264 265 bool 266 PrintValueObject (); 267 268protected: 269 270 // only this class (and subclasses, if any) should ever be concerned with 271 // the depth mechanism 272 ValueObjectPrinter (ValueObject* valobj, 273 Stream* s, 274 const DumpValueObjectOptions& options, 275 uint32_t ptr_depth, 276 uint32_t curr_depth); 277 278 // we should actually be using delegating constructors here 279 // but some versions of GCC still have trouble with those 280 void 281 Init (ValueObject* valobj, 282 Stream* s, 283 const DumpValueObjectOptions& options, 284 uint32_t ptr_depth, 285 uint32_t curr_depth); 286 287 bool 288 GetDynamicValueIfNeeded (); 289 290 const char* 291 GetDescriptionForDisplay (); 292 293 const char* 294 GetRootNameForDisplay (const char* if_fail = nullptr); 295 296 bool 297 ShouldPrintValueObject (); 298 299 bool 300 IsNil (); 301 302 bool 303 IsPtr (); 304 305 bool 306 IsRef (); 307 308 bool 309 IsAggregate (); 310 311 bool 312 PrintLocationIfNeeded (); 313 314 bool 315 PrintTypeIfNeeded (); 316 317 bool 318 PrintNameIfNeeded (bool show_type); 319 320 bool 321 CheckScopeIfNeeded (); 322 323 TypeSummaryImpl* 324 GetSummaryFormatter (); 325 326 void 327 GetValueSummaryError (std::string& value, 328 std::string& summary, 329 std::string& error); 330 331 bool 332 PrintValueAndSummaryIfNeeded (bool& value_printed, 333 bool& summary_printed); 334 335 bool 336 PrintObjectDescriptionIfNeeded (bool value_printed, 337 bool summary_printed); 338 339 bool 340 ShouldPrintChildren (bool is_failed_description, 341 uint32_t& curr_ptr_depth); 342 343 ValueObject* 344 GetValueObjectForChildrenGeneration (); 345 346 void 347 PrintChildrenPreamble (); 348 349 void 350 PrintChildrenPostamble (bool print_dotdotdot); 351 352 void 353 PrintChild (lldb::ValueObjectSP child_sp, 354 uint32_t curr_ptr_depth); 355 356 uint32_t 357 GetMaxNumChildrenToPrint (bool& print_dotdotdot); 358 359 void 360 PrintChildren (uint32_t curr_ptr_depth); 361 362 void 363 PrintChildrenIfNeeded (bool value_printed, 364 bool summary_printed); 365 366 bool 367 PrintChildrenOneLiner (bool hide_names); 368 369private: 370 371 ValueObject *m_orig_valobj; 372 ValueObject *m_valobj; 373 Stream *m_stream; 374 DumpValueObjectOptions options; 375 Flags m_type_flags; 376 ClangASTType m_clang_type; 377 uint32_t m_ptr_depth; 378 uint32_t m_curr_depth; 379 LazyBool m_should_print; 380 LazyBool m_is_nil; 381 LazyBool m_is_ptr; 382 LazyBool m_is_ref; 383 LazyBool m_is_aggregate; 384 std::pair<TypeSummaryImpl*,bool> m_summary_formatter; 385 std::string m_value; 386 std::string m_summary; 387 std::string m_error; 388 389 friend class StringSummaryFormat; 390 391 DISALLOW_COPY_AND_ASSIGN(ValueObjectPrinter); 392}; 393 394} // namespace lldb_private 395 396#endif // lldb_ValueObjectPrinter_h_ 397