Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 1 | //===-- ValueObjectPrinter.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/DataFormatters/ValueObjectPrinter.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Core/Debugger.h" |
Enrico Granata | a29cb0b | 2013-10-04 23:14:13 +0000 | [diff] [blame] | 17 | #include "lldb/DataFormatters/DataVisualization.h" |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 19 | #include "lldb/Target/Target.h" |
| 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
Enrico Granata | d595733 | 2015-06-03 20:43:54 +0000 | [diff] [blame] | 24 | DumpValueObjectOptions::DumpValueObjectOptions (ValueObject& valobj) : |
| 25 | DumpValueObjectOptions() |
| 26 | { |
| 27 | m_use_dynamic = valobj.GetDynamicValueType(); |
| 28 | m_use_synthetic = valobj.IsSynthetic(); |
Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame^] | 29 | m_varformat_language = valobj.GetPreferredDisplayLanguage(); |
Enrico Granata | d595733 | 2015-06-03 20:43:54 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj, |
| 33 | Stream* s) |
| 34 | { |
| 35 | if (valobj) |
| 36 | { |
| 37 | DumpValueObjectOptions options(*valobj); |
| 38 | Init (valobj,s,options,options.m_max_ptr_depth,0); |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | DumpValueObjectOptions options; |
| 43 | Init (valobj,s,options,options.m_max_ptr_depth,0); |
| 44 | } |
| 45 | } |
| 46 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 47 | ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj, |
| 48 | Stream* s, |
Enrico Granata | 938d1d6 | 2013-10-05 00:20:27 +0000 | [diff] [blame] | 49 | const DumpValueObjectOptions& options) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 50 | { |
Enrico Granata | 938d1d6 | 2013-10-05 00:20:27 +0000 | [diff] [blame] | 51 | Init(valobj,s,options,options.m_max_ptr_depth,0); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj, |
| 55 | Stream* s, |
| 56 | const DumpValueObjectOptions& options, |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 57 | const DumpValueObjectOptions::PointerDepth& ptr_depth, |
Enrico Granata | 938d1d6 | 2013-10-05 00:20:27 +0000 | [diff] [blame] | 58 | uint32_t curr_depth) |
| 59 | { |
| 60 | Init(valobj,s,options,ptr_depth,curr_depth); |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | ValueObjectPrinter::Init (ValueObject* valobj, |
| 65 | Stream* s, |
| 66 | const DumpValueObjectOptions& options, |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 67 | const DumpValueObjectOptions::PointerDepth& ptr_depth, |
Enrico Granata | 938d1d6 | 2013-10-05 00:20:27 +0000 | [diff] [blame] | 68 | uint32_t curr_depth) |
| 69 | { |
| 70 | m_orig_valobj = valobj; |
| 71 | m_valobj = nullptr; |
| 72 | m_stream = s; |
| 73 | this->options = options; |
| 74 | m_ptr_depth = ptr_depth; |
| 75 | m_curr_depth = curr_depth; |
| 76 | assert (m_orig_valobj && "cannot print a NULL ValueObject"); |
| 77 | assert (m_stream && "cannot print to a NULL Stream"); |
| 78 | m_should_print = eLazyBoolCalculate; |
| 79 | m_is_nil = eLazyBoolCalculate; |
| 80 | m_is_ptr = eLazyBoolCalculate; |
| 81 | m_is_ref = eLazyBoolCalculate; |
| 82 | m_is_aggregate = eLazyBoolCalculate; |
| 83 | m_summary_formatter = {nullptr,false}; |
| 84 | m_value.assign(""); |
| 85 | m_summary.assign(""); |
| 86 | m_error.assign(""); |
| 87 | } |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 88 | |
| 89 | bool |
| 90 | ValueObjectPrinter::PrintValueObject () |
| 91 | { |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 92 | if (!GetMostSpecializedValue () || m_valobj == nullptr) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 93 | return false; |
| 94 | |
| 95 | if (ShouldPrintValueObject()) |
| 96 | { |
Enrico Granata | 0f883ff | 2014-09-06 02:20:19 +0000 | [diff] [blame] | 97 | PrintValidationMarkerIfNeeded(); |
| 98 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 99 | PrintLocationIfNeeded(); |
| 100 | m_stream->Indent(); |
| 101 | |
| 102 | bool show_type = PrintTypeIfNeeded(); |
| 103 | |
| 104 | PrintNameIfNeeded(show_type); |
| 105 | } |
| 106 | |
| 107 | bool value_printed = false; |
| 108 | bool summary_printed = false; |
| 109 | |
| 110 | bool val_summary_ok = PrintValueAndSummaryIfNeeded (value_printed,summary_printed); |
| 111 | |
| 112 | if (val_summary_ok) |
| 113 | PrintChildrenIfNeeded (value_printed, summary_printed); |
Enrico Granata | 3993893 | 2013-10-03 02:06:02 +0000 | [diff] [blame] | 114 | else |
| 115 | m_stream->EOL(); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 116 | |
Enrico Granata | 0f883ff | 2014-09-06 02:20:19 +0000 | [diff] [blame] | 117 | PrintValidationErrorIfNeeded(); |
| 118 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 119 | return true; |
| 120 | } |
| 121 | |
| 122 | bool |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 123 | ValueObjectPrinter::GetMostSpecializedValue () |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 124 | { |
Enrico Granata | a29cb0b | 2013-10-04 23:14:13 +0000 | [diff] [blame] | 125 | if (m_valobj) |
| 126 | return true; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 127 | bool update_success = m_orig_valobj->UpdateValueIfNeeded (true); |
| 128 | if (!update_success) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 129 | { |
Enrico Granata | 106260c | 2013-10-22 22:42:14 +0000 | [diff] [blame] | 130 | m_valobj = m_orig_valobj; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 131 | } |
| 132 | else |
Enrico Granata | 106260c | 2013-10-22 22:42:14 +0000 | [diff] [blame] | 133 | { |
| 134 | if (m_orig_valobj->IsDynamic()) |
| 135 | { |
| 136 | if (options.m_use_dynamic == eNoDynamicValues) |
| 137 | { |
| 138 | ValueObject *static_value = m_orig_valobj->GetStaticValue().get(); |
| 139 | if (static_value) |
| 140 | m_valobj = static_value; |
| 141 | else |
| 142 | m_valobj = m_orig_valobj; |
| 143 | } |
| 144 | else |
| 145 | m_valobj = m_orig_valobj; |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | if (options.m_use_dynamic != eNoDynamicValues) |
| 150 | { |
| 151 | ValueObject *dynamic_value = m_orig_valobj->GetDynamicValue(options.m_use_dynamic).get(); |
| 152 | if (dynamic_value) |
| 153 | m_valobj = dynamic_value; |
| 154 | else |
| 155 | m_valobj = m_orig_valobj; |
| 156 | } |
| 157 | else |
| 158 | m_valobj = m_orig_valobj; |
| 159 | } |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 160 | |
| 161 | if (m_valobj->IsSynthetic()) |
| 162 | { |
| 163 | if (options.m_use_synthetic == false) |
| 164 | { |
| 165 | ValueObject *non_synthetic = m_valobj->GetNonSyntheticValue().get(); |
| 166 | if (non_synthetic) |
| 167 | m_valobj = non_synthetic; |
| 168 | } |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | if (options.m_use_synthetic == true) |
| 173 | { |
| 174 | ValueObject *synthetic = m_valobj->GetSyntheticValue().get(); |
| 175 | if (synthetic) |
| 176 | m_valobj = synthetic; |
| 177 | } |
| 178 | } |
Enrico Granata | 106260c | 2013-10-22 22:42:14 +0000 | [diff] [blame] | 179 | } |
Bruce Mitchener | 59b5a37 | 2015-09-17 18:43:40 +0000 | [diff] [blame] | 180 | m_compiler_type = m_valobj->GetCompilerType(); |
| 181 | m_type_flags = m_compiler_type.GetTypeInfo (); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 182 | return true; |
| 183 | } |
| 184 | |
| 185 | const char* |
| 186 | ValueObjectPrinter::GetDescriptionForDisplay () |
| 187 | { |
| 188 | const char* str = m_valobj->GetObjectDescription(); |
| 189 | if (!str) |
| 190 | str = m_valobj->GetSummaryAsCString(); |
| 191 | if (!str) |
| 192 | str = m_valobj->GetValueAsCString(); |
| 193 | return str; |
| 194 | } |
| 195 | |
| 196 | const char* |
| 197 | ValueObjectPrinter::GetRootNameForDisplay (const char* if_fail) |
| 198 | { |
| 199 | const char *root_valobj_name = options.m_root_valobj_name.empty() ? |
| 200 | m_valobj->GetName().AsCString() : |
| 201 | options.m_root_valobj_name.c_str(); |
| 202 | return root_valobj_name ? root_valobj_name : if_fail; |
| 203 | } |
| 204 | |
| 205 | bool |
| 206 | ValueObjectPrinter::ShouldPrintValueObject () |
| 207 | { |
| 208 | if (m_should_print == eLazyBoolCalculate) |
Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 209 | m_should_print = (options.m_flat_output == false || m_type_flags.Test (eTypeHasValue)) ? eLazyBoolYes : eLazyBoolNo; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 210 | return m_should_print == eLazyBoolYes; |
| 211 | } |
| 212 | |
| 213 | bool |
| 214 | ValueObjectPrinter::IsNil () |
| 215 | { |
| 216 | if (m_is_nil == eLazyBoolCalculate) |
| 217 | m_is_nil = m_valobj->IsObjCNil() ? eLazyBoolYes : eLazyBoolNo; |
| 218 | return m_is_nil == eLazyBoolYes; |
| 219 | } |
| 220 | |
| 221 | bool |
| 222 | ValueObjectPrinter::IsPtr () |
| 223 | { |
| 224 | if (m_is_ptr == eLazyBoolCalculate) |
Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 225 | m_is_ptr = m_type_flags.Test (eTypeIsPointer) ? eLazyBoolYes : eLazyBoolNo; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 226 | return m_is_ptr == eLazyBoolYes; |
| 227 | } |
| 228 | |
| 229 | bool |
| 230 | ValueObjectPrinter::IsRef () |
| 231 | { |
| 232 | if (m_is_ref == eLazyBoolCalculate) |
Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 233 | m_is_ref = m_type_flags.Test (eTypeIsReference) ? eLazyBoolYes : eLazyBoolNo; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 234 | return m_is_ref == eLazyBoolYes; |
| 235 | } |
| 236 | |
| 237 | bool |
| 238 | ValueObjectPrinter::IsAggregate () |
| 239 | { |
| 240 | if (m_is_aggregate == eLazyBoolCalculate) |
Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 241 | m_is_aggregate = m_type_flags.Test (eTypeHasChildren) ? eLazyBoolYes : eLazyBoolNo; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 242 | return m_is_aggregate == eLazyBoolYes; |
| 243 | } |
| 244 | |
| 245 | bool |
| 246 | ValueObjectPrinter::PrintLocationIfNeeded () |
| 247 | { |
| 248 | if (options.m_show_location) |
| 249 | { |
| 250 | m_stream->Printf("%s: ", m_valobj->GetLocationAsCString()); |
| 251 | return true; |
| 252 | } |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | bool |
| 257 | ValueObjectPrinter::PrintTypeIfNeeded () |
| 258 | { |
| 259 | bool show_type = true; |
| 260 | // if we are at the root-level and been asked to hide the root's type, then hide it |
| 261 | if (m_curr_depth == 0 && options.m_hide_root_type) |
| 262 | show_type = false; |
| 263 | else |
| 264 | // otherwise decide according to the usual rules (asked to show types - always at the root level) |
| 265 | show_type = options.m_show_types || (m_curr_depth == 0 && !options.m_flat_output); |
| 266 | |
| 267 | if (show_type) |
| 268 | { |
| 269 | // Some ValueObjects don't have types (like registers sets). Only print |
| 270 | // the type if there is one to print |
Enrico Granata | a126e46 | 2014-11-21 18:47:26 +0000 | [diff] [blame] | 271 | ConstString type_name; |
| 272 | if (options.m_use_type_display_name) |
| 273 | type_name = m_valobj->GetDisplayTypeName(); |
Enrico Granata | e8daa2f | 2014-05-17 19:14:17 +0000 | [diff] [blame] | 274 | else |
Enrico Granata | a126e46 | 2014-11-21 18:47:26 +0000 | [diff] [blame] | 275 | type_name = m_valobj->GetQualifiedTypeName(); |
| 276 | if (type_name) |
| 277 | m_stream->Printf("(%s) ", type_name.GetCString()); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 278 | else |
| 279 | show_type = false; |
| 280 | } |
| 281 | return show_type; |
| 282 | } |
| 283 | |
| 284 | bool |
| 285 | ValueObjectPrinter::PrintNameIfNeeded (bool show_type) |
| 286 | { |
| 287 | if (options.m_flat_output) |
| 288 | { |
| 289 | // If we are showing types, also qualify the C++ base classes |
| 290 | const bool qualify_cxx_base_classes = show_type; |
| 291 | if (!options.m_hide_name) |
| 292 | { |
| 293 | m_valobj->GetExpressionPath(*m_stream, qualify_cxx_base_classes); |
| 294 | m_stream->PutCString(" ="); |
| 295 | return true; |
| 296 | } |
| 297 | } |
| 298 | else if (!options.m_hide_name) |
| 299 | { |
| 300 | const char *name_cstr = GetRootNameForDisplay(""); |
| 301 | m_stream->Printf ("%s =", name_cstr); |
| 302 | return true; |
| 303 | } |
| 304 | return false; |
| 305 | } |
| 306 | |
| 307 | bool |
| 308 | ValueObjectPrinter::CheckScopeIfNeeded () |
| 309 | { |
| 310 | if (options.m_scope_already_checked) |
| 311 | return true; |
| 312 | return m_valobj->IsInScope(); |
| 313 | } |
| 314 | |
| 315 | TypeSummaryImpl* |
| 316 | ValueObjectPrinter::GetSummaryFormatter () |
| 317 | { |
| 318 | if (m_summary_formatter.second == false) |
| 319 | { |
| 320 | TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : m_valobj->GetSummaryFormat().get(); |
| 321 | |
| 322 | if (options.m_omit_summary_depth > 0) |
| 323 | entry = NULL; |
| 324 | m_summary_formatter.first = entry; |
| 325 | m_summary_formatter.second = true; |
| 326 | } |
| 327 | return m_summary_formatter.first; |
| 328 | } |
| 329 | |
| 330 | void |
| 331 | ValueObjectPrinter::GetValueSummaryError (std::string& value, |
| 332 | std::string& summary, |
| 333 | std::string& error) |
| 334 | { |
Enrico Granata | 465f4bc | 2014-02-15 01:24:44 +0000 | [diff] [blame] | 335 | if (options.m_format != eFormatDefault && options.m_format != m_valobj->GetFormat()) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 336 | { |
Enrico Granata | 465f4bc | 2014-02-15 01:24:44 +0000 | [diff] [blame] | 337 | m_valobj->GetValueAsCString(options.m_format, |
| 338 | value); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 339 | } |
Enrico Granata | 465f4bc | 2014-02-15 01:24:44 +0000 | [diff] [blame] | 340 | else |
| 341 | { |
| 342 | const char* val_cstr = m_valobj->GetValueAsCString(); |
| 343 | if (val_cstr) |
| 344 | value.assign(val_cstr); |
| 345 | } |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 346 | const char* err_cstr = m_valobj->GetError().AsCString(); |
| 347 | if (err_cstr) |
| 348 | error.assign(err_cstr); |
| 349 | |
| 350 | if (ShouldPrintValueObject()) |
| 351 | { |
| 352 | if (IsNil()) |
| 353 | summary.assign("nil"); |
| 354 | else if (options.m_omit_summary_depth == 0) |
| 355 | { |
| 356 | TypeSummaryImpl* entry = GetSummaryFormatter(); |
| 357 | if (entry) |
Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame^] | 358 | m_valobj->GetSummaryAsCString(entry, summary, options.m_varformat_language); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 359 | else |
| 360 | { |
Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame^] | 361 | const char* sum_cstr = m_valobj->GetSummaryAsCString(options.m_varformat_language); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 362 | if (sum_cstr) |
| 363 | summary.assign(sum_cstr); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | bool |
| 370 | ValueObjectPrinter::PrintValueAndSummaryIfNeeded (bool& value_printed, |
| 371 | bool& summary_printed) |
| 372 | { |
| 373 | bool error_printed = false; |
| 374 | if (ShouldPrintValueObject()) |
| 375 | { |
| 376 | if (!CheckScopeIfNeeded()) |
| 377 | m_error.assign("out of scope"); |
| 378 | if (m_error.empty()) |
| 379 | { |
| 380 | GetValueSummaryError(m_value, m_summary, m_error); |
| 381 | } |
| 382 | if (m_error.size()) |
| 383 | { |
| 384 | error_printed = true; |
| 385 | m_stream->Printf (" <%s>\n", m_error.c_str()); |
| 386 | } |
| 387 | else |
| 388 | { |
| 389 | // Make sure we have a value and make sure the summary didn't |
| 390 | // specify that the value should not be printed - and do not print |
| 391 | // the value if this thing is nil |
| 392 | // (but show the value if the user passes a format explicitly) |
| 393 | TypeSummaryImpl* entry = GetSummaryFormatter(); |
Enrico Granata | 8a068e6 | 2014-04-23 23:16:25 +0000 | [diff] [blame] | 394 | if (!IsNil() && !m_value.empty() && (entry == NULL || (entry->DoesPrintValue(m_valobj) || options.m_format != eFormatDefault) || m_summary.empty()) && !options.m_hide_value) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 395 | { |
| 396 | m_stream->Printf(" %s", m_value.c_str()); |
| 397 | value_printed = true; |
| 398 | } |
| 399 | |
| 400 | if (m_summary.size()) |
| 401 | { |
| 402 | m_stream->Printf(" %s", m_summary.c_str()); |
| 403 | summary_printed = true; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | return !error_printed; |
| 408 | } |
| 409 | |
| 410 | bool |
| 411 | ValueObjectPrinter::PrintObjectDescriptionIfNeeded (bool value_printed, |
| 412 | bool summary_printed) |
| 413 | { |
| 414 | if (ShouldPrintValueObject()) |
| 415 | { |
| 416 | // let's avoid the overly verbose no description error for a nil thing |
| 417 | if (options.m_use_objc && !IsNil()) |
| 418 | { |
| 419 | if (!options.m_hide_value || !options.m_hide_name) |
| 420 | m_stream->Printf(" "); |
| 421 | const char *object_desc = nullptr; |
| 422 | if (value_printed || summary_printed) |
| 423 | object_desc = m_valobj->GetObjectDescription(); |
| 424 | else |
| 425 | object_desc = GetDescriptionForDisplay(); |
| 426 | if (object_desc && *object_desc) |
| 427 | { |
| 428 | m_stream->Printf("%s\n", object_desc); |
| 429 | return true; |
| 430 | } |
| 431 | else if (value_printed == false && summary_printed == false) |
| 432 | return true; |
| 433 | else |
| 434 | return false; |
| 435 | } |
| 436 | } |
| 437 | return true; |
| 438 | } |
| 439 | |
| 440 | bool |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 441 | DumpValueObjectOptions::PointerDepth::CanAllowExpansion (bool is_root, |
| 442 | TypeSummaryImpl* entry, |
| 443 | ValueObject *valobj, |
| 444 | const std::string& summary) |
| 445 | { |
| 446 | switch (m_mode) |
| 447 | { |
| 448 | case Mode::Always: |
| 449 | return (m_count > 0); |
| 450 | case Mode::Never: |
| 451 | return false; |
| 452 | case Mode::Default: |
| 453 | if (is_root) |
| 454 | m_count = std::min<decltype(m_count)>(m_count,1); |
| 455 | return m_count > 0; |
| 456 | case Mode::Formatters: |
| 457 | if (!entry || entry->DoesPrintChildren(valobj) || summary.empty()) |
| 458 | return m_count > 0; |
| 459 | return false; |
| 460 | } |
Zachary Turner | 84f5b0d | 2015-09-09 17:25:43 +0000 | [diff] [blame] | 461 | return false; |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | bool |
| 465 | DumpValueObjectOptions::PointerDepth::CanAllowExpansion () const |
| 466 | { |
| 467 | switch (m_mode) |
| 468 | { |
| 469 | case Mode::Always: |
| 470 | case Mode::Default: |
| 471 | case Mode::Formatters: |
| 472 | return (m_count > 0); |
| 473 | case Mode::Never: |
| 474 | return false; |
| 475 | } |
Zachary Turner | 84f5b0d | 2015-09-09 17:25:43 +0000 | [diff] [blame] | 476 | return false; |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | bool |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 480 | ValueObjectPrinter::ShouldPrintChildren (bool is_failed_description, |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 481 | DumpValueObjectOptions::PointerDepth& curr_ptr_depth) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 482 | { |
| 483 | const bool is_ref = IsRef (); |
| 484 | const bool is_ptr = IsPtr (); |
| 485 | |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 486 | TypeSummaryImpl* entry = GetSummaryFormatter(); |
| 487 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 488 | if (is_failed_description || m_curr_depth < options.m_max_depth) |
| 489 | { |
| 490 | // We will show children for all concrete types. We won't show |
| 491 | // pointer contents unless a pointer depth has been specified. |
| 492 | // We won't reference contents unless the reference is the |
| 493 | // root object (depth of zero). |
| 494 | |
| 495 | // Use a new temporary pointer depth in case we override the |
| 496 | // current pointer depth below... |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 497 | |
| 498 | if (is_ptr || is_ref) |
| 499 | { |
| 500 | // We have a pointer or reference whose value is an address. |
| 501 | // Make sure that address is not NULL |
| 502 | AddressType ptr_address_type; |
| 503 | if (m_valobj->GetPointerValue (&ptr_address_type) == 0) |
| 504 | return false; |
| 505 | |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 506 | const bool is_root_level = m_curr_depth == 0; |
| 507 | |
| 508 | if (is_ref && |
| 509 | is_root_level) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 510 | { |
| 511 | // If this is the root object (depth is zero) that we are showing |
| 512 | // and it is a reference, and no pointer depth has been supplied |
| 513 | // print out what it references. Don't do this at deeper depths |
| 514 | // otherwise we can end up with infinite recursion... |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 515 | return true; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 518 | return curr_ptr_depth.CanAllowExpansion(false, entry, m_valobj, m_summary); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Enrico Granata | 8a068e6 | 2014-04-23 23:16:25 +0000 | [diff] [blame] | 521 | return (!entry || entry->DoesPrintChildren(m_valobj) || m_summary.empty()); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 522 | } |
| 523 | return false; |
| 524 | } |
| 525 | |
Siva Chandra | d26eb90 | 2015-07-24 21:30:58 +0000 | [diff] [blame] | 526 | bool |
| 527 | ValueObjectPrinter::ShouldExpandEmptyAggregates () |
| 528 | { |
| 529 | TypeSummaryImpl* entry = GetSummaryFormatter(); |
| 530 | |
| 531 | if (!entry) |
| 532 | return true; |
| 533 | |
| 534 | return entry->DoesPrintEmptyAggregates(); |
| 535 | } |
| 536 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 537 | ValueObject* |
| 538 | ValueObjectPrinter::GetValueObjectForChildrenGeneration () |
| 539 | { |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 540 | return m_valobj; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | void |
| 544 | ValueObjectPrinter::PrintChildrenPreamble () |
| 545 | { |
| 546 | if (options.m_flat_output) |
| 547 | { |
| 548 | if (ShouldPrintValueObject()) |
| 549 | m_stream->EOL(); |
| 550 | } |
| 551 | else |
| 552 | { |
| 553 | if (ShouldPrintValueObject()) |
| 554 | m_stream->PutCString(IsRef () ? ": {\n" : " {\n"); |
| 555 | m_stream->IndentMore(); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | void |
| 560 | ValueObjectPrinter::PrintChild (ValueObjectSP child_sp, |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 561 | const DumpValueObjectOptions::PointerDepth& curr_ptr_depth) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 562 | { |
| 563 | DumpValueObjectOptions child_options(options); |
Enrico Granata | 443844c | 2015-06-17 02:11:48 +0000 | [diff] [blame] | 564 | child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName(); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 565 | child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value) |
| 566 | .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0); |
| 567 | if (child_sp.get()) |
| 568 | { |
| 569 | ValueObjectPrinter child_printer(child_sp.get(), |
| 570 | m_stream, |
| 571 | child_options, |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 572 | (IsPtr() || IsRef()) ? --curr_ptr_depth : curr_ptr_depth, |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 573 | m_curr_depth + 1); |
| 574 | child_printer.PrintValueObject(); |
| 575 | } |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | uint32_t |
| 579 | ValueObjectPrinter::GetMaxNumChildrenToPrint (bool& print_dotdotdot) |
| 580 | { |
| 581 | ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); |
| 582 | |
| 583 | size_t num_children = synth_m_valobj->GetNumChildren(); |
| 584 | print_dotdotdot = false; |
| 585 | if (num_children) |
| 586 | { |
| 587 | const size_t max_num_children = m_valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); |
| 588 | |
| 589 | if (num_children > max_num_children && !options.m_ignore_cap) |
| 590 | { |
| 591 | print_dotdotdot = true; |
| 592 | return max_num_children; |
| 593 | } |
| 594 | } |
| 595 | return num_children; |
| 596 | } |
| 597 | |
| 598 | void |
| 599 | ValueObjectPrinter::PrintChildrenPostamble (bool print_dotdotdot) |
| 600 | { |
| 601 | if (!options.m_flat_output) |
| 602 | { |
| 603 | if (print_dotdotdot) |
| 604 | { |
| 605 | m_valobj->GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated(); |
| 606 | m_stream->Indent("...\n"); |
| 607 | } |
| 608 | m_stream->IndentLess(); |
| 609 | m_stream->Indent("}\n"); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | void |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 614 | ValueObjectPrinter::PrintChildren (bool value_printed, |
| 615 | bool summary_printed, |
| 616 | const DumpValueObjectOptions::PointerDepth& curr_ptr_depth) |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 617 | { |
| 618 | ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); |
| 619 | |
| 620 | bool print_dotdotdot = false; |
| 621 | size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); |
| 622 | if (num_children) |
| 623 | { |
| 624 | PrintChildrenPreamble (); |
| 625 | |
| 626 | for (size_t idx=0; idx<num_children; ++idx) |
| 627 | { |
| 628 | ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true)); |
| 629 | PrintChild (child_sp, curr_ptr_depth); |
| 630 | } |
| 631 | |
| 632 | PrintChildrenPostamble (print_dotdotdot); |
| 633 | } |
| 634 | else if (IsAggregate()) |
| 635 | { |
| 636 | // Aggregate, no children... |
| 637 | if (ShouldPrintValueObject()) |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 638 | { |
| 639 | // if it has a synthetic value, then don't print {}, the synthetic children are probably only being used to vend a value |
Siva Chandra | d26eb90 | 2015-07-24 21:30:58 +0000 | [diff] [blame] | 640 | if (m_valobj->DoesProvideSyntheticValue() || !ShouldExpandEmptyAggregates()) |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 641 | m_stream->PutCString( "\n"); |
| 642 | else |
| 643 | m_stream->PutCString(" {}\n"); |
| 644 | } |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 645 | } |
| 646 | else |
| 647 | { |
| 648 | if (ShouldPrintValueObject()) |
| 649 | m_stream->EOL(); |
| 650 | } |
| 651 | } |
| 652 | |
Enrico Granata | a29cb0b | 2013-10-04 23:14:13 +0000 | [diff] [blame] | 653 | bool |
| 654 | ValueObjectPrinter::PrintChildrenOneLiner (bool hide_names) |
| 655 | { |
Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 656 | if (!GetMostSpecializedValue () || m_valobj == nullptr) |
Enrico Granata | a29cb0b | 2013-10-04 23:14:13 +0000 | [diff] [blame] | 657 | return false; |
| 658 | |
| 659 | ValueObject* synth_m_valobj = GetValueObjectForChildrenGeneration(); |
| 660 | |
| 661 | bool print_dotdotdot = false; |
| 662 | size_t num_children = GetMaxNumChildrenToPrint(print_dotdotdot); |
| 663 | |
| 664 | if (num_children) |
| 665 | { |
| 666 | m_stream->PutChar('('); |
| 667 | |
| 668 | for (uint32_t idx=0; idx<num_children; ++idx) |
| 669 | { |
| 670 | lldb::ValueObjectSP child_sp(synth_m_valobj->GetChildAtIndex(idx, true)); |
Enrico Granata | ddac761 | 2014-10-09 18:47:36 +0000 | [diff] [blame] | 671 | if (child_sp) |
| 672 | child_sp = child_sp->GetQualifiedRepresentationIfAvailable(options.m_use_dynamic, options.m_use_synthetic); |
Enrico Granata | a29cb0b | 2013-10-04 23:14:13 +0000 | [diff] [blame] | 673 | if (child_sp) |
| 674 | { |
| 675 | if (idx) |
| 676 | m_stream->PutCString(", "); |
| 677 | if (!hide_names) |
| 678 | { |
| 679 | const char* name = child_sp.get()->GetName().AsCString(); |
| 680 | if (name && *name) |
| 681 | { |
| 682 | m_stream->PutCString(name); |
| 683 | m_stream->PutCString(" = "); |
| 684 | } |
| 685 | } |
| 686 | child_sp->DumpPrintableRepresentation(*m_stream, |
| 687 | ValueObject::eValueObjectRepresentationStyleSummary, |
Enrico Granata | 443844c | 2015-06-17 02:11:48 +0000 | [diff] [blame] | 688 | lldb::eFormatInvalid, |
Enrico Granata | a29cb0b | 2013-10-04 23:14:13 +0000 | [diff] [blame] | 689 | ValueObject::ePrintableRepresentationSpecialCasesDisable); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | if (print_dotdotdot) |
| 694 | m_stream->PutCString(", ...)"); |
| 695 | else |
| 696 | m_stream->PutChar(')'); |
| 697 | } |
| 698 | return true; |
| 699 | } |
| 700 | |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 701 | void |
| 702 | ValueObjectPrinter::PrintChildrenIfNeeded (bool value_printed, |
| 703 | bool summary_printed) |
| 704 | { |
| 705 | // this flag controls whether we tried to display a description for this object and failed |
| 706 | // if that happens, we want to display the children, if any |
| 707 | bool is_failed_description = !PrintObjectDescriptionIfNeeded(value_printed, summary_printed); |
| 708 | |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 709 | auto curr_ptr_depth = m_ptr_depth; |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 710 | bool print_children = ShouldPrintChildren (is_failed_description,curr_ptr_depth); |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 711 | bool print_oneline = (curr_ptr_depth.CanAllowExpansion() || |
Enrico Granata | 3fa6dc9 | 2015-03-12 22:16:20 +0000 | [diff] [blame] | 712 | options.m_show_types || |
| 713 | !options.m_allow_oneliner_mode || |
| 714 | options.m_flat_output || |
| 715 | options.m_show_location) ? false : DataVisualization::ShouldPrintAsOneLiner(*m_valobj); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 716 | |
| 717 | if (print_children) |
| 718 | { |
Enrico Granata | a29cb0b | 2013-10-04 23:14:13 +0000 | [diff] [blame] | 719 | if (print_oneline) |
| 720 | { |
| 721 | m_stream->PutChar(' '); |
| 722 | PrintChildrenOneLiner (false); |
| 723 | m_stream->EOL(); |
| 724 | } |
| 725 | else |
Enrico Granata | c1b7c09 | 2015-07-27 18:34:14 +0000 | [diff] [blame] | 726 | PrintChildren (value_printed, summary_printed, curr_ptr_depth); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 727 | } |
| 728 | else if (m_curr_depth >= options.m_max_depth && IsAggregate() && ShouldPrintValueObject()) |
| 729 | { |
| 730 | m_stream->PutCString("{...}\n"); |
| 731 | } |
Enrico Granata | 245b3ca | 2013-10-03 18:11:24 +0000 | [diff] [blame] | 732 | else |
| 733 | m_stream->EOL(); |
Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 734 | } |
Enrico Granata | 0f883ff | 2014-09-06 02:20:19 +0000 | [diff] [blame] | 735 | |
| 736 | bool |
| 737 | ValueObjectPrinter::ShouldPrintValidation () |
| 738 | { |
| 739 | return options.m_run_validator; |
| 740 | } |
| 741 | |
| 742 | bool |
| 743 | ValueObjectPrinter::PrintValidationMarkerIfNeeded () |
| 744 | { |
| 745 | if (!ShouldPrintValidation()) |
| 746 | return false; |
| 747 | |
| 748 | m_validation = m_valobj->GetValidationStatus(); |
| 749 | |
| 750 | if (TypeValidatorResult::Failure == m_validation.first) |
| 751 | { |
| 752 | m_stream->Printf("! "); |
| 753 | return true; |
| 754 | } |
| 755 | |
| 756 | return false; |
| 757 | } |
| 758 | |
| 759 | bool |
| 760 | ValueObjectPrinter::PrintValidationErrorIfNeeded () |
| 761 | { |
| 762 | if (!ShouldPrintValidation()) |
| 763 | return false; |
| 764 | |
| 765 | if (TypeValidatorResult::Success == m_validation.first) |
| 766 | return false; |
| 767 | |
| 768 | if (m_validation.second.empty()) |
| 769 | m_validation.second.assign("unknown error"); |
| 770 | |
| 771 | m_stream->Printf(" ! validation error: %s", m_validation.second.c_str()); |
| 772 | m_stream->EOL(); |
| 773 | |
| 774 | return true; |
| 775 | } |