2015-02-27 09:15:59 +00:00
|
|
|
//===- LinePrinter.h ------------------------------------------ *- C++ --*-===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00: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 09:15:59 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
|
|
|
|
#define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
|
|
|
|
|
2017-06-15 22:24:24 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2015-03-01 06:59:57 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-02-27 09:15:59 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-23 18:52:13 +00:00
|
|
|
#include "llvm/Support/BinaryStreamRef.h"
|
2017-06-15 22:24:24 +00:00
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
2017-06-15 20:55:51 +00:00
|
|
|
#include "llvm/Support/Regex.h"
|
2017-06-15 22:24:24 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-03-01 06:49:49 +00:00
|
|
|
|
|
|
|
#include <list>
|
2015-02-27 09:15:59 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-06-23 18:52:13 +00:00
|
|
|
class BinaryStreamReader;
|
|
|
|
namespace msf {
|
|
|
|
class MSFStreamLayout;
|
|
|
|
} // namespace msf
|
2016-05-04 20:32:13 +00:00
|
|
|
namespace pdb {
|
2015-02-27 09:15:59 +00:00
|
|
|
|
2017-04-13 21:11:00 +00:00
|
|
|
class ClassLayout;
|
2017-06-23 18:52:13 +00:00
|
|
|
class PDBFile;
|
2017-04-13 21:11:00 +00:00
|
|
|
|
2015-02-27 09:15:59 +00:00
|
|
|
class LinePrinter {
|
|
|
|
friend class WithColor;
|
|
|
|
|
|
|
|
public:
|
2017-03-23 15:28:15 +00:00
|
|
|
LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
|
2015-02-27 09:15:59 +00:00
|
|
|
|
2017-06-15 22:24:24 +00:00
|
|
|
void Indent(uint32_t Amount = 0);
|
|
|
|
void Unindent(uint32_t Amount = 0);
|
2015-02-27 09:15:59 +00:00
|
|
|
void NewLine();
|
|
|
|
|
2017-06-15 22:24:24 +00: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 20:58:11 +00:00
|
|
|
void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
|
|
|
|
uint32_t StartOffset);
|
2017-06-15 22:24:24 +00:00
|
|
|
|
2017-06-23 18:52:13 +00: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-02 22:25:52 +00:00
|
|
|
void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream);
|
2017-06-23 18:52:13 +00:00
|
|
|
|
2017-03-23 15:28:15 +00:00
|
|
|
bool hasColor() const { return UseColor; }
|
2015-02-27 09:15:59 +00:00
|
|
|
raw_ostream &getStream() { return OS; }
|
2015-03-02 04:39:56 +00:00
|
|
|
int getIndentLevel() const { return CurrentIndent; }
|
2015-02-27 09:15:59 +00:00
|
|
|
|
2017-04-13 21:11:00 +00:00
|
|
|
bool IsClassExcluded(const ClassLayout &Class);
|
|
|
|
bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
|
2015-03-01 06:49:49 +00:00
|
|
|
bool IsSymbolExcluded(llvm::StringRef SymbolName);
|
|
|
|
bool IsCompilandExcluded(llvm::StringRef CompilandName);
|
|
|
|
|
2015-02-27 09:15:59 +00:00
|
|
|
private:
|
2015-03-02 04:39:56 +00:00
|
|
|
template <typename Iter>
|
|
|
|
void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
|
|
|
|
List.clear();
|
|
|
|
for (; Begin != End; ++Begin)
|
2015-05-29 19:43:39 +00:00
|
|
|
List.emplace_back(StringRef(*Begin));
|
2015-03-02 04:39:56 +00:00
|
|
|
}
|
|
|
|
|
2015-02-27 09:15:59 +00:00
|
|
|
raw_ostream &OS;
|
|
|
|
int IndentSpaces;
|
|
|
|
int CurrentIndent;
|
2017-03-23 15:28:15 +00:00
|
|
|
bool UseColor;
|
2015-03-01 06:49:49 +00:00
|
|
|
|
2015-09-29 19:49:06 +00: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 09:15:59 +00:00
|
|
|
};
|
|
|
|
|
2017-09-01 20:06:56 +00: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-15 22:24:24 +00:00
|
|
|
struct AutoIndent {
|
|
|
|
explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
|
2017-09-01 20:06:56 +00:00
|
|
|
: L(&L), Amount(Amount) {
|
2017-06-15 22:24:24 +00:00
|
|
|
L.Indent(Amount);
|
|
|
|
}
|
2017-09-01 20:06:56 +00:00
|
|
|
explicit AutoIndent(const Optional<PrintScope> &Scope) {
|
|
|
|
if (Scope.hasValue()) {
|
|
|
|
L = &Scope->P;
|
|
|
|
Amount = Scope->IndentLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~AutoIndent() {
|
|
|
|
if (L)
|
|
|
|
L->Unindent(Amount);
|
|
|
|
}
|
2017-06-15 22:24:24 +00:00
|
|
|
|
2017-09-01 20:06:56 +00:00
|
|
|
LinePrinter *L = nullptr;
|
2017-06-15 22:24:24 +00:00
|
|
|
uint32_t Amount = 0;
|
|
|
|
};
|
|
|
|
|
2015-02-27 09:15:59 +00:00
|
|
|
template <class T>
|
|
|
|
inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
|
|
|
|
Printer.getStream() << Item;
|
|
|
|
return Printer.getStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum class PDB_ColorItem {
|
|
|
|
None,
|
|
|
|
Address,
|
|
|
|
Type,
|
2017-04-10 19:33:29 +00:00
|
|
|
Comment,
|
|
|
|
Padding,
|
2015-02-27 09:15:59 +00:00
|
|
|
Keyword,
|
|
|
|
Offset,
|
|
|
|
Identifier,
|
|
|
|
Path,
|
|
|
|
SectionHeader,
|
|
|
|
LiteralValue,
|
2015-03-02 04:39:56 +00:00
|
|
|
Register,
|
2015-02-27 09:15:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WithColor {
|
|
|
|
public:
|
|
|
|
WithColor(LinePrinter &P, PDB_ColorItem C);
|
|
|
|
~WithColor();
|
|
|
|
|
|
|
|
raw_ostream &get() { return OS; }
|
|
|
|
|
|
|
|
private:
|
2015-11-03 01:04:44 +00:00
|
|
|
void applyColor(PDB_ColorItem C);
|
2015-02-27 09:15:59 +00:00
|
|
|
raw_ostream &OS;
|
2017-03-29 17:11:27 +00:00
|
|
|
bool UseColor;
|
2015-02-27 09:15:59 +00:00
|
|
|
};
|
|
|
|
}
|
2016-05-04 20:32:13 +00:00
|
|
|
}
|
2015-02-27 09:15:59 +00:00
|
|
|
|
|
|
|
#endif
|