2015-02-27 10:15:59 +01:00
|
|
|
//===- LinePrinter.h ------------------------------------------ *- C++ --*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-27 10:15:59 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
|
|
|
|
#define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
|
|
|
|
|
2017-06-16 00:24:24 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2015-03-01 07:59:57 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-02-27 10:15:59 +01:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-23 20:52:13 +02:00
|
|
|
#include "llvm/Support/BinaryStreamRef.h"
|
2017-06-16 00:24:24 +02:00
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
2017-06-15 22:55:51 +02:00
|
|
|
#include "llvm/Support/Regex.h"
|
2017-06-16 00:24:24 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-03-01 07:49:49 +01:00
|
|
|
|
|
|
|
#include <list>
|
2015-02-27 10:15:59 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-06-23 20:52:13 +02:00
|
|
|
class BinaryStreamReader;
|
|
|
|
namespace msf {
|
|
|
|
class MSFStreamLayout;
|
|
|
|
} // namespace msf
|
2016-05-04 22:32:13 +02:00
|
|
|
namespace pdb {
|
2015-02-27 10:15:59 +01:00
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
class ClassLayout;
|
2017-06-23 20:52:13 +02:00
|
|
|
class PDBFile;
|
2017-04-13 23:11:00 +02:00
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
class LinePrinter {
|
|
|
|
friend class WithColor;
|
|
|
|
|
|
|
|
public:
|
2017-03-23 16:28:15 +01:00
|
|
|
LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
|
2015-02-27 10:15:59 +01:00
|
|
|
|
2017-06-16 00:24:24 +02:00
|
|
|
void Indent(uint32_t Amount = 0);
|
|
|
|
void Unindent(uint32_t Amount = 0);
|
2015-02-27 10:15:59 +01:00
|
|
|
void NewLine();
|
|
|
|
|
2017-06-16 00:24:24 +02:00
|
|
|
void printLine(const Twine &T);
|
|
|
|
void print(const Twine &T);
|
|
|
|
template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
|
|
|
|
printLine(formatv(Fmt, std::forward<Ts>(Items)...));
|
|
|
|
}
|
|
|
|
template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
|
|
|
|
print(formatv(Fmt, std::forward<Ts>(Items)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
void formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
|
|
|
|
uint32_t StartOffset);
|
2017-06-22 22:58:11 +02:00
|
|
|
void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
|
|
|
|
uint32_t StartOffset);
|
2017-06-16 00:24:24 +02:00
|
|
|
|
2017-06-23 20:52:13 +02:00
|
|
|
void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx,
|
|
|
|
StringRef StreamPurpose, uint32_t Offset,
|
|
|
|
uint32_t Size);
|
|
|
|
void formatMsfStreamData(StringRef Label, PDBFile &File,
|
|
|
|
const msf::MSFStreamLayout &Stream,
|
|
|
|
BinarySubstreamRef Substream);
|
2017-08-03 00:25:52 +02:00
|
|
|
void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream);
|
2017-06-23 20:52:13 +02:00
|
|
|
|
2017-03-23 16:28:15 +01:00
|
|
|
bool hasColor() const { return UseColor; }
|
2015-02-27 10:15:59 +01:00
|
|
|
raw_ostream &getStream() { return OS; }
|
2015-03-02 05:39:56 +01:00
|
|
|
int getIndentLevel() const { return CurrentIndent; }
|
2015-02-27 10:15:59 +01:00
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
bool IsClassExcluded(const ClassLayout &Class);
|
|
|
|
bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
|
2015-03-01 07:49:49 +01:00
|
|
|
bool IsSymbolExcluded(llvm::StringRef SymbolName);
|
|
|
|
bool IsCompilandExcluded(llvm::StringRef CompilandName);
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
private:
|
2015-03-02 05:39:56 +01:00
|
|
|
template <typename Iter>
|
|
|
|
void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
|
|
|
|
List.clear();
|
|
|
|
for (; Begin != End; ++Begin)
|
2015-05-29 21:43:39 +02:00
|
|
|
List.emplace_back(StringRef(*Begin));
|
2015-03-02 05:39:56 +01:00
|
|
|
}
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
raw_ostream &OS;
|
|
|
|
int IndentSpaces;
|
|
|
|
int CurrentIndent;
|
2017-03-23 16:28:15 +01:00
|
|
|
bool UseColor;
|
2015-03-01 07:49:49 +01:00
|
|
|
|
2015-09-29 21:49:06 +02:00
|
|
|
std::list<Regex> ExcludeCompilandFilters;
|
|
|
|
std::list<Regex> ExcludeTypeFilters;
|
|
|
|
std::list<Regex> ExcludeSymbolFilters;
|
|
|
|
|
|
|
|
std::list<Regex> IncludeCompilandFilters;
|
|
|
|
std::list<Regex> IncludeTypeFilters;
|
|
|
|
std::list<Regex> IncludeSymbolFilters;
|
2015-02-27 10:15:59 +01:00
|
|
|
};
|
|
|
|
|
2017-09-01 22:06:56 +02:00
|
|
|
struct PrintScope {
|
|
|
|
explicit PrintScope(LinePrinter &P, uint32_t IndentLevel)
|
|
|
|
: P(P), IndentLevel(IndentLevel) {}
|
|
|
|
explicit PrintScope(const PrintScope &Other, uint32_t LabelWidth)
|
|
|
|
: P(Other.P), IndentLevel(Other.IndentLevel), LabelWidth(LabelWidth) {}
|
|
|
|
|
|
|
|
LinePrinter &P;
|
|
|
|
uint32_t IndentLevel;
|
|
|
|
uint32_t LabelWidth = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline Optional<PrintScope> withLabelWidth(const Optional<PrintScope> &Scope,
|
|
|
|
uint32_t W) {
|
|
|
|
if (!Scope)
|
|
|
|
return None;
|
|
|
|
return PrintScope{*Scope, W};
|
|
|
|
}
|
|
|
|
|
2017-06-16 00:24:24 +02:00
|
|
|
struct AutoIndent {
|
|
|
|
explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
|
2017-09-01 22:06:56 +02:00
|
|
|
: L(&L), Amount(Amount) {
|
2017-06-16 00:24:24 +02:00
|
|
|
L.Indent(Amount);
|
|
|
|
}
|
2017-09-01 22:06:56 +02:00
|
|
|
explicit AutoIndent(const Optional<PrintScope> &Scope) {
|
|
|
|
if (Scope.hasValue()) {
|
|
|
|
L = &Scope->P;
|
|
|
|
Amount = Scope->IndentLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~AutoIndent() {
|
|
|
|
if (L)
|
|
|
|
L->Unindent(Amount);
|
|
|
|
}
|
2017-06-16 00:24:24 +02:00
|
|
|
|
2017-09-01 22:06:56 +02:00
|
|
|
LinePrinter *L = nullptr;
|
2017-06-16 00:24:24 +02:00
|
|
|
uint32_t Amount = 0;
|
|
|
|
};
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
template <class T>
|
|
|
|
inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
|
2019-07-18 00:59:52 +02:00
|
|
|
return Printer.getStream() << Item;
|
2015-02-27 10:15:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enum class PDB_ColorItem {
|
|
|
|
None,
|
|
|
|
Address,
|
|
|
|
Type,
|
2017-04-10 21:33:29 +02:00
|
|
|
Comment,
|
|
|
|
Padding,
|
2015-02-27 10:15:59 +01:00
|
|
|
Keyword,
|
|
|
|
Offset,
|
|
|
|
Identifier,
|
|
|
|
Path,
|
|
|
|
SectionHeader,
|
|
|
|
LiteralValue,
|
2015-03-02 05:39:56 +01:00
|
|
|
Register,
|
2015-02-27 10:15:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class WithColor {
|
|
|
|
public:
|
|
|
|
WithColor(LinePrinter &P, PDB_ColorItem C);
|
|
|
|
~WithColor();
|
|
|
|
|
|
|
|
raw_ostream &get() { return OS; }
|
|
|
|
|
|
|
|
private:
|
2015-11-03 02:04:44 +01:00
|
|
|
void applyColor(PDB_ColorItem C);
|
2015-02-27 10:15:59 +01:00
|
|
|
raw_ostream &OS;
|
2017-03-29 19:11:27 +02:00
|
|
|
bool UseColor;
|
2015-02-27 10:15:59 +01:00
|
|
|
};
|
|
|
|
}
|
2016-05-04 22:32:13 +02:00
|
|
|
}
|
2015-02-27 10:15:59 +01:00
|
|
|
|
|
|
|
#endif
|