blob: 63fb6cc46d384f5421d2eceb5eac2912df2fac16 [file] [log] [blame]
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001//===-- 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 Granataa29cb0b2013-10-04 23:14:13 +000017#include "lldb/DataFormatters/DataVisualization.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000018#include "lldb/Interpreter/CommandInterpreter.h"
19#include "lldb/Target/Target.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
Enrico Granatad5957332015-06-03 20:43:54 +000024DumpValueObjectOptions::DumpValueObjectOptions (ValueObject& valobj) :
25DumpValueObjectOptions()
26{
27 m_use_dynamic = valobj.GetDynamicValueType();
28 m_use_synthetic = valobj.IsSynthetic();
Enrico Granata73e8c4d2015-10-07 02:36:35 +000029 m_varformat_language = valobj.GetPreferredDisplayLanguage();
Enrico Granatad5957332015-06-03 20:43:54 +000030}
31
32ValueObjectPrinter::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 Granata4d93b8c2013-09-30 19:11:51 +000047ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj,
48 Stream* s,
Enrico Granata938d1d62013-10-05 00:20:27 +000049 const DumpValueObjectOptions& options)
Enrico Granata4d93b8c2013-09-30 19:11:51 +000050{
Enrico Granata938d1d62013-10-05 00:20:27 +000051 Init(valobj,s,options,options.m_max_ptr_depth,0);
Enrico Granata4d93b8c2013-09-30 19:11:51 +000052}
53
54ValueObjectPrinter::ValueObjectPrinter (ValueObject* valobj,
55 Stream* s,
56 const DumpValueObjectOptions& options,
Enrico Granatac1b7c092015-07-27 18:34:14 +000057 const DumpValueObjectOptions::PointerDepth& ptr_depth,
Enrico Granata938d1d62013-10-05 00:20:27 +000058 uint32_t curr_depth)
59{
60 Init(valobj,s,options,ptr_depth,curr_depth);
61}
62
63void
64ValueObjectPrinter::Init (ValueObject* valobj,
65 Stream* s,
66 const DumpValueObjectOptions& options,
Enrico Granatac1b7c092015-07-27 18:34:14 +000067 const DumpValueObjectOptions::PointerDepth& ptr_depth,
Enrico Granata938d1d62013-10-05 00:20:27 +000068 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 Granata4d93b8c2013-09-30 19:11:51 +000088
89bool
90ValueObjectPrinter::PrintValueObject ()
91{
Enrico Granatad07cfd32014-10-08 18:27:36 +000092 if (!GetMostSpecializedValue () || m_valobj == nullptr)
Enrico Granata4d93b8c2013-09-30 19:11:51 +000093 return false;
94
95 if (ShouldPrintValueObject())
96 {
Enrico Granata0f883ff2014-09-06 02:20:19 +000097 PrintValidationMarkerIfNeeded();
98
Enrico Granata4d93b8c2013-09-30 19:11:51 +000099 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 Granata39938932013-10-03 02:06:02 +0000114 else
115 m_stream->EOL();
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000116
Enrico Granata0f883ff2014-09-06 02:20:19 +0000117 PrintValidationErrorIfNeeded();
118
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000119 return true;
120}
121
122bool
Enrico Granatad07cfd32014-10-08 18:27:36 +0000123ValueObjectPrinter::GetMostSpecializedValue ()
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000124{
Enrico Granataa29cb0b2013-10-04 23:14:13 +0000125 if (m_valobj)
126 return true;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000127 bool update_success = m_orig_valobj->UpdateValueIfNeeded (true);
128 if (!update_success)
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000129 {
Enrico Granata106260c2013-10-22 22:42:14 +0000130 m_valobj = m_orig_valobj;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000131 }
132 else
Enrico Granata106260c2013-10-22 22:42:14 +0000133 {
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 Granatad07cfd32014-10-08 18:27:36 +0000160
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 Granata106260c2013-10-22 22:42:14 +0000179 }
Bruce Mitchener59b5a372015-09-17 18:43:40 +0000180 m_compiler_type = m_valobj->GetCompilerType();
181 m_type_flags = m_compiler_type.GetTypeInfo ();
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000182 return true;
183}
184
185const char*
186ValueObjectPrinter::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
196const char*
197ValueObjectPrinter::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
205bool
206ValueObjectPrinter::ShouldPrintValueObject ()
207{
208 if (m_should_print == eLazyBoolCalculate)
Enrico Granata622be232014-10-21 20:52:14 +0000209 m_should_print = (options.m_flat_output == false || m_type_flags.Test (eTypeHasValue)) ? eLazyBoolYes : eLazyBoolNo;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000210 return m_should_print == eLazyBoolYes;
211}
212
213bool
214ValueObjectPrinter::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
221bool
222ValueObjectPrinter::IsPtr ()
223{
224 if (m_is_ptr == eLazyBoolCalculate)
Enrico Granata622be232014-10-21 20:52:14 +0000225 m_is_ptr = m_type_flags.Test (eTypeIsPointer) ? eLazyBoolYes : eLazyBoolNo;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000226 return m_is_ptr == eLazyBoolYes;
227}
228
229bool
230ValueObjectPrinter::IsRef ()
231{
232 if (m_is_ref == eLazyBoolCalculate)
Enrico Granata622be232014-10-21 20:52:14 +0000233 m_is_ref = m_type_flags.Test (eTypeIsReference) ? eLazyBoolYes : eLazyBoolNo;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000234 return m_is_ref == eLazyBoolYes;
235}
236
237bool
238ValueObjectPrinter::IsAggregate ()
239{
240 if (m_is_aggregate == eLazyBoolCalculate)
Enrico Granata622be232014-10-21 20:52:14 +0000241 m_is_aggregate = m_type_flags.Test (eTypeHasChildren) ? eLazyBoolYes : eLazyBoolNo;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000242 return m_is_aggregate == eLazyBoolYes;
243}
244
245bool
246ValueObjectPrinter::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
256bool
257ValueObjectPrinter::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 Granataa126e462014-11-21 18:47:26 +0000271 ConstString type_name;
272 if (options.m_use_type_display_name)
273 type_name = m_valobj->GetDisplayTypeName();
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000274 else
Enrico Granataa126e462014-11-21 18:47:26 +0000275 type_name = m_valobj->GetQualifiedTypeName();
276 if (type_name)
277 m_stream->Printf("(%s) ", type_name.GetCString());
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000278 else
279 show_type = false;
280 }
281 return show_type;
282}
283
284bool
285ValueObjectPrinter::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
307bool
308ValueObjectPrinter::CheckScopeIfNeeded ()
309{
310 if (options.m_scope_already_checked)
311 return true;
312 return m_valobj->IsInScope();
313}
314
315TypeSummaryImpl*
316ValueObjectPrinter::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
330void
331ValueObjectPrinter::GetValueSummaryError (std::string& value,
332 std::string& summary,
333 std::string& error)
334{
Enrico Granata465f4bc2014-02-15 01:24:44 +0000335 if (options.m_format != eFormatDefault && options.m_format != m_valobj->GetFormat())
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000336 {
Enrico Granata465f4bc2014-02-15 01:24:44 +0000337 m_valobj->GetValueAsCString(options.m_format,
338 value);
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000339 }
Enrico Granata465f4bc2014-02-15 01:24:44 +0000340 else
341 {
342 const char* val_cstr = m_valobj->GetValueAsCString();
343 if (val_cstr)
344 value.assign(val_cstr);
345 }
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000346 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 Granata73e8c4d2015-10-07 02:36:35 +0000358 m_valobj->GetSummaryAsCString(entry, summary, options.m_varformat_language);
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000359 else
360 {
Enrico Granata73e8c4d2015-10-07 02:36:35 +0000361 const char* sum_cstr = m_valobj->GetSummaryAsCString(options.m_varformat_language);
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000362 if (sum_cstr)
363 summary.assign(sum_cstr);
364 }
365 }
366 }
367}
368
369bool
370ValueObjectPrinter::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 Granata8a068e62014-04-23 23:16:25 +0000394 if (!IsNil() && !m_value.empty() && (entry == NULL || (entry->DoesPrintValue(m_valobj) || options.m_format != eFormatDefault) || m_summary.empty()) && !options.m_hide_value)
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000395 {
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
410bool
411ValueObjectPrinter::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
440bool
Enrico Granatac1b7c092015-07-27 18:34:14 +0000441DumpValueObjectOptions::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 Turner84f5b0d2015-09-09 17:25:43 +0000461 return false;
Enrico Granatac1b7c092015-07-27 18:34:14 +0000462}
463
464bool
465DumpValueObjectOptions::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 Turner84f5b0d2015-09-09 17:25:43 +0000476 return false;
Enrico Granatac1b7c092015-07-27 18:34:14 +0000477}
478
479bool
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000480ValueObjectPrinter::ShouldPrintChildren (bool is_failed_description,
Enrico Granatac1b7c092015-07-27 18:34:14 +0000481 DumpValueObjectOptions::PointerDepth& curr_ptr_depth)
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000482{
483 const bool is_ref = IsRef ();
484 const bool is_ptr = IsPtr ();
485
Enrico Granatac1b7c092015-07-27 18:34:14 +0000486 TypeSummaryImpl* entry = GetSummaryFormatter();
487
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000488 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 Granata4d93b8c2013-09-30 19:11:51 +0000497
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 Granatac1b7c092015-07-27 18:34:14 +0000506 const bool is_root_level = m_curr_depth == 0;
507
508 if (is_ref &&
509 is_root_level)
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000510 {
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 Granatac1b7c092015-07-27 18:34:14 +0000515 return true;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000516 }
517
Enrico Granatac1b7c092015-07-27 18:34:14 +0000518 return curr_ptr_depth.CanAllowExpansion(false, entry, m_valobj, m_summary);
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000519 }
520
Enrico Granata8a068e62014-04-23 23:16:25 +0000521 return (!entry || entry->DoesPrintChildren(m_valobj) || m_summary.empty());
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000522 }
523 return false;
524}
525
Siva Chandrad26eb902015-07-24 21:30:58 +0000526bool
527ValueObjectPrinter::ShouldExpandEmptyAggregates ()
528{
529 TypeSummaryImpl* entry = GetSummaryFormatter();
530
531 if (!entry)
532 return true;
533
534 return entry->DoesPrintEmptyAggregates();
535}
536
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000537ValueObject*
538ValueObjectPrinter::GetValueObjectForChildrenGeneration ()
539{
Enrico Granatad07cfd32014-10-08 18:27:36 +0000540 return m_valobj;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000541}
542
543void
544ValueObjectPrinter::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
559void
560ValueObjectPrinter::PrintChild (ValueObjectSP child_sp,
Enrico Granatac1b7c092015-07-27 18:34:14 +0000561 const DumpValueObjectOptions::PointerDepth& curr_ptr_depth)
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000562{
563 DumpValueObjectOptions child_options(options);
Enrico Granata443844c2015-06-17 02:11:48 +0000564 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000565 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 Granatac1b7c092015-07-27 18:34:14 +0000572 (IsPtr() || IsRef()) ? --curr_ptr_depth : curr_ptr_depth,
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000573 m_curr_depth + 1);
574 child_printer.PrintValueObject();
575 }
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000576}
577
578uint32_t
579ValueObjectPrinter::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
598void
599ValueObjectPrinter::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
613void
Enrico Granatac1b7c092015-07-27 18:34:14 +0000614ValueObjectPrinter::PrintChildren (bool value_printed,
615 bool summary_printed,
616 const DumpValueObjectOptions::PointerDepth& curr_ptr_depth)
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000617{
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 Granatad07cfd32014-10-08 18:27:36 +0000638 {
639 // if it has a synthetic value, then don't print {}, the synthetic children are probably only being used to vend a value
Siva Chandrad26eb902015-07-24 21:30:58 +0000640 if (m_valobj->DoesProvideSyntheticValue() || !ShouldExpandEmptyAggregates())
Enrico Granatad07cfd32014-10-08 18:27:36 +0000641 m_stream->PutCString( "\n");
642 else
643 m_stream->PutCString(" {}\n");
644 }
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000645 }
646 else
647 {
648 if (ShouldPrintValueObject())
649 m_stream->EOL();
650 }
651}
652
Enrico Granataa29cb0b2013-10-04 23:14:13 +0000653bool
654ValueObjectPrinter::PrintChildrenOneLiner (bool hide_names)
655{
Enrico Granatad07cfd32014-10-08 18:27:36 +0000656 if (!GetMostSpecializedValue () || m_valobj == nullptr)
Enrico Granataa29cb0b2013-10-04 23:14:13 +0000657 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 Granataddac7612014-10-09 18:47:36 +0000671 if (child_sp)
672 child_sp = child_sp->GetQualifiedRepresentationIfAvailable(options.m_use_dynamic, options.m_use_synthetic);
Enrico Granataa29cb0b2013-10-04 23:14:13 +0000673 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 Granata443844c2015-06-17 02:11:48 +0000688 lldb::eFormatInvalid,
Enrico Granataa29cb0b2013-10-04 23:14:13 +0000689 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 Granata4d93b8c2013-09-30 19:11:51 +0000701void
702ValueObjectPrinter::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 Granatac1b7c092015-07-27 18:34:14 +0000709 auto curr_ptr_depth = m_ptr_depth;
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000710 bool print_children = ShouldPrintChildren (is_failed_description,curr_ptr_depth);
Enrico Granatac1b7c092015-07-27 18:34:14 +0000711 bool print_oneline = (curr_ptr_depth.CanAllowExpansion() ||
Enrico Granata3fa6dc92015-03-12 22:16:20 +0000712 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 Granata4d93b8c2013-09-30 19:11:51 +0000716
717 if (print_children)
718 {
Enrico Granataa29cb0b2013-10-04 23:14:13 +0000719 if (print_oneline)
720 {
721 m_stream->PutChar(' ');
722 PrintChildrenOneLiner (false);
723 m_stream->EOL();
724 }
725 else
Enrico Granatac1b7c092015-07-27 18:34:14 +0000726 PrintChildren (value_printed, summary_printed, curr_ptr_depth);
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000727 }
728 else if (m_curr_depth >= options.m_max_depth && IsAggregate() && ShouldPrintValueObject())
729 {
730 m_stream->PutCString("{...}\n");
731 }
Enrico Granata245b3ca2013-10-03 18:11:24 +0000732 else
733 m_stream->EOL();
Enrico Granata4d93b8c2013-09-30 19:11:51 +0000734}
Enrico Granata0f883ff2014-09-06 02:20:19 +0000735
736bool
737ValueObjectPrinter::ShouldPrintValidation ()
738{
739 return options.m_run_validator;
740}
741
742bool
743ValueObjectPrinter::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
759bool
760ValueObjectPrinter::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}