[all-commits] [llvm/llvm-project] fe8933: [lldb][DataFormatter] Simplify std::map formatter ...

Michael Buch via All-commits all-commits at lists.llvm.org
Mon Jul 8 09:19:46 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fe8933ba211da094dc866b2bde64928c8121131b
      https://github.com/llvm/llvm-project/commit/fe8933ba211da094dc866b2bde64928c8121131b
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2024-07-08 (Mon, 08 Jul 2024)

  Changed paths:
    M lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp

  Log Message:
  -----------
  [lldb][DataFormatter] Simplify std::map formatter  (#97579)

Depends on:
* https://github.com/llvm/llvm-project/pull/97544
* https://github.com/llvm/llvm-project/pull/97549
* https://github.com/llvm/llvm-project/pull/97551

This patch tries to simplify the way in which the `std::map` formatter
goes from the root `__tree` pointer to a specific key/value pair.

Previously we would:
1. synthesize a structure that mimicked what `__iter_pointer` looked
like in memory
2. call `GetChildCompilerTypeAtIndex` on it to find the byte offset at
which the pair was located in the synthesized structure
3. finally, use that offset through a call to
`GetSyntheticChildAtOffset` to retrieve the key/value pair

Not only was this logic hard to follow, and encoded the libc++ layout in
non-obvious ways, it was also fragile to alignment miscalculations
(https://github.com/llvm/llvm-project/pull/97443); this would break once
the new layout of std::map landed as part of
https://github.com/https://github.com/llvm/llvm-project/issues/93069.

Instead, this patch simply casts the `__iter_pointer` to the
`__node_pointer` and uses a straightforward
`GetChildMemberWithName("__value_")` to get to the key/value we care
about. This allows us to get rid of some support infrastructure/class
state.

Ideally we would fix the underlying alignment issue, but this unblocks
the libc++ refactor in the interim, while also benefitting the formatter
in terms of readability (in my opinion).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list