|
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"
|
@@ -330,29 +331,37 @@ bool lldb_private::formatters::LibStdcppSmartPointerSummaryProvider(
|
330 | 331 | if (!ptr_sp)
|
331 | 332 | return false;
|
332 | 333 |
|
333 |
| - ValueObjectSP usecount_sp( |
334 |
| - valobj_sp->GetChildAtNamePath({"_M_refcount", "_M_pi", "_M_use_count"})); |
335 |
| - if (!usecount_sp) |
| 334 | + DumpCxxSmartPtrPointerSummary(stream, *ptr_sp, options); |
| 335 | + |
| 336 | + ValueObjectSP pi_sp = valobj_sp->GetChildAtNamePath({"_M_refcount", "_M_pi"}); |
| 337 | + if (!pi_sp) |
336 | 338 | return false;
|
337 | 339 |
|
338 |
| - if (ptr_sp->GetValueAsUnsigned(0) == 0 || |
339 |
| - usecount_sp->GetValueAsUnsigned(0) == 0) { |
340 |
| - stream.Printf("nullptr"); |
| 340 | + bool success; |
| 341 | + uint64_t pi_addr = pi_sp->GetValueAsUnsigned(0, &success); |
| 342 | + // Empty control field. We're done. |
| 343 | + if (!success || pi_addr == 0) |
341 | 344 | return true;
|
| 345 | + |
| 346 | + int64_t shared_count = 0; |
| 347 | + if (auto count_sp = pi_sp->GetChildMemberWithName("_M_use_count")) { |
| 348 | + bool success; |
| 349 | + shared_count = count_sp->GetValueAsSigned(0, &success); |
| 350 | + if (!success) |
| 351 | + return false; |
| 352 | + |
| 353 | + stream.Printf(" strong=%" PRId64, shared_count); |
342 | 354 | }
|
343 | 355 |
|
344 |
| - Status error; |
345 |
| - ValueObjectSP pointee_sp = ptr_sp->Dereference(error); |
346 |
| - if (pointee_sp && error.Success()) { |
347 |
| - if (pointee_sp->DumpPrintableRepresentation( |
348 |
| - stream, ValueObject::eValueObjectRepresentationStyleSummary, |
349 |
| - lldb::eFormatInvalid, |
350 |
| - ValueObject::PrintableRepresentationSpecialCases::eDisable, |
351 |
| - false)) { |
352 |
| - return true; |
353 |
| - } |
| 356 | + // _M_weak_count is the number of weak references + (_M_use_count != 0). |
| 357 | + if (auto weak_count_sp = pi_sp->GetChildMemberWithName("_M_weak_count")) { |
| 358 | + bool success; |
| 359 | + int64_t count = weak_count_sp->GetValueAsUnsigned(0, &success); |
| 360 | + if (!success) |
| 361 | + return false; |
| 362 | + |
| 363 | + stream.Printf(" weak=%" PRId64, count - (shared_count != 0)); |
354 | 364 | }
|
355 | 365 |
|
356 |
| - stream.Printf("ptr = 0x%" PRIx64, ptr_sp->GetValueAsUnsigned(0)); |
357 | 366 | return true;
|
358 | 367 | }
|
0 commit comments