Path: blob/main/contrib/llvm-project/llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp
35260 views
//===- PrettyClassDefinitionDumper.cpp --------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "PrettyClassDefinitionDumper.h"910#include "PrettyClassLayoutGraphicalDumper.h"11#include "llvm-pdbutil.h"1213#include "llvm/ADT/APFloat.h"14#include "llvm/ADT/SmallString.h"15#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"16#include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"17#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"18#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"19#include "llvm/DebugInfo/PDB/UDTLayout.h"2021#include "llvm/Support/Format.h"2223using namespace llvm;24using namespace llvm::pdb;2526ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P)27: PDBSymDumper(true), Printer(P) {}2829void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) {30assert(opts::pretty::ClassFormat !=31opts::pretty::ClassDefinitionFormat::None);3233ClassLayout Layout(Class);34start(Layout);35}3637void ClassDefinitionDumper::start(const ClassLayout &Layout) {38prettyPrintClassIntro(Layout);3940PrettyClassLayoutGraphicalDumper Dumper(Printer, 1, 0);41DumpedAnything |= Dumper.start(Layout);4243prettyPrintClassOutro(Layout);44}4546void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout &Layout) {47DumpedAnything = false;48Printer.NewLine();4950uint32_t Size = Layout.getSize();51const PDBSymbolTypeUDT &Class = Layout.getClass();5253if (Layout.getClass().isConstType())54WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";55if (Layout.getClass().isVolatileType())56WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";57if (Layout.getClass().isUnalignedType())58WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";5960WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";61WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();62WithColor(Printer, PDB_ColorItem::Comment).get() << " [sizeof = " << Size63<< "]";64uint32_t BaseCount = Layout.bases().size();65if (BaseCount > 0) {66Printer.Indent();67char NextSeparator = ':';68for (auto *BC : Layout.bases()) {69const auto &Base = BC->getBase();70if (Base.isIndirectVirtualBaseClass())71continue;7273Printer.NewLine();74Printer << NextSeparator << " ";75WithColor(Printer, PDB_ColorItem::Keyword).get() << Base.getAccess();76if (BC->isVirtualBase())77WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";7879WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base.getName();80NextSeparator = ',';81}8283Printer.Unindent();84}8586Printer << " {";87Printer.Indent();88}8990void ClassDefinitionDumper::prettyPrintClassOutro(const ClassLayout &Layout) {91Printer.Unindent();92if (DumpedAnything)93Printer.NewLine();94Printer << "}";95Printer.NewLine();96if (Layout.deepPaddingSize() > 0) {97APFloat Pct(100.0 * (double)Layout.deepPaddingSize() /98(double)Layout.getSize());99SmallString<8> PctStr;100Pct.toString(PctStr, 4);101WithColor(Printer, PDB_ColorItem::Padding).get()102<< "Total padding " << Layout.deepPaddingSize() << " bytes (" << PctStr103<< "% of class size)";104Printer.NewLine();105APFloat Pct2(100.0 * (double)Layout.immediatePadding() /106(double)Layout.getSize());107PctStr.clear();108Pct2.toString(PctStr, 4);109WithColor(Printer, PDB_ColorItem::Padding).get()110<< "Immediate padding " << Layout.immediatePadding() << " bytes ("111<< PctStr << "% of class size)";112Printer.NewLine();113}114}115116117