|
10 | 10 | #include "LibCxx.h"
|
11 | 11 |
|
12 | 12 | #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
|
| 13 | +#include "lldb/DataFormatters/FormattersHelpers.h" |
13 | 14 | #include "lldb/DataFormatters/StringPrinter.h"
|
14 | 15 | #include "lldb/DataFormatters/VectorIterator.h"
|
15 | 16 | #include "lldb/Target/Target.h"
|
@@ -450,29 +451,37 @@ bool lldb_private::formatters::LibStdcppSmartPointerSummaryProvider(
|
450 | 451 | if (!ptr_sp)
|
451 | 452 | return false;
|
452 | 453 |
|
453 |
| - ValueObjectSP usecount_sp( |
454 |
| - valobj_sp->GetChildAtNamePath({"_M_refcount", "_M_pi", "_M_use_count"})); |
455 |
| - if (!usecount_sp) |
| 454 | + DumpCxxSmartPtrPointerSummary(stream, *ptr_sp, options); |
| 455 | + |
| 456 | + ValueObjectSP pi_sp = valobj_sp->GetChildAtNamePath({"_M_refcount", "_M_pi"}); |
| 457 | + if (!pi_sp) |
456 | 458 | return false;
|
457 | 459 |
|
458 |
| - if (ptr_sp->GetValueAsUnsigned(0) == 0 || |
459 |
| - usecount_sp->GetValueAsUnsigned(0) == 0) { |
460 |
| - stream.Printf("nullptr"); |
| 460 | + bool success; |
| 461 | + uint64_t pi_addr = pi_sp->GetValueAsUnsigned(0, &success); |
| 462 | + // Empty control field. We're done. |
| 463 | + if (!success || pi_addr == 0) |
461 | 464 | return true;
|
| 465 | + |
| 466 | + int64_t shared_count = 0; |
| 467 | + if (auto count_sp = pi_sp->GetChildMemberWithName("_M_use_count")) { |
| 468 | + bool success; |
| 469 | + shared_count = count_sp->GetValueAsSigned(0, &success); |
| 470 | + if (!success) |
| 471 | + return false; |
| 472 | + |
| 473 | + stream.Printf(" strong=%" PRId64, shared_count); |
462 | 474 | }
|
463 | 475 |
|
464 |
| - Status error; |
465 |
| - ValueObjectSP pointee_sp = ptr_sp->Dereference(error); |
466 |
| - if (pointee_sp && error.Success()) { |
467 |
| - if (pointee_sp->DumpPrintableRepresentation( |
468 |
| - stream, ValueObject::eValueObjectRepresentationStyleSummary, |
469 |
| - lldb::eFormatInvalid, |
470 |
| - ValueObject::PrintableRepresentationSpecialCases::eDisable, |
471 |
| - false)) { |
472 |
| - return true; |
473 |
| - } |
| 476 | + // _M_weak_count is the number of weak references + (_M_use_count != 0). |
| 477 | + if (auto weak_count_sp = pi_sp->GetChildMemberWithName("_M_weak_count")) { |
| 478 | + bool success; |
| 479 | + int64_t count = weak_count_sp->GetValueAsUnsigned(0, &success); |
| 480 | + if (!success) |
| 481 | + return false; |
| 482 | + |
| 483 | + stream.Printf(" weak=%" PRId64, count - (shared_count != 0)); |
474 | 484 | }
|
475 | 485 |
|
476 |
| - stream.Printf("ptr = 0x%" PRIx64, ptr_sp->GetValueAsUnsigned(0)); |
477 | 486 | return true;
|
478 | 487 | }
|
0 commit comments