2015-06-27 07:56:53 +08:00
|
|
|
//===-------- StackMapPrinter.h - Pretty-print stackmaps --------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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-06-27 07:56:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
|
|
|
|
#define LLVM_TOOLS_LLVM_READOBJ_STACKMAPPRINTER_H
|
|
|
|
|
|
|
|
#include "llvm/Object/StackMapParser.h"
|
2018-01-10 08:14:19 +08:00
|
|
|
#include "llvm/Support/ScopedPrinter.h"
|
2015-06-27 07:56:53 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
// Pretty print a stackmap to the given ostream.
|
2018-01-10 08:14:19 +08:00
|
|
|
template <typename StackMapParserT>
|
|
|
|
void prettyPrintStackMap(ScopedPrinter &W, const StackMapParserT &SMP) {
|
2015-06-27 07:56:53 +08:00
|
|
|
|
2018-01-10 08:14:19 +08:00
|
|
|
W.printNumber("LLVM StackMap Version", SMP.getVersion());
|
|
|
|
W.printNumber("Num Functions", SMP.getNumFunctions());
|
2015-06-27 07:56:53 +08:00
|
|
|
|
|
|
|
// Functions:
|
|
|
|
for (const auto &F : SMP.functions())
|
2018-01-10 08:14:19 +08:00
|
|
|
W.startLine() << " Function address: " << F.getFunctionAddress()
|
2016-09-15 04:22:03 +08:00
|
|
|
<< ", stack size: " << F.getStackSize()
|
2018-01-10 08:14:19 +08:00
|
|
|
<< ", callsite record count: " << F.getRecordCount() << "\n";
|
2015-06-27 07:56:53 +08:00
|
|
|
|
|
|
|
// Constants:
|
2018-01-10 08:14:19 +08:00
|
|
|
W.printNumber("Num Constants", SMP.getNumConstants());
|
2015-06-27 07:56:53 +08:00
|
|
|
unsigned ConstantIndex = 0;
|
|
|
|
for (const auto &C : SMP.constants())
|
2018-01-10 08:14:19 +08:00
|
|
|
W.startLine() << " #" << ++ConstantIndex << ": " << C.getValue() << "\n";
|
2015-06-27 07:56:53 +08:00
|
|
|
|
|
|
|
// Records:
|
2018-01-10 08:14:19 +08:00
|
|
|
W.printNumber("Num Records", SMP.getNumRecords());
|
2015-06-27 07:56:53 +08:00
|
|
|
for (const auto &R : SMP.records()) {
|
2018-01-10 08:14:19 +08:00
|
|
|
W.startLine() << " Record ID: " << R.getID()
|
|
|
|
<< ", instruction offset: " << R.getInstructionOffset()
|
|
|
|
<< "\n";
|
|
|
|
W.startLine() << " " << R.getNumLocations() << " locations:\n";
|
2015-06-27 07:56:53 +08:00
|
|
|
|
|
|
|
unsigned LocationIndex = 0;
|
|
|
|
for (const auto &Loc : R.locations()) {
|
2018-01-10 08:14:19 +08:00
|
|
|
raw_ostream &OS = W.startLine();
|
|
|
|
OS << " #" << ++LocationIndex << ": ";
|
2015-06-27 07:56:53 +08:00
|
|
|
switch (Loc.getKind()) {
|
|
|
|
case StackMapParserT::LocationKind::Register:
|
2019-04-13 11:08:45 +08:00
|
|
|
OS << "Register R#" << Loc.getDwarfRegNum();
|
2015-06-27 07:56:53 +08:00
|
|
|
break;
|
|
|
|
case StackMapParserT::LocationKind::Direct:
|
2019-04-13 11:08:45 +08:00
|
|
|
OS << "Direct R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset();
|
2015-06-27 07:56:53 +08:00
|
|
|
break;
|
|
|
|
case StackMapParserT::LocationKind::Indirect:
|
2018-01-10 08:14:19 +08:00
|
|
|
OS << "Indirect [R#" << Loc.getDwarfRegNum() << " + " << Loc.getOffset()
|
2019-04-13 11:08:45 +08:00
|
|
|
<< "]";
|
2015-06-27 07:56:53 +08:00
|
|
|
break;
|
|
|
|
case StackMapParserT::LocationKind::Constant:
|
2019-04-13 11:08:45 +08:00
|
|
|
OS << "Constant " << Loc.getSmallConstant();
|
2015-06-27 07:56:53 +08:00
|
|
|
break;
|
|
|
|
case StackMapParserT::LocationKind::ConstantIndex:
|
|
|
|
OS << "ConstantIndex #" << Loc.getConstantIndex() << " ("
|
2019-04-13 11:08:45 +08:00
|
|
|
<< SMP.getConstant(Loc.getConstantIndex()).getValue() << ")";
|
2015-06-27 07:56:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-04-13 11:08:45 +08:00
|
|
|
OS << ", size: " << Loc.getSizeInBytes() << "\n";
|
2015-06-27 07:56:53 +08:00
|
|
|
}
|
|
|
|
|
2018-01-10 08:14:19 +08:00
|
|
|
raw_ostream &OS = W.startLine();
|
|
|
|
OS << " " << R.getNumLiveOuts() << " live-outs: [ ";
|
2015-06-27 07:56:53 +08:00
|
|
|
for (const auto &LO : R.liveouts())
|
|
|
|
OS << "R#" << LO.getDwarfRegNum() << " ("
|
|
|
|
<< LO.getSizeInBytes() << "-bytes) ";
|
|
|
|
OS << "]\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|